Skip to content

Commit

Permalink
ONI-174: Added migration with query rights to roles. (#37)
Browse files Browse the repository at this point in the history
* ONI-174: Added migration with query rights to roles.

* ONI-174: Changed comment in migration.
  • Loading branch information
wzglinieckisoldevelo authored and tdethier committed Nov 15, 2023
1 parent 7669e12 commit d084add
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions report/migrations/0010_add_query_rights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 3.2.17 on 2023-03-01 15:02
import logging

from django.db import migrations

from core.utils import insert_role_right_for_system, remove_role_right_for_system

logger = logging.getLogger(__name__)

# It is a dictionary with IsSystem values, it maps to RoleIDs:
# ROLES_ID = [1, 2, 3, 5, 6, 7, 11, 12]
ROLES_ID = [1, 2, 4, 16, 32, 64, 524288, 1048576]
REPORT_QUERY_ROLE_ID = 131200


def add_query_rights(apps, schema_editor):
"""
Add gql_query_reports_perms to every role with report permission (based on existing data).
"""
for role in ROLES_ID:
insert_role_right_for_system(role, REPORT_QUERY_ROLE_ID)


def remove_query_rights(apps, schema_editor):
"""
Add gql_query_reports_perms to every role with report permission (based on existing data).
"""
for role in ROLES_ID:
remove_role_right_for_system(role, REPORT_QUERY_ROLE_ID)


class Migration(migrations.Migration):
dependencies = [
('report', '0009_set_managed_to_true'),
]

operations = [
migrations.RunPython(add_query_rights, remove_query_rights),
]

0 comments on commit d084add

Please sign in to comment.