{"id":15024451,"url":"https://github.com/certego/django-group-role","last_synced_at":"2025-04-12T06:30:56.594Z","repository":{"id":45432577,"uuid":"430672910","full_name":"certego/django-group-role","owner":"certego","description":"A simple django app to manage group-based role permissions","archived":false,"fork":false,"pushed_at":"2025-04-03T07:17:41.000Z","size":88,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-03T07:39:25.167Z","etag":null,"topics":["authentication","django","roles-management"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/certego.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-22T11:06:53.000Z","updated_at":"2025-04-03T07:17:11.000Z","dependencies_parsed_at":"2024-10-14T04:40:27.786Z","dependency_job_id":null,"html_url":"https://github.com/certego/django-group-role","commit_stats":{"total_commits":21,"total_committers":2,"mean_commits":10.5,"dds":0.04761904761904767,"last_synced_commit":"58a736c309ecfe7b7af3c6757639caae410c93b4"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/certego%2Fdjango-group-role","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/certego%2Fdjango-group-role/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/certego%2Fdjango-group-role/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/certego%2Fdjango-group-role/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/certego","download_url":"https://codeload.github.com/certego/django-group-role/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248529323,"owners_count":21119488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","django","roles-management"],"created_at":"2024-09-24T20:00:22.566Z","updated_at":"2025-04-12T06:30:56.170Z","avatar_url":"https://github.com/certego.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django Group Role\n[![Linters/Tests][ci-badge]][ci]\n[![PyPI versions][pypi-badge]][pypi]\n[![PyPI pyversions][pythonver]][pypi]\n[![Django version][djversion]][pypi]\n\n`django-group-role` aims to simplify \"role based access\" in django-based projects and applications.\nThis app is build on top on `contrib.auth` and `guardian` apps.\n\n\n`django-group-role` aims to enhance existing `Group` and `Permission` models of `contrib.auth` app to configure global-level access rules.\n\n## Install\nFirst add `'django_group_role'` to `INSTALLED_APPS` after `contrib.auth` and `guardian` and then configure the \"role-definition\" module:\n\n```PYTHON\nINSTALLED_APPS = [\n    ...\n    \"django.contrib.auth\",\n    ...\n    \"guardian\",\n    \"django_group_role\",\n    ...\n]\n\n# every used role must be registered in this module\nROLES_MODULE = \"myproject.roles\"\n```\n\n\n## Basic Setup\n\n\"Roles\" are classes derived from `django_group_role.roles.Role` and should declare the following two attributes:\n\n- `name`: the name of the group which will be bound to this role (mandatory)\n- `permissions`: specify which permissions are granted to this role, it may be indicated in one of the following form:\n   - a _list_ of available permission which will be bound to this role, they must be provided using the notation `'\u003cappname\u003e.\u003ccodename\u003e'`\n   - a _dict_ which keys can be app-names or `\u003cappname.model\u003e` (see example below)\n\n```python\nfrom django_group_role import Role\n\n\nclass BasicRole(Role):\n    name = \"Base\"\n    abstract = True\n    permissions = [\"auth.view_user\", \"auth.view_group\"]\n\n\nclass ExpandedRole(BasicRole):\n    name = \"Expanded\"\n    permissions = [\"auth.add_user\", \"auth.change_user\"]\n\n\nclass DerivedRole(BasicRole):\n    name = \"Derived\"\n    permissions = {\n        'auth': {\n            'user': ['view_user', 'add_user', 'delete_user']\n        },\n        'auth.group': ['view_group'],\n    }\n\n```\n\n\u003e NOTE: to do not have the command creating a \"base\" group set it as ``abstract = True``\n\n\n## Role inheritance\nRoles can derive one-another like normal python classes, when a roles extend an other one it is not required to provide the `permissions` list. When extending an existing role its permissions gets merged with those defined in the base class.\n\n\u003e NOTE: ATM multi-role inheritance is not tested, it may work but it is not guaranteed.\n\n## Database alignment\nSince `Role` classes are not bound to database `Group` they must be synchronized in order to work as expected. To perform this the management command `populate_roles` is available. This command takes every configured role defined in `ROLES_MODULE` and set-up its permissions on the database, also creating the appropriate group if it does not exists yet.\n\nSee command help for further information regarding its arguments.\n\n### Signals\nUpon setup each role fires two signals:\n\n- `pre_role_setup`: before the setup process starts, providing `role` and `clear` kwargs\n- `post_role_setup`: after the setup process ends, providing `role` kwargs\n\n## Use in unittest (TestCase)\nFor django style `TestCase` based testing is it possible to use the `RoleEnabledTestMixin`. This overrides the `setUpTestData` to load and create role-related data before running tests.\n\n\u003e NOTE: ATM it is not guaranteed that loading different roles in each test may not collide, it could be released in the future.\n\n----\n\n\n## Credits\n\nThis work was in part inspired by [django-role-permissions](https://github.com/vintasoftware/django-role-permissions).\n\n\n[pypi]: https://pypi.org/project/django-group-role/\n[pypi-badge]: https://img.shields.io/pypi/v/django-group-role\n[pythonver]: https://img.shields.io/pypi/pyversions/django-group-role\n[djversion]: https://img.shields.io/pypi/djversions/django-group-role\n[ci]: https://github.com/certego/django-group-role/actions/workflows/ci.yaml\n[ci-badge]: https://github.com/certego/django-group-role/actions/workflows/ci.yaml/badge.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcertego%2Fdjango-group-role","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcertego%2Fdjango-group-role","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcertego%2Fdjango-group-role/lists"}