Permissions: workaround DRF bug and expose exception code.

master
Tom Hacohen 4 years ago
parent c0575cb64c
commit f6af96ace6

@ -25,8 +25,10 @@ class IsCollectionAdmin(permissions.BasePermission):
""" """
Custom permission to only allow owners of a collection to view it Custom permission to only allow owners of a collection to view it
""" """
message = 'Only collection admins can perform this operation.' message = {
code = 'admin_access_required' 'detail': 'Only collection admins can perform this operation.',
'code': 'admin_access_required',
}
def has_permission(self, request, view): def has_permission(self, request, view):
collection_uid = view.kwargs['collection_uid'] collection_uid = view.kwargs['collection_uid']
@ -42,8 +44,10 @@ class IsCollectionAdminOrReadOnly(permissions.BasePermission):
""" """
Custom permission to only allow owners of a collection to edit it Custom permission to only allow owners of a collection to edit it
""" """
message = 'Only collection admins can edit collections.' message = {
code = 'admin_access_required' 'detail': 'Only collection admins can edit collections.',
'code': 'admin_access_required',
}
def has_permission(self, request, view): def has_permission(self, request, view):
collection_uid = view.kwargs.get('collection_uid', None) collection_uid = view.kwargs.get('collection_uid', None)
@ -67,8 +71,10 @@ class HasWriteAccessOrReadOnly(permissions.BasePermission):
""" """
Custom permission to restrict write Custom permission to restrict write
""" """
message = 'You need write access to write to this collection' message = {
code = 'no_write_access' 'detail': 'You need write access to write to this collection',
'code': 'no_write_access',
}
def has_permission(self, request, view): def has_permission(self, request, view):
collection_uid = view.kwargs['collection_uid'] collection_uid = view.kwargs['collection_uid']

Loading…
Cancel
Save