Commit 509fbd86 authored by lukas.burgey's avatar lukas.burgey
Browse files

Merge branch 'dev' into 'master'

Fixes

See merge request !2
parents b3ae682b 5161f1b1
Pipeline #81791 passed with stage
in 56 seconds
......@@ -105,15 +105,12 @@ class User(AbstractUser):
# services returns all services this user has access to
@property
def services(self):
queryset = None
s = set()
for vo in self.vos.all():
if queryset is None:
queryset = vo.services.all()
else:
queryset.union(vo.services.all())
s = s.union(vo.services.all())
return queryset
return list(s)
@property
def is_active_at_clients(self):
......
......@@ -88,12 +88,36 @@ class BaseTestCase(TestCase):
vos=[cls.group_two],
)
SSHPublicKey(
cls.key = SSHPublicKey(
name=cls.TEST_NAME,
key=cls.TEST_KEY,
user=cls.user,
).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
class LoggedInTest(BaseTestCase):
......
......@@ -190,20 +190,27 @@ class DeploymentView(generics.RetrieveUpdateAPIView):
raise exceptions.ValidationError('You have no VO with id "{}"'.format(dep_id))
if self.kwargs['type'] == 'service':
try:
service = Service.objects.get(vos__user=self.request.user, id=dep_id)
dep, created = ServiceDeployment.objects.get_or_create(
user=self.request.user,
service=service,
defaults={},
)
if created:
LOGGER.debug('Created new ServiceDeployment')
# find service with id dep_id
service = None
for s in self.request.user.services:
if s.id == int(dep_id):
if service is None:
service = s
else:
raise Exception('user has multiple services with identical id')
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:
raise exceptions.ValidationError('You are not permitted to access a service with id "{}"'.format(dep_id))
return dep
raise exceptions.ValidationError('Type must be either "service" or "vo"')
......
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