Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Giving default permissions or a default group to new users

Default behaviour seems to be new users have no permissions and no groups. However I'd like not to have to manually grant every single new users basic permissions, and I'd assume they'd like not to have to wait for me to do so.

How should I assign default permissions for new users?

Some similar questions have been asked but with no clear answer for the general case:

  • Django default user permissions
  • How do I define default permissions for users in Django Guardian?
  • Django Assign-perm w/ Post-Save Signal

I'm using python-social-auth so I don't have my own create-user form and view which I guess is where everyone else sets default permissions. I assume I need an on-user-create hook of some sort but not sure what the cleanest approach is.

This is unrelated to creating the default possible permissions that may be granted to users, although for reference,

  • Default permission/group data in Django
  • In Django, how do you programmatically create a group with permissions
like image 805
jozxyqk Avatar asked Jul 10 '15 06:07

jozxyqk


People also ask

What are the default permissions of a newly created file?

New files created in your account are given a default protection of 644 (that is, 666 - 022), which grants read and write permission to the owner of the file, and read permission to the group and others.

What is the default permission newly created file and directory?

These values are additive for each "triplet", meaning that a file permission of rw- has the value of 6 and rwx has the value of 7. As discussed above, any file that's newly created, the default value is 644 (rw-r--r--), meaning that the file's owner can read and write, and all others can only read this file.

How do I change the default permissions on a file?

To change the default permissions that are set when you create a file or directory within a session or with a script, use the umask command. The syntax is similar to that of chmod (above), but use the = operator to set the default permissions.

Which of the following action can be used to restrict non admin users from creating security principals in an Azure AD tenant?

Instead, create a Conditional Access policy that targets Microsoft Azure Management will block non-administrators access to Microsoft Azure Management.


1 Answers

You can subscribe to post_save signal on User model and put newly created user to desired group or add permissions.

from django.contrib.auth.models import Group

def add_to_default_group(sender, **kwargs):
    user = kwargs["instance"]
    if kwargs["created"]:
        group = Group.objects.get(name='groupname')
        user.groups.add(group)

And on django 1.8+ put following code into your AppConfig.ready()

from django.conf import settings

post_save.connect(add_to_default_group, sender=settings.AUTH_USER_MODEL)
like image 116
kmmbvnr Avatar answered Oct 12 '22 13:10

kmmbvnr