How to inherit permissions from other group

Hi all,
I want to create a group can inherit permissions from other group.

Ex:
developer
---- backend
---- frontend

Expected:

  • “developer” group have permission: sessions.add_session
  • “backend: group have permission: sessions.delete_session
    → the user:” dev1" in “backend” group have 2 permisson: sessions.delete_session, sessions.add_session.

I tried:

  1. Add parent filed in to group:
Group.add_to_class('parent', models.ForeignKey('self', null=True,
                     blank=True, on_delete=models.SET_NULL, related_name='children'))
  1. Create group: “developer” and “backend”. “developer” is parent of “backend”
  2. Create “backend_dev1” user and set it into group “backend”

When I login “backend_dev1”, it only have permission of “backend” group.
I also tried use signals to set permissions after create user, but it not work.
Even if it worked, it would be difficult to update permissions when parent groups have permission changes.
of course, I can set user have 2 group: ‘developer’ and ‘backend’.
But I’m looking for solution can auto inherit permissions from other group.
I hope to have some suggestions on this topic.
Many thanks !

The appropriate way to do this using the existing Django provided facilities is to make the individuals members of the parent groups.

To create a structure to what you’re saying you want to do here, both effectively and efficiently, you’d need to create a more efficient hierarchical structure for groups. The direct approach of creating a link to self does not scale well. (See the threads here on hierarchical data structures in the ORM.)

1 Like

Thank you !
I will refer other topic.