Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User groups and permissions

I need to implement user rights for user groups (pretty similar to facebook groups). For example, each group can have members with rights like: can_post, can_delete, can_ban, etc. Of course, one user can be a member of many groups and group can have many different users with different rights.

What models I need for this functionality?

like image 396
duke_nukem Avatar asked Sep 12 '12 17:09

duke_nukem


People also ask

What are permission groups?

A permission group is a query that returns a set of users based on defined criteria. Permission groups enable you to express your security needs in very rich ways. They simplify security management on your site.

What are the 3 types of permissions?

Permission Types Files and directories can have three types of permissions: read, write, and execute: Someone with read permission may read the contents of a file, or list the contents of a directory.

What are examples of user groups?

A software user group is a group of people who use a particular product or platform to discuss their experiences and gain support. For example, Oracle, IBM and the Android operating system all have user groups.

What are user account permissions?

Permissions are a method for assigning access rights to specific user accounts and user groups. Through the use of permissions, Windows defines which user accounts and user groups can access which files and folders, and what they can do with them.


1 Answers

Django has a built in groups system. Whenever you have a question like this, I recommend searching the Django docs, which are extensive, helpful, and well written.

So long as you are using the django.contrib.auth app, you have access to groups. You can then assign permissions to those groups.

from django.contrib.auth.models import User, Group, Permission from django.contrib.contenttypes.models import ContentType  content_type = ContentType.objects.get(app_label='myapp', model='BlogPost') permission = Permission.objects.create(codename='can_publish',                                        name='Can Publish Posts',                                        content_type=content_type) user = User.objects.get(username='duke_nukem') group = Group.objects.get(name='wizard') group.permissions.add(permission) user.groups.add(group) 
like image 135
Jordan Reiter Avatar answered Oct 13 '22 08:10

Jordan Reiter