Skip to content

Commit

Permalink
v11.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GitRon committed Jul 19, 2024
1 parent 3c9b457 commit 9e9c920
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

**11.1.0** (2024-07-16)
**11.1.1** (2024-07-19)
* Fixed a bug leading to missing docs

**11.1.0** (2024-07-18)
* Added static role permission feature

**11.0.3** (2024-07-16)
Expand Down
2 changes: 1 addition & 1 deletion ambient_toolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Python toolbox of Ambient Digital containing an abundance of useful tools and gadgets."""

__version__ = "11.1.0"
__version__ = "11.1.1"
22 changes: 11 additions & 11 deletions docs/features/static_role_permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ based on a static (hardcoded) definition of roles and permissions.

1. Add `StaticRolePermissionBackend` to your `AUTHENTICATION_BACKENDS` in the `settings.py`:

```py
```python
AUTHENTICATION_BACKENDS = [
# ... other backends
# 'django.contrib.auth.backends.ModelBackend', <-- replace the default ModelBackend
Expand All @@ -24,12 +24,12 @@ AUTHENTICATION_BACKENDS = [
Example:

`settings.py`
```py
```python
STATIC_ROLE_PERMISSIONS_PATH = "my_project.conf.permisions.PERMISSIONS_DICT"
```

`my_project.conf.permisions.py`
```py
```python
PERMISSIONS_DICT: dict[str, set[str]] = {
"role_1": {"my_app.permission_1", "my_app.permission_2", ...},
"role_2": {...},
Expand All @@ -43,9 +43,9 @@ By default, a system check will match the values against the Django model permis
In theory, roles and permissions could be any hashable value. Just make sure that the return value of `User.role`
matches the keys of the dictionary.

3. add `ambient_toolbox` to your `INSTALLED_APPS` in the `settings.py` if not already done:
3. Add `ambient_toolbox` to your `INSTALLED_APPS` in the `settings.py` if not already done:

```py
```python
INSTALLED_APPS = [
# ... other apps
"ambient_toolbox",
Expand All @@ -56,7 +56,7 @@ This is needed to register the [system check](#system-check).

## Simple example

```py
```python
PERMISSIONS_DICT: dict[str, set[str]] = {
"admin": {
"auth.view_user",
Expand All @@ -81,7 +81,7 @@ User(is_staff=True).has_perm("auth.edit_user") # --> True (without any db query

This library does not require a role field on the user model, but here is an example how you could implement it:

```py
```python
class UserRoleChoices(models.TextChoices):
ADMIN = "ADMIN", "Admin"
EMPLOYEE = "EMPLOYEE", "Employee"
Expand Down Expand Up @@ -122,16 +122,16 @@ Django permission system in a nutshell:
- User have permissions (n:m)
- Users have groups (n:m)
- Groups have permissions (n:m)
- So a user has all permissions of his groups and his own permissions combined
- So a user has all permissions of their groups and their own permissions combined
- Permissions are strings like `app_label.permission_name` (e.g. `polls.view_poll`)
- Groups, Permissions and their relations are stored in the db and can be managed via the admin interface at runtime

However, in many cases this adds of lot of complexity to the application, which is not needed.
However, in many cases, this adds a lot of complexities to the application, which is not needed.

- When users should only have one group at a time, you still need to manage an n:m relation
- When permissions should not change at runtime, you still need to create and query the permissions via your database.
- When your authorisation logic is not based on permissions at all, you probably still need to deal with permission,
e.g. in Django Admin, because the Django ecosystem is build around this system.
e.g. in Django Admin, because the Django ecosystem is built around this system.

This library provides a much simpler way to manage permissions, which is based roles and a hardcoded
set of permissions per role.
Expand All @@ -143,6 +143,6 @@ If your reality is more complex than that, you should not use it.

E.g when:

- User should have more than one role at a time
- Users should have more than one role at a time
- Permissions should be managed at runtime
- You need to assign permissions to individual users
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The package is published at pypi under the following link: `https://pypi.org/pro
features/selectors.md
features/sentry.md
features/services.md
features/static_role_permissions.md
features/tests.md
features/translations.md
features/utils.rst
Expand Down

0 comments on commit 9e9c920

Please sign in to comment.