How do i create an API that contains user, group and permissions.
I want to combine auth_user_group and auth_group_permissions. how to import both models in my code. I cannot find the models in django.contrib.auth.
There are no such models: auth_user_group is the intermediary table for the M2M relationshipt between users and groups and auth_group_permissionsthe intermediary table between Permission and Group
if you wan't to display the user's groups and permissions on your API you'll need to use the serializer relations http://www.django-rest-framework.org/api-guide/relations/
hope this helps
Related
I need to know that how we can implement dynamic role on hasura.I mean if we have lots of tables and want to have 4 access control per the table (insert, delete, update, select), a one way is that we create 4 roles for each table for example if we had two tables that named users, cars, we would have these roles:
1-add_user
2-delete_user
3-update_user
4-select_user
and
5-add_car
6-delete_car
7-update_car
8-select_car
it is not a efficient way...
please help me to find the best way.
thank you.
As far as my understanding goes of roles, in your case role will just be user. Your tables users and cars will have permissions assigned to user role. So for e.g
Role user will have (insert, delete, update, select) permissions for
users table but can only have (select) permission for cars table.
For implementation, you can easily create them in permission section of your respective table.
Let me know if this was helpful to you or if you have any furthur doubts.
I'm actually learning Django Rest Framework and I have this project that involves multiple user types so for example it consists of Students, Teachers and Admins each one with his attributes so I created a User model that inherits from AbstractUser and 3 other models for each type where each type has a foreign key of it's corresponding user. So here comes the problem how can I use Django-Rest-Auth library with these user types so for example when I use the register endpoint how can I modify it in order to create a Student in the students model based on the request data ?
I would appreciate any ones help.
Thanks in advance
I have one model user and one table against that model users I have different roles for user as patient, hospital and so on, each user have different fields and values to enter during registration so I have created different routes and controllers for different roles.
Now I'm facing problem during authorization process how I can authorize. I have only one model user so I can create only one policy called UserPolicy and use the $this->authorize method in the UserController.
I have also other controllers as PatientController, HospitalController which all bound to the one table and model called user and fetching the record only based on the user type. Now how can I create the policies for them and use the $this->authorize method in the Hospital, Patient controllers?
you are using the same table and you require different data from each kind if user ?
anyway if that the situation , you can create a type field in the users table , then create 2 middlewares , in your middleware check the type of the user then throw an exception or make him pass
What is the correct way to relate users in parse to one another as friends?
I also want users to be able to query other users but not see all fields, like emails. Is there a way I can create a view on the users table with cloud code, and only return this to the client code?
I was thinking I can create a friends table that will have two columns with 2 pointers, 1 for each user.
thanks for any advice.
I was thinking I can create a friends table that will have two columns with 2 pointers, 1 for each user.
I'll do that too, with a status column to handle pending, blocked...etc
I also want users to be able to query other users but not see all fields, like emails.
You have to add a privateData column on user with ACL restricted to owner only, which would contain private infos such as emails...etc
I have a many-to-many relationship, users and roles, which I have worked out just fine. However, I have another table I would like to relate as well, called leads. A user and that user's role can be assigned to a lead.
So for example, I've created a Role and let's call it 'Manager'. Now, when I am managing my Users, I'd need to be able to assign different users to different roles which will be a many-to-many relationship (a role can have many users, a user can have many roles). So I will assign the role of 'Manager' to User A.
Now, when I am modifying my leads, I'd like to be able to assign a role_user to my lead (In my example, I'd like to assign a user to that lead), but I'd first need to assign a role to that Lead (Manager), and then be able to assign a user that is of that role to that lead.
Currently, I've got a many-to-many relationship setup for users and roles, using the pivot table name role_user. I've then got a many-to-many relationship setup on that pivot table, role_user, and leads, using another pivot table named lead_role_user.
Models + Controller - http://paste.laravel.com/D6h
My error: Call to undefined method Illuminate\Database\Query\Builder::roles()
It feels as though I am making this much more difficult than it should be.