问题
Is it possible to give a user default permissions for a specific app, right after creation?
There is a similar question here, but since it is 1,5 years old I hope, there is a possibility to do it now.
The background is the following:
I only run one app in my Djangopage. Let's call it 'foo'.
My users log into the admin-page with their LDAP Account. If they log in the first time, their account isn't in the database and will be created.
When they are logged in then, they can't do anything, because they don't have any permissions.
I want to give them all permissions for my 'foo' App, right after account-creation. At the moment, I need to log in with an adminaccount and grant them manually.
回答1:
If you're using the RemoteUserBackend authentication backend with LDAP, then you could subclass it, override the configure_user method and set the permission there.
If you're using a different method to authenticate, then you can use the post_save
signal.
来源:https://stackoverflow.com/questions/20992334/django-default-user-permissions