mirror of https://github.com/sipwise/repoapi.git
* We want to split build releases from hotfix perms * create dev and devops groups and assign desired permissions. These groups will match LDAP groups. * create permissions using hack stolen from https://stackoverflow.com/questions/29296757/django-data-migrate-permissions Change-Id: I1b82ebf13aa3cba05e4733e4bef186fbbb52bb13pull/7/head
parent
dcc424c7af
commit
10ce513d20
@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.2.13 on 2022-06-14 16:37
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("build", "0005_buildrelease_triggered_jobs"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="buildrelease",
|
||||
options={
|
||||
"permissions": [
|
||||
("can_trigger", "can trigger build releases"),
|
||||
("can_trigger_hotfix", "can trigger hotfix builds"),
|
||||
]
|
||||
},
|
||||
),
|
||||
]
|
||||
@ -0,0 +1,62 @@
|
||||
# Generated by Django 3.2.13 on 2022-06-14 16:12
|
||||
from django.contrib.auth.management import create_permissions
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def add_permissions(apps, schema_editor):
|
||||
"""ContentType table is populated after all the migrations applied"""
|
||||
for app_config in apps.get_app_configs():
|
||||
app_config.models_module = True
|
||||
create_permissions(app_config, verbosity=0)
|
||||
app_config.models_module = None
|
||||
|
||||
|
||||
def forwards_func(apps, schema_editor):
|
||||
add_permissions(apps, schema_editor)
|
||||
Group = apps.get_model("auth", "Group")
|
||||
Permission = apps.get_model("auth", "Permission")
|
||||
ContentType = apps.get_model("contenttypes", "ContentType")
|
||||
db_alias = schema_editor.connection.alias
|
||||
|
||||
Group.objects.using(db_alias).bulk_create(
|
||||
[Group(name="dev"), Group(name="devops")]
|
||||
)
|
||||
dev_grp = Group.objects.using(db_alias).get(name="dev")
|
||||
devops_grp = Group.objects.using(db_alias).get(name="devops")
|
||||
|
||||
BuildRelease = apps.get_model("build", "BuildRelease")
|
||||
ct = ContentType.objects.get_for_model(BuildRelease)
|
||||
|
||||
dev_grp.permissions.set(
|
||||
[
|
||||
Permission.objects.using(db_alias).get(
|
||||
content_type=ct, codename="can_trigger"
|
||||
),
|
||||
]
|
||||
)
|
||||
devops_grp.permissions.set(
|
||||
[
|
||||
Permission.objects.using(db_alias).get(
|
||||
content_type=ct, codename="can_trigger_hotfix"
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def reverse_func(apps, schema_editor):
|
||||
Group = apps.get_model("auth", "Group")
|
||||
db_alias = schema_editor.connection.alias
|
||||
Group.objects.using(db_alias).filter(name="dev").delete()
|
||||
Group.objects.using(db_alias).filter(name="devops").delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("repoapi", "0010_gerritrepoinfo_projectname"),
|
||||
("build", "0006_alter_buildrelease_options"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(forwards_func, reverse_func),
|
||||
]
|
||||
Loading…
Reference in new issue