Skip to content

Commit 583be45

Browse files
committed
feat: filter score calibrations by user permissions in fetch_score_set_by_urn
1 parent f4fbc42 commit 583be45

File tree

2 files changed

+77
-12
lines changed

2 files changed

+77
-12
lines changed

src/mavedb/routers/score_sets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ async def fetch_score_set_by_urn(
121121
if item.superseding_score_set and not has_permission(user, item.superseding_score_set, Action.READ).permitted:
122122
item.superseding_score_set = None
123123

124+
item.score_calibrations = [sc for sc in item.score_calibrations if has_permission(user, sc, Action.READ).permitted]
125+
124126
return item
125127

126128

tests/routers/test_score_set.py

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,6 @@ def test_can_update_score_set_data_before_publication(
352352
score_set_update_payload = deepcopy(TEST_MINIMAL_SEQ_SCORESET)
353353
score_set_update_payload.update({camelize(attribute): updated_data})
354354

355-
# The score ranges attribute requires a publication identifier source
356-
if attribute == "score_ranges":
357-
score_set_update_payload.update(
358-
{"secondaryPublicationIdentifiers": [{"identifier": TEST_PUBMED_IDENTIFIER, "dbName": "PubMed"}]}
359-
)
360-
361355
response = client.put(f"/api/v1/score-sets/{score_set['urn']}", json=score_set_update_payload)
362356
assert response.status_code == 200
363357

@@ -457,11 +451,6 @@ def test_can_update_score_set_supporting_data_after_publication(
457451
"attribute,updated_data,expected_response_data",
458452
[
459453
("target_genes", TEST_MINIMAL_ACC_SCORESET["targetGenes"], TEST_MINIMAL_SEQ_SCORESET_RESPONSE["targetGenes"]),
460-
(
461-
"score_ranges",
462-
[TEST_BRNICH_SCORE_CALIBRATION, TEST_PATHOGENICITY_SCORE_CALIBRATION],
463-
None,
464-
),
465454
],
466455
)
467456
@pytest.mark.parametrize(
@@ -517,7 +506,6 @@ def test_cannot_update_score_set_target_data_after_publication(
517506
score_set_update_payload.update(
518507
{
519508
camelize(attribute): updated_data,
520-
"secondaryPublicationIdentifiers": [{"identifier": TEST_PUBMED_IDENTIFIER, "dbName": "PubMed"}],
521509
}
522510
)
523511
response = client.put(f"/api/v1/score-sets/{published_urn}", json=score_set_update_payload)
@@ -695,6 +683,81 @@ def test_admin_can_get_other_user_private_score_set(session, client, admin_app_o
695683
assert (key, expected_response[key]) == (key, response_data[key])
696684

697685

686+
@pytest.mark.parametrize(
687+
"mock_publication_fetch",
688+
[
689+
(
690+
[
691+
{"dbName": "PubMed", "identifier": f"{TEST_PUBMED_IDENTIFIER}"},
692+
{"dbName": "bioRxiv", "identifier": f"{TEST_BIORXIV_IDENTIFIER}"},
693+
]
694+
)
695+
],
696+
indirect=["mock_publication_fetch"],
697+
)
698+
def test_extra_user_can_only_view_published_score_calibrations_in_score_set(
699+
client, setup_router_db, extra_user_app_overrides, mock_publication_fetch, session, data_provider, data_files
700+
):
701+
experiment = create_experiment(client)
702+
score_set = create_seq_score_set(client, experiment["urn"])
703+
score_set = mock_worker_variant_insertion(client, session, data_provider, score_set, data_files / "scores.csv")
704+
705+
with patch.object(arq.ArqRedis, "enqueue_job", return_value=None) as worker_queue:
706+
published_score_set = publish_score_set(client, score_set["urn"])
707+
worker_queue.assert_called_once()
708+
709+
create_test_score_calibration_in_score_set_via_client(
710+
client, published_score_set["urn"], deepcamelize(TEST_BRNICH_SCORE_CALIBRATION)
711+
)
712+
public_calibration = create_publish_and_promote_score_calibration(
713+
client,
714+
published_score_set["urn"],
715+
deepcamelize(TEST_BRNICH_SCORE_CALIBRATION),
716+
)
717+
718+
with DependencyOverrider(extra_user_app_overrides):
719+
response = client.get(f"/api/v1/score-sets/{published_score_set['urn']}")
720+
721+
assert response.status_code == 200
722+
response_data = response.json()
723+
assert len(response_data["scoreCalibrations"]) == 1
724+
assert response_data["scoreCalibrations"][0]["urn"] == public_calibration["urn"]
725+
726+
727+
@pytest.mark.parametrize(
728+
"mock_publication_fetch",
729+
[
730+
(
731+
[
732+
{"dbName": "PubMed", "identifier": f"{TEST_PUBMED_IDENTIFIER}"},
733+
{"dbName": "bioRxiv", "identifier": f"{TEST_BIORXIV_IDENTIFIER}"},
734+
]
735+
)
736+
],
737+
indirect=["mock_publication_fetch"],
738+
)
739+
def test_creating_user_can_view_all_score_calibrations_in_score_set(client, setup_router_db, mock_publication_fetch):
740+
experiment = create_experiment(client)
741+
score_set = create_seq_score_set(client, experiment["urn"])
742+
private_calibration = create_test_score_calibration_in_score_set_via_client(
743+
client, score_set["urn"], deepcamelize(TEST_BRNICH_SCORE_CALIBRATION)
744+
)
745+
public_calibration = create_publish_and_promote_score_calibration(
746+
client,
747+
score_set["urn"],
748+
deepcamelize(TEST_BRNICH_SCORE_CALIBRATION),
749+
)
750+
751+
response = client.get(f"/api/v1/score-sets/{score_set['urn']}")
752+
753+
assert response.status_code == 200
754+
response_data = response.json()
755+
assert len(response_data["scoreCalibrations"]) == 2
756+
urns = [calibration["urn"] for calibration in response_data["scoreCalibrations"]]
757+
assert private_calibration["urn"] in urns
758+
assert public_calibration["urn"] in urns
759+
760+
698761
########################################################################################################################
699762
# Adding scores to score set
700763
########################################################################################################################

0 commit comments

Comments
 (0)