0

Is there a built in way to assign functional permissions to users in Django? From documentations looks like Dajngo permissions are bound to Models.

For example, what I want is to create is 4 types of user groups: Normal users, Managers, Admins and Superadmin.

By default users in different groups will have access to perform different kinds of actions. For example users in Admin group can perform Task1, Task2 and Task3, but users in Managers group can only perform Task1 and Task2(no matter in which app these Tasks are).

Further, user permissions can be modified for a user to revoke access from performing certain task. For example, by default all Admins can perform Task1, Task2 and Task3, but a particular admin's permission can be modified to perform only Task1 and Task3.

Can this be achieved by build in Django permissions and groups or will need to write own permission system(or is there third-party Django app to do this)?

If it will be better to write own permission and group system, any suggestion for design to follow.

Thanks!

Harshveer Singh
  • 4,037
  • 7
  • 37
  • 45
  • The has_permission decorator can be used for views, that is a lot to manage -- users, groups and permissions. I have use django-guardian for Role Based Access Control. It might suit your needs. – fiacre Apr 03 '17 at 04:41

1 Answers1

1

You can set the permissions in the admin page like foo.can_write or in your own view like

myuser.user_permissions.add(permission, permission, ...)

In the view you can set the permissions needed for some action. From documentations:

from django.contrib.auth.decorators import permission_required
@permission_required('polls.can_vote')
def my_view(request):
Mattia
  • 961
  • 13
  • 25