From 2e669ff43b3251271c2525a415c15a60b8f3a67c Mon Sep 17 00:00:00 2001
From: GraceDB <gracedb@gracedb-dev2.ligo.uwm.edu>
Date: Wed, 8 May 2019 12:39:27 -0500
Subject: [PATCH] Update spiir account

---
 .../0030_update_spiir_acct_and_certs.py       | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 gracedb/ligoauth/migrations/0030_update_spiir_acct_and_certs.py

diff --git a/gracedb/ligoauth/migrations/0030_update_spiir_acct_and_certs.py b/gracedb/ligoauth/migrations/0030_update_spiir_acct_and_certs.py
new file mode 100644
index 000000000..6730f0fbc
--- /dev/null
+++ b/gracedb/ligoauth/migrations/0030_update_spiir_acct_and_certs.py
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-03-15 20:38
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+ACCOUNT = {
+    'old_username': 'gstlal-spiir',
+    'new_username': 'spiir',
+    'old_last_name': 'GSTLAL SPIIR Analysis',
+    'new_last_name': 'SPIIR',
+    'new_subject': '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=ldas-pcdev11.ligo.caltech.edu/CN=spiir/CN=Qi Chu/CN=UID:qi.chu.robot',
+}
+
+
+def update_acct(apps, schema_editor):
+    RobotUser = apps.get_model('ligoauth', 'RobotUser')
+
+    # Get user
+    user = RobotUser.objects.get(username=ACCOUNT['old_username'])
+
+    # Create new certificate for user
+    user.x509cert_set.create(subject=ACCOUNT['new_subject'])
+
+    # Update user information
+    user.username = ACCOUNT['new_username']
+    user.last_name = ACCOUNT['new_last_name']
+    user.save(update_fields=['username', 'last_name'])
+
+
+def revert_acct(apps, schema_editor):
+    RobotUser = apps.get_model('ligoauth', 'RobotUser')
+
+    # Get user
+    user = RobotUser.objects.get(username=ACCOUNT['new_username'])
+
+    # Delete new certificate
+    user.x509cert_set.get(subject=ACCOUNT['new_subject']).delete()
+
+    # Revert user information
+    user.username = ACCOUNT['old_username']
+    user.last_name = ACCOUNT['old_last_name']
+    user.save(update_fields=['username', 'last_name'])
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ligoauth', '0029_update_detchar_certs'),
+    ]
+
+    operations = [
+        migrations.RunPython(update_acct, revert_acct),
+    ]
-- 
GitLab