diff --git a/gracedb/ligoauth/migrations/0044_create_robot_accounts_authgroup.py b/gracedb/ligoauth/migrations/0044_create_robot_accounts_authgroup.py new file mode 100644 index 0000000000000000000000000000000000000000..a47792b41772aad0d7ccf4b251208cbf4a52bf15 --- /dev/null +++ b/gracedb/ligoauth/migrations/0044_create_robot_accounts_authgroup.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-06-18 16:33 +from __future__ import unicode_literals + +from django.db import migrations + +AUTHGROUP_INFO = { + 'name': 'robot_accounts', + 'description': ('Shared robot accounts for LIGO/Virgo pipelines, ' + 'follow-up processes, etc.'), + 'ldap_name': 'Communities:robot:GraceDBrobotCert', +} + + +def create_authgroup(apps, schema_editor): + AuthGroup = apps.get_model('ligoauth', 'AuthGroup') + + # Create AuthGroup + AuthGroup.objects.create(**AUTHGROUP_INFO) + + +def delete_authgroup(apps, schema_editor): + AuthGroup = apps.get_model('ligoauth', 'AuthGroup') + + # Delete AuthGroup + ag = AuthGroup.objects.get(name=AUTHGROUP_INFO['name']) + ag.delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('ligoauth', '0043_x509cert_delete_users_m2m_field'), + ] + + operations = [ + migrations.RunPython(create_authgroup, delete_authgroup), + ] diff --git a/gracedb/ligoauth/migrations/0045_populate_robot_accounts_authgroup.py b/gracedb/ligoauth/migrations/0045_populate_robot_accounts_authgroup.py new file mode 100644 index 0000000000000000000000000000000000000000..e26d448e48add1207d3610fc3d75a1b5c8cf18d7 --- /dev/null +++ b/gracedb/ligoauth/migrations/0045_populate_robot_accounts_authgroup.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-06-18 16:42 +from __future__ import unicode_literals + +from django.db import migrations + +ROBOT_GROUP_NAME = 'robot_accounts' + + +# Add current RobotUsers to robot_accounts AuthGroup +def add_users(apps, schema_editor): + AuthGroup = apps.get_model('ligoauth', 'AuthGroup') + RobotUser = apps.get_model('ligoauth', 'RobotUser') + + group = AuthGroup.objects.get(name=ROBOT_GROUP_NAME) + for robot in RobotUser.objects.all(): + group.user_set.add(robot.user_ptr) + + +class Migration(migrations.Migration): + + dependencies = [ + ('ligoauth', '0044_create_robot_accounts_authgroup'), + ] + + operations = [ + migrations.RunPython(add_users, migrations.RunPython.noop), + ]