-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #432 from UW-GAC/feature/permission-rename
Give permissions better names
- Loading branch information
Showing
13 changed files
with
424 additions
and
331 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
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 +1 @@ | ||
__version__ = "0.20.dev3" | ||
__version__ = "0.20.dev4" |
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
56 changes: 56 additions & 0 deletions
56
anvil_consortium_manager/migrations/0014_rename_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,56 @@ | ||
# Generated by Django 4.2.7 on 2023-11-06 19:12 | ||
# We cannot easily test this migration using django-test-migrations because | ||
# permissions and content types are created via post-migrate signals, and | ||
# django-test-migrations mutes signals. | ||
# So this is only manually tested :( | ||
# | ||
# Some relevant stack overflow posts: | ||
# https://stackoverflow.com/questions/47182012/remove-old-permissions-in-django | ||
|
||
from django.db import migrations | ||
|
||
|
||
def set_up_new_permissions(apps, schema_editor): | ||
# Map between original codename and updated codename. | ||
permissions_codename_map = { | ||
"anvil_project_manager_edit": "anvil_consortium_manager_staff_edit", | ||
"anvil_project_manager_view": "anvil_consortium_manager_staff_view", | ||
"anvil_project_manager_limited_view": "anvil_consortium_manager_view", | ||
"anvil_project_manager_account_link": "anvil_consortium_manager_account_link", | ||
} | ||
# Map between original codename and updated name. | ||
permissions_name_map = { | ||
"anvil_project_manager_edit": "AnVIL Consortium Manager Staff Edit Permission", | ||
"anvil_project_manager_view": "AnVIL Consortium Manager Staff View Permission", | ||
"anvil_project_manager_limited_view": "AnVIL Consortium Manager View Permission", | ||
"anvil_project_manager_account_link": "AnVIL Consortium Manager Account Link Permission", | ||
} | ||
# Rename old permissions if they exist. | ||
Permission = apps.get_model("auth", "Permission") | ||
|
||
ContentType = apps.get_model("contenttypes", "ContentType") | ||
try: | ||
model = ContentType.objects.get(app_label="anvil_consortium_manager", model="anvilprojectmanageraccess") | ||
for original_codename in permissions_codename_map.keys(): | ||
permission = Permission.objects.get(content_type=model, codename=original_codename) | ||
# Update codename and name. | ||
permission.codename = permissions_codename_map[original_codename] | ||
permission.name = permissions_name_map[original_codename] | ||
# Save the new permission | ||
permission.save() | ||
except ContentType.DoesNotExist: | ||
# Permissions and ContentTypes are created after all migrations are completed using | ||
# post-migrate signals. If the ContentType for this app does not exist, then this is | ||
# the first time that "migrate" has been run, so no permissions need to be renamed. | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("anvil_consortium_manager", "0013_alter_anvilprojectmanageraccess_options"), | ||
] | ||
|
||
operations = [ | ||
# I could not get the reverse code to work - see comments above. | ||
migrations.RunPython(set_up_new_permissions, reverse_code=migrations.RunPython.noop), | ||
] |
25 changes: 25 additions & 0 deletions
25
anvil_consortium_manager/migrations/0015_add_new_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,25 @@ | ||
# Generated by Django 4.2.7 on 2023-11-06 22:55 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("anvil_consortium_manager", "0014_rename_permissions"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="anvilprojectmanageraccess", | ||
options={ | ||
"default_permissions": (), | ||
"managed": False, | ||
"permissions": [ | ||
("anvil_consortium_manager_staff_edit", "AnVIL Consortium Manager Staff Edit Permission"), | ||
("anvil_consortium_manager_staff_view", "AnVIL Consortium Manager Staff View Permission"), | ||
("anvil_consortium_manager_account_link", "AnVIL Consortium Manager Account Link Permission"), | ||
("anvil_consortium_manager_view", "AnVIL Consortium Manager View Permission"), | ||
], | ||
}, | ||
), | ||
] |
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
Oops, something went wrong.