-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bump django from 5.0.6 to 5.0.7 in /server Bumps [django](https://github.com/django/django) from 5.0.6 to 5.0.7. - [Commits](django/django@5.0.6...5.0.7) --- updated-dependencies: - dependency-name: django dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> * add Django Guardian to project * configure django guardian and add Site and Org specific object level permission models * remove our implementations of the Role and Permission model * adjust site permission/role verbose name and admin representation --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
97e073e
commit 00124bf
Showing
15 changed files
with
290 additions
and
110 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
47 changes: 47 additions & 0 deletions
47
server/apps/core/migrations/0004_grouppermission_userpermission.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,47 @@ | ||
# Generated by Django 5.0.6 on 2024-07-22 19:25 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('auth', '0012_alter_user_first_name_max_length'), | ||
('contenttypes', '0002_remove_content_type_name'), | ||
('core', '0003_role'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='GroupPermission', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('object_pk', models.CharField(max_length=255, verbose_name='object ID')), | ||
('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, | ||
'indexes': [models.Index(fields=['content_type', 'object_pk'], name='core_groupp_content_9384ee_idx')], | ||
'unique_together': {('group', 'permission', 'object_pk')}, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='UserPermission', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('object_pk', models.CharField(max_length=255, verbose_name='object ID')), | ||
('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, | ||
'indexes': [models.Index(fields=['content_type', 'object_pk'], name='core_userpe_content_92a909_idx')], | ||
'unique_together': {('user', 'permission', 'object_pk')}, | ||
}, | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
server/apps/core/migrations/0005_remove_role_permissions_delete_permission_and_more.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,23 @@ | ||
# Generated by Django 5.0.6 on 2024-07-22 20:03 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0004_grouppermission_userpermission'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='role', | ||
name='permissions', | ||
), | ||
migrations.DeleteModel( | ||
name='Permission', | ||
), | ||
migrations.DeleteModel( | ||
name='Role', | ||
), | ||
] |
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 was deleted.
Oops, something went wrong.
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
43 changes: 43 additions & 0 deletions
43
server/apps/org/migrations/0003_orggroupobjectpermission_orguserobjectpermission.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,43 @@ | ||
# Generated by Django 5.0.6 on 2024-07-22 19:25 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('auth', '0012_alter_user_first_name_max_length'), | ||
('org', '0002_rename_trakorg_org_rename_trakorgaccess_orgaccess'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='OrgGroupObjectPermission', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('content_object', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='org.org')), | ||
('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, | ||
'unique_together': {('group', 'permission', 'content_object')}, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='OrgUserObjectPermission', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('content_object', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='org.org')), | ||
('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, | ||
'unique_together': {('user', 'permission', 'content_object')}, | ||
}, | ||
), | ||
] |
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 |
---|---|---|
@@ -1,10 +1,31 @@ | ||
from django.contrib import admin | ||
from django.contrib.auth.models import Permission | ||
from django.contrib.contenttypes.models import ContentType | ||
from guardian.admin import GuardedModelAdmin | ||
|
||
from apps.site.models import Site | ||
from apps.site.models import Site, SiteGroupObjectPermission, SiteUserObjectPermission | ||
|
||
|
||
@admin.register(Site) | ||
class HaztrakSiteAdmin(admin.ModelAdmin): | ||
list_display = ["__str__", "last_rcrainfo_manifest_sync"] | ||
readonly_fields = ["rcra_site"] | ||
search_fields = ["rcra_site__epa_id"] | ||
|
||
|
||
@admin.register(SiteUserObjectPermission) | ||
class SiteUserObjectPermissionAdmin(GuardedModelAdmin): | ||
def formfield_for_foreignkey(self, db_field, request, **kwargs): | ||
if db_field.name == "permission": | ||
content_type = ContentType.objects.get_for_model(Site) | ||
kwargs["queryset"] = Permission.objects.filter(content_type=content_type) | ||
return super().formfield_for_foreignkey(db_field, request, **kwargs) | ||
|
||
|
||
@admin.register(SiteGroupObjectPermission) | ||
class SiteGroupObjectPermissionAdmin(GuardedModelAdmin): | ||
def formfield_for_foreignkey(self, db_field, request, **kwargs): | ||
if db_field.name == "permission": | ||
content_type = ContentType.objects.get_for_model(Site) | ||
kwargs["queryset"] = Permission.objects.filter(content_type=content_type) | ||
return super().formfield_for_foreignkey(db_field, request, **kwargs) |
Oops, something went wrong.