Coverage for posts/permissions.py: 75.00%

6 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-24 10:40 -0700

1from rest_framework import permissions 1a

2 

3 

4class IsAuthorOrReadOnly(permissions.BasePermission): 1a

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

6 # Read-only permissions are allowed for any request 

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

8 return True 1b

9 

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

11 return obj.author == request.user