Skip to content
Snippets Groups Projects
Commit bcc873e4 authored by Alexander Pace's avatar Alexander Pace
Browse files

Adding migration for edoardo milotti to cwb pipeline

parent 8720b3bb
No related branches found
No related tags found
No related merge requests found
Pipeline #96403 passed
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-01 16:19
from __future__ import unicode_literals
from django.db import migrations
# Creates UserObjectPermission objects which allow specific users
# to add events for pipelines. Based on current production database
# content (27 October 2017)
# List of pipeline names and lists of usernames who should
# be allowed to add events for them
PP_LIST = [
{
'pipeline': 'cwb',
'usernames': [
'edoardo.milotti@ligo.org',
]
},
]
def add_permissions(apps, schema_editor):
User = apps.get_model('auth', 'User')
Permission = apps.get_model('auth', 'Permission')
UserObjectPermission = apps.get_model('guardian', 'UserObjectPermission')
Pipeline = apps.get_model('events', 'Pipeline')
ContentType = apps.get_model('contenttypes', 'ContentType')
perm = Permission.objects.get(codename='populate_pipeline')
ctype = ContentType.objects.get_for_model(Pipeline)
for pp_dict in PP_LIST:
pipeline = Pipeline.objects.get(name=pp_dict['pipeline'])
# Loop over users
for username in pp_dict['usernames']:
# 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(
user=user, permission=perm, content_type=ctype,
object_pk=pipeline.id)
def remove_permissions(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('guardian', '0007_add_gareth_davies_to_pycbc'),
]
operations = [
migrations.RunPython(add_permissions, remove_permissions),
]
\ No newline at end of file
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