Skip to content
Snippets Groups Projects
Commit 146ab7ea authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Bugfix to ligoauth migrations

Fixing two migrations
  - ligoauth 0004: properly delete User instance for gstlal-spiir-gpu,
    not just LocalUser/RobotUser
  - ligoauth 0013: deleted, since gstlal-spiir-gpu has been deleted,
    we don't need to create a RobotUser instance for it
parent addf6088
No related branches found
No related tags found
No related merge requests found
......@@ -37,11 +37,12 @@ def update_accounts(apps, schema_editor):
user.x509cert_set.add(new_cert)
# Delete gstlal-spiir-gpu user and associated cert(s)
gpu_user = LocalUser.objects.get(username=GSTLAL_SPIIR_GPU['username'])
gpu_user = LocalUser.objects.get(username=GSTLAL_SPIIR_GPU['username']).user_ptr
for cert in gpu_user.x509cert_set.all():
cert.delete()
gpu_user.delete()
def rollback_accounts(apps, schema_editor):
LocalUser = apps.get_model('ligoauth', 'LocalUser')
X509Cert = apps.get_model('ligoauth', 'X509Cert')
......@@ -70,6 +71,7 @@ class Migration(migrations.Migration):
dependencies = [
('ligoauth', '0003_initial_localuser_and_x509cert_data'),
('guardian', '0002_authorize_users_to_populate_pipelines'),
]
operations = [
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-10-17 18:24
from __future__ import unicode_literals
from django.db import migrations
username = 'gstlal-spiir-gpu'
def add_robotuser(apps, schema_editor):
User = apps.get_model('auth', 'User')
RobotUser = apps.get_model('ligoauth', 'RobotUser')
# Get user account
user = User.objects.get(username=username)
# Create RobotUser account with user_ptr and update dict
r_user = RobotUser.objects.create(user_ptr=user)
r_user.__dict__.update(user.__dict__)
r_user.save()
def remove_robotuser(apps, schema_editor):
RobotUser = apps.get_model('ligoauth', 'RobotUser')
# Delete RobotUser, keep parent User
r_user = RobotUser.objects.get(username=username)
r_user.delete(keep_parents=True)
class Migration(migrations.Migration):
dependencies = [
('ligoauth', '0012_rename_localuser_to_robotuser'),
]
operations = [
migrations.RunPython(add_robotuser, remove_robotuser),
]
......@@ -8,7 +8,7 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ligoauth', '0013_make_gstlal-spiir-gpu_robotuser'),
('ligoauth', '0012_rename_localuser_to_robotuser'),
]
operations = [
......
......@@ -36,7 +36,7 @@ def remove_cert(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [
('ligoauth', '0014_x509cert_subject_longer'),
('ligoauth', '0013_x509cert_subject_longer'),
]
operations = [
......
......@@ -146,8 +146,9 @@ def add_permissions(apps, schema_editor):
# Loop over users
for username in pp_dict['usernames']:
# Robot users should be created already by ligoauth 0002
user, created = User.objects.get_or_create(username=username)
# Robot users should have been already created by ligoauth 0003,
# but we have to create human user accounts here
user, _ = User.objects.get_or_create(username=username)
# Create UserObjectPermission
uop, uop_created = UserObjectPermission.objects.get_or_create(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment