Skip to content

Commit ad5609b

Browse files
committed
Check existence and permission on superseded_score_set_urn and meta_analyzes_score_set_urns on score set updates
The `score_set_update` router function, used but the scoreset PUT and PATCH endpoints, allowed for updating `superseded_score_set_urn` and `meta_analyzes_score_set_urns`, but was not validating their existence and user permissions. This change adds both checks for those values.
1 parent b3a5a88 commit ad5609b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/mavedb/routers/score_sets.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,38 @@ async def score_set_update(
264264
logger.error(msg="Could not find ORCID user with the provided user ID.", extra=logging_context())
265265
raise HTTPException(status_code=422, detail=str(e))
266266

267+
if "superseded_score_set_urn" in item_update_dict:
268+
superseded_urn = item_update_dict.get("superseded_score_set_urn")
269+
if superseded_urn:
270+
superseded_score_set = await fetch_score_set_by_urn(db, superseded_urn, user_data, user_data, True)
271+
272+
if superseded_score_set is None:
273+
logger.info(
274+
msg="Failed to create score set; The requested superseded score set does not exist.",
275+
extra=logging_context(),
276+
)
277+
raise HTTPException(
278+
status_code=status.HTTP_400_BAD_REQUEST,
279+
detail="Unknown superseded score set",
280+
)
281+
282+
if "meta_analyzes_score_set_urns" in item_update_dict:
283+
meta_analyzed_urns = item_update_dict.get("meta_analyzes_score_set_urns") or []
284+
existing_meta_analyses = find_meta_analyses_for_experiment_sets(db, meta_analyzed_urns, item.experiment)
285+
existing_meta_analyses_urns = [ma.urn for ma in existing_meta_analyses]
286+
287+
# compare list of urns with existing meta analyses to find any urns that do not correspond to existing score sets
288+
missing_urns = [urn for urn in meta_analyzed_urns if urn not in existing_meta_analyses_urns]
289+
if len(missing_urns) > 0:
290+
logger.info(
291+
msg="Failed to create score set; The following meta analysis URNs do not correspond to existing score sets.",
292+
extra=logging_context(),
293+
)
294+
raise HTTPException(
295+
status_code=status.HTTP_400_BAD_REQUEST,
296+
detail=f"Unknown meta analysis URNs: {missing_urns}",
297+
)
298+
267299
# Score set has not been published and attributes affecting scores may still be edited.
268300
if item.private:
269301
if "score_ranges" in item_update_dict:

0 commit comments

Comments
 (0)