-
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.
OM-70: add migration with modal role (#12)
* OM-70: add additional roles * OM-70: get models using get_model * OM-70: add migration that adds modal view right * OM-70: add operation in migrations --------- Co-authored-by: Jan <[email protected]>
- Loading branch information
1 parent
b59ae37
commit f18a902
Showing
2 changed files
with
48 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Generated by Django 3.2.21 on 2023-11-06 09:29 | ||
|
||
from django.db import migrations | ||
|
||
POLICY_HOLDER_SEARCH_PERM = [203000] | ||
ROLE_NAME_EMPLOYER = "Employer" | ||
|
||
|
||
def add_rights(role_name, role_model, role_right_model): | ||
role = role_model.objects.get(name=role_name) | ||
for right_id in POLICY_HOLDER_SEARCH_PERM: | ||
if not role_right_model.objects.filter(validity_to__isnull=True, role=role, right_id=right_id).exists(): | ||
_add_right_for_role(role, right_id, role_right_model) | ||
|
||
|
||
def _add_right_for_role(role, right_id, role_right_model): | ||
role_right_model.objects.create(role=role, right_id=right_id, audit_user_id=1) | ||
|
||
|
||
def remove_rights(role_id, role_right_model): | ||
role_right_model.objects.filter( | ||
role__is_system=role_id, | ||
right_id__in=POLICY_HOLDER_SEARCH_PERM, | ||
validity_to__isnull=True | ||
).delete() | ||
|
||
|
||
def on_migration(apps, schema_editor): | ||
role_model = apps.get_model("core", "role") | ||
role_right_model = apps.get_model("core", "roleright") | ||
add_rights(ROLE_NAME_EMPLOYER, role_model, role_right_model) | ||
|
||
|
||
def on_reverse_migration(apps, schema_editor): | ||
role_right_model = apps.get_model("core", "roleright") | ||
remove_rights(ROLE_NAME_EMPLOYER, role_right_model) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('msystems', '0003_add_search_policyholders_perms'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(on_migration, on_reverse_migration), | ||
] |