Skip to content

Commit 6971fff

Browse files
committed
Annotators can see the identification tasks where they have contributed
1 parent 029baef commit 6971fff

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

api/permissions.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,27 @@ def has_permission(self, request, view):
131131
return False
132132

133133
class IdentificationTaskPermissions(FullDjangoModelPermissions):
134-
pass
134+
def has_permission(self, request, view):
135+
# Always require authentication
136+
if not request.user or not request.user.is_authenticated:
137+
return False
138+
139+
if view.action == 'retrieve':
140+
return True
141+
142+
return super().has_permission(request, view)
143+
144+
def has_object_permission(self, request, view, obj):
145+
if isinstance(request.user, TigaUser):
146+
return False
147+
148+
if obj.annotators.filter(pk=request.user.pk).exists():
149+
# If it's a user that has annotated this task, allow access
150+
if view.action == 'retrieve':
151+
return True
152+
153+
perms = self.get_required_permissions(request.method, obj._meta.model)
154+
return request.user.has_perms(perms)
135155

136156
class MyIdentificationTaskPermissions(DjangoRegularUserModelPermissions):
137157
pass

api/tests/integration/identification_tasks/get.tavern.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,31 @@ stages:
6262

6363
---
6464

65+
test_name: Identification tasks can be read by annotators that has annotated that identification task.
66+
67+
includes:
68+
- !include schema.yml
69+
70+
marks:
71+
- usefixtures:
72+
- api_live_url
73+
- identification_task
74+
- annotation
75+
- jwt_token_user
76+
77+
stages:
78+
- name: User with perm view can retrieve
79+
request:
80+
url: "{api_live_url}/{endpoint}/{identification_task.report.pk}/"
81+
method: "GET"
82+
headers:
83+
Authorization: "Bearer {jwt_token_user:s}"
84+
response:
85+
status_code: 200
86+
json: !force_format_include "{response_data_validation}"
87+
88+
---
89+
6590
test_name: Archived identification tasks can not be retrieved.
6691

6792
includes:

api/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def get_queryset(self):
521521
qs = super().get_queryset()
522522

523523
user = self.request.user
524-
if not (user and user.has_perm("tigacrafting.view_archived_identificationtasks")):
524+
if isinstance(user, TigaUser) or not (user and user.has_perm("tigacrafting.view_archived_identificationtasks")):
525525
qs = qs.exclude(status=IdentificationTask.Status.ARCHIVED)
526526

527527
return qs

0 commit comments

Comments
 (0)