Django默认用户权限 [英] Django default user permissions

查看:60
本文介绍了Django默认用户权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在创建后立即为用户授予特定应用程序的默认权限?

Is it possible to give a user default permissions for a specific app, right after creation?

此处,但是我希望它已经有1.5年的历史了,现在有可能这样做.

There is a similar question here, but since it is 1,5 years old I hope, there is a possibility to do it now.

背景如下:

我只在Djangopage中运行一个应用程序.我们称之为"foo".
我的用户使用其LDAP帐户登录到管理页面.如果他们是第一次登录,则他们的帐户不在数据库中,并且将被创建.然后,他们登录后将无法执行任何操作,因为他们没有任何权限.我想在创建帐户后立即向他们授予我的"foo"应用程序的所有权限.目前,我需要使用管理员帐户登录并手动授予他们.

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.

推荐答案

如果您使用的是

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.

如果您使用其他方法进行身份验证,则可以使用 post_save 信号.

If you're using a different method to authenticate, then you can use the post_save signal.

这篇关于Django默认用户权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆