Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ONI-174: Added migration with query rights to roles. #37

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
]
Loading