2024-05-11 03:22:01 +00:00
|
|
|
# Generated by Django 4.1.13 on 2024-05-09 03:16
|
|
|
|
|
|
|
|
import common.db.models
|
|
|
|
from django.conf import settings
|
|
|
|
from django.db import migrations, models
|
2022-02-17 12:13:31 +00:00
|
|
|
|
|
|
|
from rbac.builtin import BuiltinRole
|
|
|
|
|
|
|
|
|
|
|
|
def create_builtin_roles(apps, schema_editor):
|
2022-02-21 08:24:03 +00:00
|
|
|
BuiltinRole.sync_to_db(show_msg=True)
|
2022-02-17 12:13:31 +00:00
|
|
|
|
|
|
|
|
2024-05-11 03:22:01 +00:00
|
|
|
def set_admin_roles(apps, schema_editor):
|
|
|
|
User = apps.get_model('users', 'User')
|
|
|
|
Role = apps.get_model('rbac', 'Role')
|
|
|
|
Org = apps.get_model('orgs', 'Organization')
|
|
|
|
RoleBinding = apps.get_model('rbac', 'RoleBinding')
|
|
|
|
user = User.objects.get(username='admin')
|
|
|
|
system_role = Role.objects.get(name='SystemAdmin')
|
|
|
|
org_role = Role.objects.get(name='OrgAdmin')
|
|
|
|
org = Org.objects.get(id='00000000-0000-0000-0000-000000000002')
|
|
|
|
RoleBinding.objects.create(user=user, role=system_role, scope='system')
|
|
|
|
RoleBinding.objects.create(user=user, role=org_role, scope='org', org=org)
|
|
|
|
|
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
('rbac', '0002_auto_20210929_1409'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
2024-05-11 03:22:01 +00:00
|
|
|
migrations.RunPython(create_builtin_roles),
|
|
|
|
migrations.RunPython(set_admin_roles),
|
2022-02-17 12:13:31 +00:00
|
|
|
]
|