-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Custom generic object permission models (#657)
* GUARDIAN_USER_OBJ_PERMS_USE and GUARDIAN_GROUP_OBJ_PERMS_USE support * Document GUARDIAN_USER_OBJ_PERMS_USE and GUARDIAN_GROUP_OBJ_PERMS_USE * example_project using GUARDIAN_USER_OBJ_PERMS_USE and GUARDIAN_GROUP_OBJ_PERMS_USE * Update docs/configuration.rst Co-Authored-By: Michael <michael-k@users.noreply.github.com> * Conf settings should end in _MODEL, not _USE * Explicit exception chaining during model lookup * Fix typo in exception chaining * Add __all__ = […] to silence unused-import warnings in models/__init__ * Code comment should use _MODEL, not _USE
- Loading branch information
Showing
15 changed files
with
263 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
example_project/articles/migrations/0002_custom_generic_permissions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Generated by Django 2.1.14 on 2019-11-14 10:41 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('auth', '0009_alter_user_last_name_max_length'), | ||
('contenttypes', '0002_remove_content_type_name'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('articles', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='BigGroupObjectPermission', | ||
fields=[ | ||
('object_pk', models.CharField(max_length=255, verbose_name='object ID')), | ||
('id', models.BigAutoField(editable=False, primary_key=True, serialize=False, unique=True)), | ||
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), | ||
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.Group')), | ||
('permission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.Permission')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='BigUserObjectPermission', | ||
fields=[ | ||
('object_pk', models.CharField(max_length=255, verbose_name='object ID')), | ||
('id', models.BigAutoField(editable=False, primary_key=True, serialize=False, unique=True)), | ||
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), | ||
('permission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.Permission')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.AddIndex( | ||
model_name='biguserobjectpermission', | ||
index=models.Index(fields=['content_type', 'object_pk'], name='articles_bi_content_3fff51_idx'), | ||
), | ||
migrations.AddIndex( | ||
model_name='biguserobjectpermission', | ||
index=models.Index(fields=['content_type', 'object_pk', 'user'], name='articles_bi_content_a2ac4b_idx'), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='biguserobjectpermission', | ||
unique_together={('user', 'permission', 'object_pk')}, | ||
), | ||
migrations.AddIndex( | ||
model_name='biggroupobjectpermission', | ||
index=models.Index(fields=['content_type', 'object_pk'], name='articles_bi_content_824ecd_idx'), | ||
), | ||
migrations.AddIndex( | ||
model_name='biggroupobjectpermission', | ||
index=models.Index(fields=['content_type', 'object_pk', 'group'], name='articles_bi_content_61c3ef_idx'), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='biggroupobjectpermission', | ||
unique_together={('group', 'permission', 'object_pk')}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from .models import ( | ||
UserObjectPermissionBase, | ||
UserObjectPermissionAbstract, | ||
GroupObjectPermissionBase, | ||
GroupObjectPermissionAbstract, | ||
Permission, | ||
Group | ||
) | ||
|
||
# Must import after .models | ||
# When .models is loaded, default generic object permissions are created | ||
# The following statements may redirect external references to custom | ||
# generic object permission models | ||
from guardian.utils import get_user_obj_perms_model, get_group_obj_perms_model | ||
UserObjectPermission = get_user_obj_perms_model() | ||
GroupObjectPermission = get_group_obj_perms_model() | ||
|
||
__all__ = [ | ||
'UserObjectPermissionBase', | ||
'UserObjectPermissionAbstract', | ||
'GroupObjectPermissionBase', | ||
'GroupObjectPermissionAbstract', | ||
'Permission', | ||
'Group', | ||
'UserObjectPermission', | ||
'GroupObjectPermission' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.