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

Group for RAVEN users

Create a group for the RAVEN pipeline, add users, and give the group
specific permissions. Right now, they are just allowed to populate
the Fermi, SNEWS, and Swift pipelines for uploading external events.
parent 2e669ff4
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-05-08 16:19
from __future__ import unicode_literals
from django.db import migrations
GROUP_NAME = 'raven_users'
def create_group(apps, schema_editor):
Group = apps.get_model('auth', 'Group')
Group.objects.create(name=GROUP_NAME)
def delete_group(apps, schema_editor):
Group = apps.get_model('auth', 'Group')
g = Group.objects.get(name=GROUP_NAME)
g.delete()
class Migration(migrations.Migration):
dependencies = [
('auth', '0020_populate_priority_users_group'),
]
operations = [
migrations.RunPython(create_group, delete_group),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-05-08 16:22
from __future__ import unicode_literals
from django.db import migrations
GROUP_NAME = 'raven_users'
USERS = [
'brandon.piotrzkowski@LIGO.ORG',
]
def add_users(apps, schema_editor):
Group = apps.get_model('auth', 'Group')
User = apps.get_model('auth', 'User')
# Get group
pg = Group.objects.get(name=GROUP_NAME)
# Get users
users = User.objects.filter(username__in=USERS)
# Add users
pg.user_set.add(*users)
def remove_users(apps, schema_editor):
Group = apps.get_model('auth', 'Group')
User = apps.get_model('auth', 'User')
# Get group
pg = Group.objects.get(name=GROUP_NAME)
# Get users
users = User.objects.filter(username__in=USERS)
# Remove users
pg.user_set.remove(*users)
class Migration(migrations.Migration):
dependencies = [
('auth', '0021_create_raven_users_group'),
]
operations = [
migrations.RunPython(add_users, remove_users),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-05-08 16:27
from __future__ import unicode_literals
from django.db import migrations
GROUP_NAME = 'raven_users'
PIPELINES = [
'Fermi',
'Swift',
'SNEWS',
]
def add_permissions(apps, schema_editor):
Group = apps.get_model('auth', 'Group')
Permission = apps.get_model('auth', 'Permission')
GroupObjectPermission = apps.get_model('guardian', 'GroupObjectPermission')
Pipeline = apps.get_model('events', 'Pipeline')
ContentType = apps.get_model('contenttypes', 'ContentType')
# Get group
group = Group.objects.get(name=GROUP_NAME)
perm = Permission.objects.get(codename='populate_pipeline')
ctype = ContentType.objects.get_for_model(Pipeline)
for pipeline in PIPELINES:
pipeline = Pipeline.objects.get(name=pipeline)
# Create GroupObjectPermission
gop = GroupObjectPermission.objects.create(group=group,
permission=perm, content_type=ctype, object_pk=pipeline.id)
def remove_permissions(apps, schema_editor):
Group = apps.get_model('auth', 'Group')
Permission = apps.get_model('auth', 'Permission')
GroupObjectPermission = apps.get_model('guardian', 'GroupObjectPermission')
Pipeline = apps.get_model('events', 'Pipeline')
ContentType = apps.get_model('contenttypes', 'ContentType')
# Get group
group = Group.objects.get(name=GROUP_NAME)
perm = Permission.objects.get(codename='populate_pipeline')
ctype = ContentType.objects.get_for_model(Pipeline)
for pipeline in PIPELINES:
pipeline = Pipeline.objects.get(name=pipeline)
# Get GroupObjectPermission and delete
gop = GroupObjectPermission.objects.get(group=group,
permission=perm, content_type=ctype, object_pk=pipeline.id)
gop.delete()
class Migration(migrations.Migration):
dependencies = [
('auth', '0021_create_raven_users_group'),
('guardian', '0004_add_guardian_anonymoususer_to_public_group'),
]
operations = [
migrations.RunPython(add_permissions, remove_permissions),
]
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