vintasoftware / django-role-permissions

A django app for role based permissions.
http://django-role-permissions.readthedocs.org/
MIT License
728 stars 114 forks source link

Can I do this with this git project? #127

Closed simeon49 closed 3 years ago

simeon49 commented 3 years ago

Hello everyone, we have the following requirements recently.

in departmet/models.py

class Department(models.Model):
      name = models.CharField()
      ....

in customer_resources/models.py

class CustomerResource(models.Model):
      customer = models.ForeignKey(User)
      belong_department = models.ForeignKey(Department)

     class Meta:
        default_permissions = ()
        permissions = [
            ('view_customer_resource', 'can view customer info'),
            ('change_customer_resource', 'can change customer info'),
            ....
        ]

I want create a manager group for department A, the one who is in this group can "view", "change", ... all the customer resources that belong to department A.

depart_a = Department(...)
depart_a_manager_group = Group.objects.create(...)

assign_perm('view_customer_resource', depart_a_manager_group, depart_a)

manager_01 = User(...)
manager_01.groups.add(depart_a_manager_group)

customer_01 = CustomerResource(belong_department=depart_a, ...)
assert user.has_permissions('view_customer_resource', customer_01), 'how to do this???, any one help'

Can I do this with this git project?

simeon49 commented 3 years ago

any one help?

filipeximenes commented 3 years ago

Hi @simeon49, yes, I believe this project is capable of doing something like what you described. But that's pretty what most permission libraries you find [including the default django permissions tooling] will do, so I suggest you study the docs and play with the library before you decide if it fits your needs

simeon49 commented 3 years ago

Hi @simeon49, yes, I believe this project is capable of doing something like what you described. But that's pretty what most permission libraries you find [including the default django permissions tooling] will do, so I suggest you study the docs and play with the library before you decide if it fits your needs

Thank you

filipeximenes commented 3 years ago

I'm going to close this ticket for now, feel free to reopen it in case you have more questions :)