Package: django-fperms-iscore
Perms for iscore libraryDocumentationThe full documentation is athttps://django-perms-iscore.readthedocs.io.QuickstartInstall django-fperms-iscore:pip install django-fperms-iscoreAdd it to yourINSTALLED_APPS:INSTALLED_APPS=(...'fperms_iscore.apps.FPermsConfig',...)It includes all the basic permissions fromhttp://github.com/formulka/django-fpermsand adds a new type:core: for iscore specific resourcesUsageA superuser has for all intents and purposes permission to do everything. For regular users you can assign permissions directly or via a user group.Creating a new permission:You can create a new permission directly via its model or via a specially formated string:fromfperms_iscoreimportenumsfromfperms_iscore.modelsimportIsCorePermIsCorePerm.objects.create(type=enums.PERM_TYPE_CORE,codename='create',core='issue_tracker.IssueIsCore',)IsCorePerm.objects.create_from_str('core.issue_tracker.IssueIsCore.create')Assigning a permission:You can assign existing permission via the custompermsmanager available for both User (including custom ones) and Group models. You can add single permission or multiple both directly via its instance or using the formated string:fromdjango.auth.modelsimportUser,Groupfromfperms_iscore.modelsimportIsCorePermperm=IsCorePerm.objects.create_from_str('core.issue_tracker.IssueIsCore.create')user=User.objects.get(pk=1)user.perms.add_perm(perm)group=Group.objects.get(pk=1)group.perms.add_perm('core.issue_tracker.IssueIsCore.create')By default if said permission does not exist, it will raise an exception. You can override this behavior by settingPERM_AUTO_CREATEvariable in your project settings toTrue, assigning a permission will then create it as well if it does not exist.Retrieving permission instance:You can get a permission instance directly from the model or via the string representation.perm=IsCorePerm.objects.get(type=enums.PERM_TYPE_CORE,codename='create',core='issue_tracker.IssueIsCore',)perm=IsCorePerm.objects.get_from_str('core.issue_tracker.IssueIsCore.create')Checking permission:You can check whether the user or group has a required permission viahas_permmethod of thepermsmanager again using both the permission instance or the string representation....perm=IsCorePerm.objects.create(type=enums.PERM_TYPE_CORE,codename='create',core='issue_tracker.IssueIsCore',)assertuser.perms.has_perm(perm)assertuser.perms.has_perm('core.issue_tracker.IssueIsCore.create')New perm typecorepermission for iscore specific resourcestype is defined asfperms_iscore.enums.PERM_TYPE_COREcodename is usually one of the CRUD operations (create, read, update, delete)it requirestype,codenameandcorefieldsstring representation is'core.<app_label>.<core_name>.<codename>'...# equivalent results:IsCorePerm.objects.create(type=enums.PERM_TYPE_CORE,codename='create',core='issue_tracker.IssueIsCore',)IsCorePerm.objects.create_from_str('core.issue_tracker.IssueIsCore.create')Running TestsDoes the code actually work?source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ toxRunning TestsDoes the code actually work?source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ toxCreditsTools used in rendering this package:Cookiecuttercookiecutter-djangopackageHistory0.2.16 (2020-11-03)Better cache for user permissions0.2.15 (2020-10-24)New django-fperms library and related changes0.2.14 (2020-10-22)Better verbose name of default permissionImproved sync_permissions command, unchanged permissions are not printed as updated0.1.0 (2018-03-13)First release on PyPI.