Add country admin
This commit is contained in:
parent
ff7df815f4
commit
9acef83894
|
|
@ -73,7 +73,28 @@ class IsStandardUser(IsGuest):
|
|||
return False
|
||||
|
||||
|
||||
class IsCommentModerator(IsStandardUser):
|
||||
class IsCountryAdmin(IsStandardUser):
|
||||
"""
|
||||
Object-level permission to only allow owners of an object to edit it.
|
||||
Assumes the model instance has an `owner` attribute.
|
||||
"""
|
||||
def has_object_permission(self, request, view, obj):
|
||||
# Read permissions are allowed to any request.
|
||||
if super().has_object_permission(request, view, obj):
|
||||
return True
|
||||
|
||||
# Must have role
|
||||
role = Role.objects.filter(role=Role.COUNTRY_ADMIN,
|
||||
country_id=obj.country_id) \
|
||||
.first() # 'Comments moderator'
|
||||
|
||||
is_access = UserRole.objects.filter(user=request.user, role=role).exists()
|
||||
if obj.user != request.user and is_access:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class IsCommentModerator(IsCountryAdmin):
|
||||
"""
|
||||
Object-level permission to only allow owners of an object to edit it.
|
||||
Assumes the model instance has an `owner` attribute.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user