Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow provider to get the job by id #1493

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions gateway/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,21 @@ def retrieve(self, request, pk=None): # pylint: disable=unused-argument
tracer = trace.get_tracer("gateway.tracer")
ctx = TraceContextTextMapPropagator().extract(carrier=request.headers)
with tracer.start_as_current_span("gateway.job.retrieve", context=ctx):
job = Job.objects.filter(pk=pk).first()
psschwei marked this conversation as resolved.
Show resolved Hide resolved
if job is None:
logger.warning("Job [%s] not found", pk)
return Response(
{"message": f"Job [{pk}] was not found."},
status=status.HTTP_404_NOT_FOUND,
)
author = self.request.user
if job.program and job.program.provider:
provider_groups = job.program.provider.admin_groups.all()
author_groups = author.groups.all()
has_access = any(group in provider_groups for group in author_groups)
if has_access:
serializer = self.get_serializer(job)
return Response(serializer.data)
instance = self.get_object()
serializer = self.get_serializer(instance)
return Response(serializer.data)
psschwei marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
13 changes: 13 additions & 0 deletions gateway/tests/api/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ def test_job_detail(self):
self.assertEqual(jobs_response.data.get("status"), "SUCCEEDED")
self.assertEqual(jobs_response.data.get("result"), '{"somekey":1}')

def test_job_provider_detail(self):
Tansito marked this conversation as resolved.
Show resolved Hide resolved
"""Tests job detail authorized."""
user = models.User.objects.get(username="test_user_2")
self.client.force_authenticate(user=user)

jobs_response = self.client.get(
reverse("v1:jobs-detail", args=["1a7947f9-6ae8-4e3d-ac1e-e7d608deec86"]),
format="json",
)
self.assertEqual(jobs_response.status_code, status.HTTP_200_OK)
self.assertEqual(jobs_response.data.get("status"), "QUEUED")
self.assertEqual(jobs_response.data.get("result"), '{"somekey":1}')

def test_not_authorized_job_detail(self):
"""Tests job detail fails trying to access to other user job."""
self._authorize()
Expand Down