mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-09-16 09:12:29 +03:00
Adding permission IsModelInstanceOwnerOrIsAnonReadOnly
This commit is contained in:
parent
d44a6c5a69
commit
6bd2205833
|
@ -77,6 +77,27 @@ class IsAdminUser(BasePermission):
|
|||
raise _403_FORBIDDEN_RESPONSE
|
||||
|
||||
|
||||
class IsModelInstanceOwnerOrIsAnonReadOnly(BasePermission):
|
||||
"""
|
||||
The request is authenticated as the owner of the model instance, or is a read-only request.
|
||||
"""
|
||||
|
||||
def check_permission(self, user):
|
||||
|
||||
if self.view.method in('GET', 'HEAD',):
|
||||
return
|
||||
|
||||
if not user.is_authenticated():
|
||||
raise _403_FORBIDDEN_RESPONSE
|
||||
|
||||
try:
|
||||
if self.view.model_instance.get_owner() == user:
|
||||
return
|
||||
except: pass
|
||||
|
||||
raise _403_FORBIDDEN_RESPONSE
|
||||
|
||||
|
||||
class IsUserOrIsAnonReadOnly(BasePermission):
|
||||
"""
|
||||
The request is authenticated as a user, or is a read-only request.
|
||||
|
|
Loading…
Reference in New Issue
Block a user