Skip to content

Commit 7d2ec94

Browse files
committed
fix: move the policy check_permission to the beginning of send_message
1 parent b7581ef commit 7d2ec94

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from fastapi import Depends, HTTPException, status
77

8-
from diracx.core.properties import GENERIC_PILOT, OPERATOR, SERVICE_ADMINISTRATOR
8+
from diracx.core.properties import GENERIC_PILOT, PILOT, OPERATOR, SERVICE_ADMINISTRATOR
99
from diracx.db.os import PilotLogsDB
1010
from diracx.routers.access_policies import BaseAccessPolicy
1111

@@ -43,13 +43,15 @@ async def policy(
4343
assert action, "action is a mandatory parameter"
4444
assert pilot_db, "pilot_db is a mandatory parameter"
4545

46+
if GENERIC_PILOT in user_info.properties:
47+
return
48+
if PILOT in user_info.properties:
49+
return
4650
if SERVICE_ADMINISTRATOR in user_info.properties:
4751
return
4852
if OPERATOR in user_info.properties:
4953
return
50-
if GENERIC_PILOT in user_info.properties:
51-
return
52-
# return # to ignore a sender
54+
5355
raise HTTPException(status.HTTP_403_FORBIDDEN, detail=user_info.properties)
5456

5557

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ async def send_message(
2828
check_permissions: CheckPilotLogsPolicyCallable,
2929
):
3030
logger.warning(f"Message received '{data}'")
31+
await check_permissions(action=ActionType.CREATE, pilot_db=pilot_logs_db)
32+
3133
pilot_id = 1234 # need to get pilot id from pilot_stamp (via pilot DB)
3234

3335
docs = []
@@ -40,6 +42,5 @@ async def send_message(
4042
"Message": line.line,
4143
}
4244
)
43-
await check_permissions(action=ActionType.CREATE, pilot_db=pilot_logs_db)
4445
await pilot_logs_db.bulk_insert(pilot_logs_db.index_name(pilot_id), docs)
4546
return data

0 commit comments

Comments
 (0)