Skip to content

Commit

Permalink
ONI-174: Add util to remove permission from a role. (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzglinieckisoldevelo authored Oct 9, 2023
1 parent baa752f commit 736f422
Showing 1 changed file with 14 additions and 0 deletions.
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

0 comments on commit 736f422

Please sign in to comment.