Coverage for apis/permissions.py: 80.00%

8 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-05 08:29 -0800

1from rest_framework import permissions 1a

2 

3 

4class IsAuthorOrReadOnly(permissions.BasePermission): 1a

5 def has_permission(self, request, view): 1a

6 # Authenticated users only can see list view 

7 # if request.user.is_authenticated: 

8 # return True 

9 # return False 

10 return bool(request.user.is_authenticated) 1a

11 

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

13 # Read permissions are allowed to any request so we'll always 

14 # allow GET, HEAD, or OPTIONS requests 

15 if request.method in permissions.SAFE_METHODS: 15 ↛ 19line 15 didn't jump to line 19 because the condition on line 15 was always true1a

16 return True 1a

17 

18 # Write permissions are only allowed to the author of a post 

19 return obj.author == request.user