Skip to main content

Perms for iscore library

Project description

https://badge.fury.io/py/django-fperms-iscore.svg https://travis-ci.org/Formulka/django-fperms-iscore.svg?branch=master https://codecov.io/gh/Formulka/django-fperms-iscore/branch/master/graph/badge.svg

Perms for iscore library

Documentation

The full documentation is at https://django-perms-iscore.readthedocs.io.

Quickstart

Install django-fperms-iscore:

pip install django-fperms-iscore

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'fperms_iscore.apps.FPermsConfig',
    ...
)

It includes all the basic permissions from http://github.com/formulka/django-fperms and adds a new type:

  • core: for iscore specific resources

Usage

A 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:

from fperms_iscore import enums
from fperms_iscore.models import IsCorePerm

IsCorePerm.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 custom perms manager 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:

from django.auth.models import User, Group

from fperms_iscore.models import IsCorePerm

perm = 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 setting PERM_AUTO_CREATE variable in your project settings to True, 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 via has_perm method of the perms manager 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',
)

assert user.perms.has_perm(perm)
assert user.perms.has_perm('core.issue_tracker.IssueIsCore.create')

New perm type

core

  • permission for iscore specific resources

  • type is defined as fperms_iscore.enums.PERM_TYPE_CORE

  • codename is usually one of the CRUD operations (create, read, update, delete)

  • it requires type, codename and core fields

  • string 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 Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package:

History

0.2.16 (2020-11-03)

  • Better cache for user permissions

0.2.15 (2020-10-24)

  • New django-fperms library and related changes

0.2.14 (2020-10-22)

  • Better verbose name of default permission

  • Improved sync_permissions command, unchanged permissions are not printed as updated

0.1.0 (2018-03-13)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-fperms-iscore-0.2.21.tar.gz (11.8 kB view details)

Uploaded Source

File details

Details for the file django-fperms-iscore-0.2.21.tar.gz.

File metadata

  • Download URL: django-fperms-iscore-0.2.21.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.10

File hashes

Hashes for django-fperms-iscore-0.2.21.tar.gz
Algorithm Hash digest
SHA256 a42414c3ce0db9e338d2023ba47db6331e7660596d0d2522d7baf5dabd9e6625
MD5 b141b609cd09e05dac24758a5ab0bc06
BLAKE2b-256 662e58c73d838ae6b6b05e5a52294f924f6367a15305ab5243395fe432ab6530

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page