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

Add migration aimed at removing RBAC on RBAC roles #192

Merged
merged 3 commits into from
Jan 28, 2020
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
36 changes: 36 additions & 0 deletions rbac/management/migrations/0012_remove_RonR_resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 2.2.4 on 2019-11-26 17:03

from django.db import migrations, models


def remove_rbac_roles(apps, schema_editor):
# get all permissions/access objects for RBAC
Access = apps.get_model('management', 'Access')
rbac_permissions = Access.objects.filter(permission__contains='rbac:')

# iterate through all RBAC permissions
for rbac_permission in rbac_permissions:
# get the role for the permission (bubbling up)
role = rbac_permission.role

# check to see if there are any access objects that are not RBAC
non_rbac_permissions = role.access.exclude(permission__contains='rbac:')

# if so, just delete the access object we know is RBAC, and leave the role
if non_rbac_permissions:
# this will still delete the resource definitions for the access object
rbac_permission.delete()
else:
# otherwise, we only have RBAC access objects, so delete everything
role.delete()


class Migration(migrations.Migration):

dependencies = [
('management', '0011_group_naming'),
]

operations = [
migrations.RunPython(remove_rbac_roles)
]