Skip to content

Commit

Permalink
Allow users to enable and disable their namespaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
newswangerd committed Jun 26, 2018
1 parent bacc3ff commit 30024b9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions galaxy/api/views/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ def check_owners(data_owners):
return errors, owners


def can_update(namespace_id, user_id):
namespace = models.Namespace.objects.get(pk=namespace_id)
if not namespace.owners.filter(pk=user_id):
return False

return True


def check_providers(data_providers, parent=None):
errors = {}

Expand Down Expand Up @@ -209,7 +217,7 @@ def post(self, request, *args, **kwargs):
if errors:
raise ValidationError(detail=errors)

if not request.user.is_staff and request.user.pk not in owners:
if not request.user.is_staff and not can_update(data['id'], request.user.id):
owners.append(request.user.id)

namespace_attributes = {
Expand Down Expand Up @@ -257,7 +265,7 @@ def update(self, request, *args, **kwargs):
if errors:
raise ValidationError(detail=errors)

if not request.user.is_staff and request.user.pk not in owners:
if not request.user.is_staff and not can_update(data['id'], request.user.id):
raise PermissionDenied("User does not have access to Namespace {0}".format(
data.get('name', '')))

Expand Down

0 comments on commit 30024b9

Please sign in to comment.