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: Add util to remove permission from a role. #223

Merged
merged 1 commit 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
14 changes: 14 additions & 0 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,20 @@ def insert_role_right_for_system(system_role, right_id):
return role_right


def remove_role_right_for_system(system_role, right_id):
RoleRight = apps.get_model("core", "RoleRight")
Role = apps.get_model("core", "Role")
existing_role = Role.objects.filter(is_system=system_role, validity_to__isnull=True).first()
if not existing_role:
logger.warning("Migration requested to remove a role_right for system role %s but couldn't find that role", system_role)
role_right = RoleRight.objects.filter(role=existing_role, right_id=right_id).first()
if role_right:
role_right.delete()
logger.info("Role right removed for system role %s and right ID %s", system_role, right_id)
else:
logger.warning("Role right not found for system role %s and right ID %s", system_role, right_id)


def convert_to_python_value(string):
try:
value = ast.literal_eval(string)
Expand Down