Server: correctly masks status in a cleaner manner

This commit is contained in:
2025-12-04 11:30:36 +01:00
parent 6633578e2c
commit 4ca89b6ffe
+10 -22
View File
@@ -62,29 +62,17 @@ async def status(token: str = Depends(oauth2_scheme)) -> DAQStatusModel:
sample_pgroup = full.sample.user if full.sample is not None else None
sample_view_allowed = sample_pgroup in data.pgroups or is_staff
masked_sample = full.sample if in_ro and sample_view_allowed else None
masked_box = full.box if in_ro else None
masked_best_res = full.last_best_res if in_ro else None
masked_best_b = full.last_best_b_factor if in_ro else None
masked_crystal = full.crystal_size if in_ro else CrystalSize(x=0,y=0,z=0)
return DAQStatusModel(
state=full.state,
busy=full.busy,
geom=full.geom,
diffraction=full.diffraction,
bl=full.bl,
sample=masked_sample,
session=SessionStatus(
full.sample = full.sample if in_ro and sample_view_allowed else None
full.box = full.box if in_ro else None
full.last_best_res = full.last_best_res if in_ro else None
full.last_best_b_factor = full.last_best_b_factor if in_ro else None
full.crystal_size = full.crystal_size if in_ro else CrystalSize(x=0,y=0,z=0)
full.session = SessionStatus(
current_pgroup=cfg.pgroup,
session=cfg.session_state(data.session),
staff=data.staff
),
box=masked_box,
last_best_res=masked_best_res,
last_best_b_factor=masked_best_b,
crystal_size=masked_crystal
)
return full
except Exception as e:
logger.error(f"Error getting status: {e}")
@@ -424,10 +412,10 @@ async def auto(s: SampleShortInfo, token: str = Depends(oauth2_scheme)):
@app.post("/scan/smart_params")
async def set_smart_params(p: SimpleScanParameters, token: str = Depends(oauth2_scheme)) -> str:
token_data = auth.parse_token(token)
logger.debug(f"{token_data.session} Try to set smart params: {p}")
#token_data = auth.parse_token(token)
#logger.debug(f"{token_data.session} Try to set smart params: {p}")
auth.check_jwt_rw(cfg, auth.parse_token(token))
daq.smart_params = p
cfg.auto_params = p
return "OK"
@app.post("/scan/cancel")