Hello. I'm just an abstract object 📦 and I would be very glad to have user authorization because I hate criminals 🦹♂️ like pedophiles, robbers, hackers and so on.
Project description
django-object-checker
Hello. I'm just an abstract object 📦 and I would be very glad to have user authorization because I hate criminals 🦹♂️ like pedophiles, robbers, hackers and so on.
Introduction
Project django-object-checker extends standard django role base access control to be able to check individual object types.
Main purpose of this extended authorization system is to maintain control for each objects individually with modular solution.
Installation
# pip
pip install django-object-checker
# pipenv
pipenv install django-object-checker
# poetry
poetry add django-object-checker
Setup
Just add checkers module path to settings.OBJECT_CHECKERS_MODULE
:
The path is path to the module, where you going to implement all your checkers. This is required for our BaseObjectChecker to be able to find his subclasses.
OBJECT_CHECKERS_MODULE = 'app.checkers'
Example
1. Create module according to specified path in settings
2. Create your own ObjectChecker class with checker method
Valid check methods are only these, which name starts with
check_
. So if you want to implement your custom methods which you want to be ignored by BaseObjectChecker your hands are free.
from django.contrib.auth.models import Group, User
from object_checker.base_object_checker import ObjectChecker
class MyObjectChecker(ObjectChecker):
@staticmethod
def check_my_object(role: Group, user: User, obj):
result = False
if role.name == 'manager':
result = True
return result
3. Add new object check class to module __init__.py
from app.checkers.my_object_checker import MyObjectChecker
4. Example usage of your custom object checker in your project
Method to check is
has_object_permission
and has three arguments:
- name of check method
- user object
- object/objects to be checked
from object_checker.base_object_checker import has_object_permission
if has_object_permission('check_my_object', user, my_object):
print('User has access to this/these object/objects.')
else:
print('User has NOT access to this/these object/objects.')
Made with ❤ by Adam Žúrek & BACKBONE s.r.o.
0.1.0 : 2020-09-23
- Initial release
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
Built Distribution
Hashes for django-object-checker-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96abfa1c28f86a5764d6ee1df4045403b9d88bee6168001b39a51abaa8248bae |
|
MD5 | f7737981cefec39d0e9898b71d8bcfd7 |
|
BLAKE2b-256 | 99800d0fdcab6066526f634d069f143ad345358f8054065d5a7b472fc2a6d25a |
Hashes for django_object_checker-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d726083b9c2eb9f9c1b23b5218569282bc29a587949551d8920a376e88e44d1 |
|
MD5 | 120ad85c7ec25acebaa127323d7e731e |
|
BLAKE2b-256 | 75a8e4a9eee7b18de5dbc04e4d6317a712190b12481d39151ec33109125d5471 |