Commit 5161f1b1 authored by lukas.burgey's avatar lukas.burgey
Browse files

Revert "Fix an error which caused services to be invisible to the user"

This reverts commit 500742f8.
parent b3ae682b
...@@ -105,15 +105,12 @@ class User(AbstractUser): ...@@ -105,15 +105,12 @@ class User(AbstractUser):
# services returns all services this user has access to # services returns all services this user has access to
@property @property
def services(self): def services(self):
queryset = None s = set()
for vo in self.vos.all(): for vo in self.vos.all():
if queryset is None: s = s.union(vo.services.all())
queryset = vo.services.all()
else:
queryset.union(vo.services.all())
return queryset return list(s)
@property @property
def is_active_at_clients(self): def is_active_at_clients(self):
......
...@@ -88,12 +88,36 @@ class BaseTestCase(TestCase): ...@@ -88,12 +88,36 @@ class BaseTestCase(TestCase):
vos=[cls.group_two], vos=[cls.group_two],
) )
SSHPublicKey( cls.key = SSHPublicKey(
name=cls.TEST_NAME, name=cls.TEST_NAME,
key=cls.TEST_KEY, key=cls.TEST_KEY,
user=cls.user, user=cls.user,
).save() ).save()
# only needed to manually tear down the test data
@classmethod
def manualTearDownTestData(cls):
# delete in reverse order
for member in [
'key',
'service_one',
'service_two_a',
'service_two_b',
'site',
'site2',
'user',
'group_none',
'group_one',
'group_two',
'idp',
]:
if hasattr(cls, member):
try:
getattr(cls, member).delete()
# pylint: disable=bare-except
except:
pass
# the user is logged in using session authentication # the user is logged in using session authentication
class LoggedInTest(BaseTestCase): class LoggedInTest(BaseTestCase):
......
...@@ -190,20 +190,27 @@ class DeploymentView(generics.RetrieveUpdateAPIView): ...@@ -190,20 +190,27 @@ class DeploymentView(generics.RetrieveUpdateAPIView):
raise exceptions.ValidationError('You have no VO with id "{}"'.format(dep_id)) raise exceptions.ValidationError('You have no VO with id "{}"'.format(dep_id))
if self.kwargs['type'] == 'service': if self.kwargs['type'] == 'service':
try: # find service with id dep_id
service = Service.objects.get(vos__user=self.request.user, id=dep_id) service = None
dep, created = ServiceDeployment.objects.get_or_create( for s in self.request.user.services:
user=self.request.user, if s.id == int(dep_id):
service=service, if service is None:
defaults={}, service = s
) else:
if created: raise Exception('user has multiple services with identical id')
LOGGER.debug('Created new ServiceDeployment')
if service is None:
raise exceptions.ValidationError('You are not permitted to access a service with id "{}"'.format(dep_id))
return dep dep, created = ServiceDeployment.objects.get_or_create(
user=self.request.user,
service=service,
defaults={},
)
if created:
LOGGER.debug('Created new ServiceDeployment')
except Service.DoesNotExist: return dep
raise exceptions.ValidationError('You are not permitted to access a service with id "{}"'.format(dep_id))
raise exceptions.ValidationError('Type must be either "service" or "vo"') raise exceptions.ValidationError('Type must be either "service" or "vo"')
......
Supports Markdown
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