Coverage for snippets/permissions.py: 75.00%

6 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-29 13:21 -0700

1from rest_framework import permissions 1a

2 

3 

4class IsOwnerOrReadOnly(permissions.BasePermission): 1a

5 """ 

6 Custom permission to only allow owners of an object to edit it. 

7 """ 

8 

9 def has_object_permission(self, request, view, obj): 1a

10 # Read permissions are allowed to any request, 

11 # so we'll always allow GET, HEAD, or OPTIONS requests. 

12 if request.method in permissions.SAFE_METHODS: 12 ↛ 16line 12 didn't jump to line 16 because the condition on line 12 was always true1b

13 return True 1b

14 

15 # Write permissions are only allowed to the owner of the snippet. 

16 return obj.owner == request.user