Skip to content

Commit 7124b0c

Browse files
feat: Returning the forbidden jobs in the error
1 parent 6f601f1 commit 7124b0c

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

diracx-db/src/diracx/db/sql/pilot_agents/db.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def add_pilot_references(
4444
stmt = insert(PilotAgents).values(values)
4545
await self.conn.execute(stmt)
4646

47-
async def get_pilot_by_reference(self, pilot_ref: str):
47+
async def get_pilot_by_reference(self, pilot_ref: str) -> dict:
4848
stmt = select(PilotAgents).where(PilotAgents.pilot_job_reference == pilot_ref)
4949

5050
# Execute the query and fetch one result
@@ -55,17 +55,17 @@ async def get_pilot_by_reference(self, pilot_ref: str):
5555

5656
return dict(pilot._mapping)
5757

58-
async def get_pilot_job_ids(self, pilot_id: set) -> set[dict]:
58+
async def get_pilot_job_ids(self, pilot_id: set) -> list[int]:
5959
stmt = select(JobToPilotMapping.job_id).where(
6060
JobToPilotMapping.pilot_id == pilot_id
6161
)
6262

6363
# Execute the results
6464
result = await self.conn.execute(stmt)
6565

66-
return set(result.scalars().all())
66+
return list(result.scalars().all())
6767

68-
async def associate_pilot_with_jobs(self, pilot_id: int, job_ids: set[int]):
68+
async def associate_pilot_with_jobs(self, pilot_id: int, job_ids: list[int]):
6969

7070
now = datetime.now(tz=timezone.utc)
7171

diracx-routers/src/diracx/routers/jobs/access_policies.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ async def policy(
8282
if set(job_ids) <= set(pilot_jobs):
8383
return
8484

85+
forbidden_jobs_ids = set(job_ids) - set(pilot_jobs)
86+
8587
raise HTTPException(
86-
status.HTTP_403_FORBIDDEN, "this pilot can't access/modify this job"
88+
status.HTTP_403_FORBIDDEN,
89+
f"this pilot can't access/modify some jobs: ids={forbidden_jobs_ids}",
8790
)
8891

8992
raise HTTPException(status.HTTP_403_FORBIDDEN, "you are not a pilot")

diracx-routers/tests/jobs/test_wms_access_policy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ async def get_pilot_job_ids_patch(*args, **kwargs):
144144
)
145145

146146
assert (
147-
str(excinfo.value) == "403: " + "this pilot can't access/modify this job"
147+
str(excinfo.value)
148+
== "403: " + "this pilot can't access/modify some jobs: ids={1, 2}"
148149
), excinfo
149150

150151
# ------------------------- Pilot accessing some of his jobs -------------------------
@@ -181,7 +182,8 @@ async def get_pilot_job_ids_patch(*args, **kwargs):
181182
)
182183

183184
assert (
184-
str(excinfo.value) == "403: " + "this pilot can't access/modify this job"
185+
str(excinfo.value)
186+
== "403: " + "this pilot can't access/modify some jobs: ids={12}"
185187
), excinfo
186188

187189

0 commit comments

Comments
 (0)