Commit 6b5240ba authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

Cleanup of Group usage

parent c2b20c67
......@@ -2,7 +2,6 @@ import mock
import pytest
from django.conf import settings
from django.contrib.auth.models import Group as AuthGroup
from django.urls import reverse
from core.tests.utils import GraceDbTestBase
......
......@@ -8,7 +8,7 @@ import StringIO
import urllib
from django.conf import settings
from django.contrib.auth.models import User, Permission, Group as AuthGroup
from django.contrib.auth.models import User, Permission, Group as DjangoGroup
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.db import IntegrityError
......@@ -146,7 +146,7 @@ def group_required(view):
@wraps(view)
def inner(self, request, event, group_name, *args, **kwargs):
try:
group = AuthGroup.objects.get(name=str(group_name))
group = DjangoGroup.objects.get(name=str(group_name))
except:
return Response("Group does not exist.",
status=status.HTTP_404_NOT_FOUND)
......
......@@ -5,7 +5,6 @@ import os
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group as AuthGroup
from django.db import models
from django.utils.translation import ugettext_lazy as _
......
......@@ -5,7 +5,6 @@ import os
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import Group as AuthGroup
from guardian.shortcuts import get_objects_for_user
from rest_framework import mixins, parsers, permissions, serializers, status, \
......
......@@ -8,8 +8,6 @@ from django.utils.translation import ugettext_lazy as _
from model_utils.managers import InheritanceManager
#from django.contrib.auth.models import User as DjangoUser
#from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
......
......@@ -22,7 +22,7 @@ from core.vfile import VersionedFile
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission
from django.contrib.auth.models import Group as AuthGroup
from django.contrib.auth.models import Group as DjangoGroup
from django.conf import settings
from guardian.models import GroupObjectPermission
......@@ -356,7 +356,7 @@ def get_lvem_perm_status(request, event):
# Get the group
# Returns a tuple: (can_expose, can_protect)
try:
lv_em_group = AuthGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
lv_em_group = DjangoGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
except:
# Something is really wrong.
return (None, None)
......
......@@ -20,7 +20,7 @@ from .forms import CreateEventForm, SignoffForm
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import User, Permission
from django.contrib.auth.models import Group as AuthGroup
from django.contrib.auth.models import Group as DjangoGroup
from django.contrib.contenttypes.models import ContentType
from .permission_utils import filter_events_for_user, user_has_perm
from .permission_utils import is_external, check_external_file_access
......@@ -710,7 +710,7 @@ def modify_permissions(request, event):
# Get the group
try:
g = AuthGroup.objects.get(name=group_name)
g = DjangoGroup.objects.get(name=group_name)
except Group.DoesNotExist:
return HttpResponseNotFound('Group not found')
......
......@@ -3,6 +3,7 @@ import re
from django.conf import settings
from django.contrib import auth
from django.contrib.auth.models import Group as DjangoGroup
from django.contrib.auth.middleware import PersistentRemoteUserMiddleware
from django.contrib.auth.models import Group
from django.core.exceptions import ImproperlyConfigured
......@@ -126,7 +127,7 @@ class ControlRoomMiddleware(object):
# Add user to control room group(s)
for ifo, ip in settings.CONTROL_ROOM_IPS.iteritems():
if (ip == user_ip):
control_room_group = Group.objects.get(name=
control_room_group = DjangoGroup.objects.get(name=
(ifo.lower() + self.control_room_group_suffix))
request.user.groups.through.objects.get_or_create(
user=request.user, group=control_room_group)
......
from django.conf import settings
from django.contrib.auth.models import Group as AuthGroup, User, AnonymousUser
from django.contrib.auth.models import User, AnonymousUser
from django.contrib.auth.middleware import AuthenticationMiddleware
from django.core.exceptions import ImproperlyConfigured
from django.test import RequestFactory, TestCase
......
from django.conf import settings
from django.contrib.auth.models import Group as AuthGroup, User, AnonymousUser
from django.contrib.auth.models import Group as DjangoGroup, User, AnonymousUser
from django.contrib.auth.middleware import AuthenticationMiddleware
from django.core.exceptions import ImproperlyConfigured
from django.test import RequestFactory
......@@ -44,7 +44,7 @@ class TestControlRoomMiddlewareHomeView(GraceDbTestBase):
super(TestControlRoomMiddlewareHomeView, cls).setUpTestData()
# Create control room group
cls.control_room_group, _ = AuthGroup.objects.get_or_create(
cls.control_room_group, _ = DjangoGroup.objects.get_or_create(
name=cls.ifo.lower() + '_control_room')
def test_internal_user_in_control_room(self):
......@@ -145,7 +145,7 @@ class TestControlRoomMiddleware(GraceDbTestBase):
super(TestControlRoomMiddleware, cls).setUpTestData()
# Create control room group
cls.control_room_group, _ = AuthGroup.objects.get_or_create(
cls.control_room_group, _ = DjangoGroup.objects.get_or_create(
name=cls.ifo.lower() + '_control_room')
def test_internal_user_in_control_room(self):
......@@ -391,7 +391,7 @@ class TestShibbolethWebAuthMiddleware(GraceDbTestBase):
def test_group_addition(self):
"""Add a group for a user based on shib group header content"""
# Create new group for testing
new_group = AuthGroup.objects.create(name='new_group')
new_group = DjangoGroup.objects.create(name='new_group')
# Compile group header
delim = ShibbolethWebAuthMiddleware.group_delimiter
groups_str = delim.join([self.internal_group.name, new_group.name])
......@@ -426,7 +426,7 @@ class TestShibbolethWebAuthMiddleware(GraceDbTestBase):
def test_group_removal(self):
"""Remove a group for a user based on shib group header content"""
# Create new group, add to user
new_group = AuthGroup.objects.create(name='new_group')
new_group = DjangoGroup.objects.create(name='new_group')
self.internal_user.groups.add(new_group)
# Set up request
......@@ -467,7 +467,7 @@ class TestShibbolethWebAuthMiddleware(GraceDbTestBase):
r_user.groups.add(self.internal_group)
# Create new group for testing
new_group = AuthGroup.objects.create(name='new_group')
new_group = DjangoGroup.objects.create(name='new_group')
# Compile group header
delim = ShibbolethWebAuthMiddleware.group_delimiter
groups_str = delim.join([self.internal_group.name, new_group.name])
......@@ -507,7 +507,7 @@ class TestShibbolethWebAuthMiddleware(GraceDbTestBase):
r_user = RobotUser.objects.create(username='robot.user')
r_user.groups.add(self.internal_group)
# Create new group and add robotusre
new_group = AuthGroup.objects.create(name='new_group')
new_group = DjangoGroup.objects.create(name='new_group')
r_user.groups.add(new_group)
# Set up request
......
import urllib
from django.conf import settings
from django.contrib.auth.models import Group as AuthGroup, Permission
from django.contrib.auth.models import Group as DjangoGroup, Permission
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from django.urls import reverse
......@@ -52,12 +52,12 @@ class TestEventSearch(EventCreateMixin, GraceDbTestBase, SearchTestingBase):
# Assign default permissions for internal group (also have to create
# executives group because this perm assign code is TERRIBLE)
execs, _ = AuthGroup.objects.get_or_create(name='executives')
execs, _ = DjangoGroup.objects.get_or_create(name='executives')
assign_default_event_perms(cls.internal_event)
assign_default_event_perms(cls.lvem_event)
# Expose events
lvem_group = AuthGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
lvem_group = DjangoGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
update_event_perms_for_group(cls.lvem_event, lvem_group, 'expose')
def test_internal_user_search(self):
......@@ -168,12 +168,12 @@ class TestEventLatest(EventCreateMixin, GraceDbTestBase):
# Assign default permissions for internal group (also have to create
# executives group because this perm assign code is TERRIBLE)
execs, _ = AuthGroup.objects.get_or_create(name='executives')
execs, _ = DjangoGroup.objects.get_or_create(name='executives')
assign_default_event_perms(cls.internal_event)
assign_default_event_perms(cls.lvem_event)
# Expose an event to LV-EM
lvem_group = AuthGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
lvem_group = DjangoGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
update_event_perms_for_group(cls.lvem_event, lvem_group, 'expose')
def test_internal_user_latest(self):
......
......@@ -3,7 +3,6 @@ import pytz
from django import forms
from django.conf import settings
from django.contrib.auth.models import Group as AuthGroup
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.views.generic.base import ContextMixin
......
......@@ -4,7 +4,7 @@ import os
from django.conf import settings
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import Group as AuthGroup
from django.contrib.auth.models import Group as DjangoGroup
from .buildVOEvent import construct_voevent_file
from .models import Superevent, Log, Labelling, EMObservation, EMFootprint, \
......@@ -831,8 +831,8 @@ def expose_superevent(superevent, user, add_log_message=True,
issue_alert=True):
# Get groups
lvem_group = AuthGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
public_group = AuthGroup.objects.get(name=settings.PUBLIC_GROUP)
lvem_group = DjangoGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
public_group = DjangoGroup.objects.get(name=settings.PUBLIC_GROUP)
# Assign permissions which will expose the superevent to LV-EM and the
# public
......@@ -860,8 +860,8 @@ def hide_superevent(superevent, user, add_log_message=True,
issue_alert=True):
# Get groups
lvem_group = AuthGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
public_group = AuthGroup.objects.get(name=settings.PUBLIC_GROUP)
lvem_group = DjangoGroup.objects.get(name=settings.LVEM_OBSERVERS_GROUP)
public_group = DjangoGroup.objects.get(name=settings.PUBLIC_GROUP)
# Assign permissions which will expose the superevent to LV-EM and the
# public
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment