-->

Django user not getting the assigned group's p

2019-08-10 07:14发布

问题:

I am using django admin back end for creating user groups. I created a group called admin and assigned several permissions to it.

But when I assign this group admin to a user the permissions of that group are not automatically assigned to the user.

The django docs say that:

A user in a group automatically has the permissions granted to that group. 
For example, if the group Site editors has the permission can_edit_home_page, 
any user in that group will have that permission.

Can someone please tell me if I understood it correctly or not? Or do I need to write some code myself to assign permissions of a group to a user.

I am using django rest framework and south and postgres as database.

Also I checked using the django shell that,

when I assign a user specific permissions manually they get assigned. Also when I assign a group specific permissions they also get assigned to that group.

But when I assign a group to a user, the group gets assigned but the the groups permissions are not.

回答1:

The group permissions do not get copied to the user as user permissions, but the user should still have all the groups permissions.

Example:

User Anton
  - can add X

Group Admin
  - can change X
  - can delete X

Anton can only add X as long as he is not in the Admin Group. When he is member of the Group he will be able to change/delete X. If you view the user permissions in django-admin they will still look the same though.