Skip to content

Commit

Permalink
specific endpoints list depending on user permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Glatthard committed Aug 7, 2015
1 parent 184b3cc commit 4ab79e9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
18 changes: 14 additions & 4 deletions ipynbsrv/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,24 @@ def has_object_permission(self, request, view, obj):

class IsSuperUserOrReadOnly(
permissions.BasePermission,
IsAuthenticatedMixin,
IsSuperUserMixin,
IsSafeMethodMixin):

def has_permission(self, request, view):
if self.is_authenticated(request):
if self.is_safe_method(request):
return True
if self.is_superuser(request.user):
return True
return False

def has_object_permission(self, request, view, obj):
if self.is_safe_method(request):
return True
if self.is_superuser(request.user):
return True
if self.is_authenticated(request):
if self.is_safe_method(request):
return True
if self.is_superuser(request.user):
return True
return False


Expand Down
33 changes: 19 additions & 14 deletions ipynbsrv/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,25 @@ def api_root(request, format=None):
"""
API Root
"""
return Response({'endpoints': {
'configurationvariables': 'desc',
'users': 'desc',
'collaborationgroups': 'desc',
'backends': 'desc',
'containers': 'desc',
'images': 'desc',
'snapshots': 'desc',
'servers': 'desc',
'shares': 'desc',
'tags': 'desc',
'notifications': 'desc',
'notificationlogs': 'desc',
}})
available_endpoints = {}
available_endpoints['users'] = 'desc'
available_endpoints['collaborationgroups'] = 'desc'
available_endpoints['containers'] = 'desc'
available_endpoints['images'] = 'desc'
available_endpoints['snapshots'] = 'desc'
available_endpoints['shares'] = 'desc'
available_endpoints['tags'] = 'desc'
available_endpoints['notifications'] = 'desc'
available_endpoints['notificationlogs'] = 'desc'
available_endpoints['notificationtypes'] = 'desc'

# additional endpoints for superusers only
if request.user.is_superuser:
available_endpoints['configurationvariables'] = 'desc'
available_endpoints['backends'] = 'desc'
available_endpoints['servers'] = 'desc'

return Response(available_endpoints)


class ConfigurationVariableList(generics.ListCreateAPIView):
Expand Down

0 comments on commit 4ab79e9

Please sign in to comment.