Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
akihikokuroda committed Jul 17, 2024
1 parent 7ca8dd7 commit 6666bbf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
17 changes: 14 additions & 3 deletions gateway/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,20 @@ def get_jobs(
ctx = TraceContextTextMapPropagator().extract(carrier=request.headers)
with tracer.start_as_current_span("gateway.program.get_jobs", context=ctx):
program = Program.objects.filter(id=pk).first()
jobs = Job.objects.filter(program=program)
job_ids = [str(job.id) for job in jobs]
return Response(job_ids)
if (
program.provider
and program.provider.admin_group in request.user.groups.all()
):
jobs = Job.objects.filter(program=program)
else:
jobs = Job.objects.filter(program=program, author=request.user)
return Response(
list(
jobs.values(
"status", "result", "id", "created", "version", "arguments"
)
)
)


class JobViewSet(viewsets.GenericViewSet):
Expand Down
2 changes: 1 addition & 1 deletion gateway/tests/api/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_job_list(self):

jobs_response = self.client.get(reverse("v1:jobs-list"), format="json")
self.assertEqual(jobs_response.status_code, status.HTTP_200_OK)
self.assertEqual(jobs_response.data.get("count"), 2)
self.assertEqual(jobs_response.data.get("count"), 3)
self.assertEqual(
jobs_response.data.get("results")[0].get("status"), "SUCCEEDED"
)
Expand Down
22 changes: 21 additions & 1 deletion gateway/tests/api/test_v1_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,29 @@ def test_get_jobs(self):
user = models.User.objects.get(username="test_user_2")
self.client.force_authenticate(user=user)

# program w/o provider
response = self.client.get(
"/api/v1/programs/1a7947f9-6ae8-4e3d-ac1e-e7d608deec82/get_jobs/",
format="json",
)
print(response.data)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.status_code, status.HTTP_200_OK)

# program w/ provider by not author
response = self.client.get(
"/api/v1/programs/6160a2ff-e482-443d-af23-15110b646ae2/get_jobs/",
format="json",
)
self.assertEqual(len(response.data), 2)
self.assertEqual(response.status_code, status.HTTP_200_OK)

# program w/ provider by author
user = models.User.objects.get(username="test_user")
self.client.force_authenticate(user=user)

response = self.client.get(
"/api/v1/programs/6160a2ff-e482-443d-af23-15110b646ae2/get_jobs/",
format="json",
)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.status_code, status.HTTP_200_OK)
22 changes: 22 additions & 0 deletions gateway/tests/fixtures/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@
"author": 2
}
},
{
"model": "api.job",
"pk": "1a7947f9-6ae8-4e3d-ac1e-e7d608deec85",
"fields": {
"program": "6160a2ff-e482-443d-af23-15110b646ae2",
"created": "2023-02-01T15:30:43.281796Z",
"result": "{\"somekey\":1}",
"status": "QUEUED",
"author": 2
}
},
{
"model": "api.job",
"pk": "1a7947f9-6ae8-4e3d-ac1e-e7d608deec86",
"fields": {
"program": "6160a2ff-e482-443d-af23-15110b646ae2",
"created": "2023-02-01T15:30:43.281796Z",
"result": "{\"somekey\":1}",
"status": "QUEUED",
"author": 1
}
},
{
"model": "api.runtimejob",
"pk": "runtime_job_1",
Expand Down

0 comments on commit 6666bbf

Please sign in to comment.