Skip to content

Commit 6415ff0

Browse files
committed
Only show unpublished superseding score set to the users who have permissions to view it. The current version to other users will only be the published one.
1 parent 82cc0d6 commit 6415ff0

File tree

2 files changed

+87
-69
lines changed

2 files changed

+87
-69
lines changed

src/mavedb/lib/validation/urn_re.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
MAVEDB_TMP_URN_PATTERN = r"tmp:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
99
MAVEDB_TMP_URN_RE = re.compile(MAVEDB_TMP_URN_PATTERN)
1010

11+
# Old temp URN
12+
MAVEDB_OLD_TMP_URN_PATTERN = r"^tmp:[A-Za-z0-9]{16}$"
13+
MAVEDB_OLD_TMP_URN_RE = re.compile(MAVEDB_OLD_TMP_URN_PATTERN)
14+
1115
# Experiment set URN
1216
MAVEDB_EXPERIMENT_SET_URN_PATTERN = rf"urn:{MAVEDB_URN_NAMESPACE}:\d{{{MAVEDB_EXPERIMENT_SET_URN_DIGITS}}}"
1317
MAVEDB_EXPERIMENT_SET_URN_RE = re.compile(MAVEDB_EXPERIMENT_SET_URN_PATTERN)

src/mavedb/routers/score_sets.py

Lines changed: 83 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
search_score_sets as _search_score_sets,
4242
refresh_variant_urns,
4343
)
44+
from mavedb.lib.validation import urn_re
4445
from mavedb.lib.taxonomies import find_or_create_taxonomy
4546
from mavedb.lib.urns import (
4647
generate_experiment_set_urn,
@@ -64,7 +65,7 @@
6465

6566

6667
async def fetch_score_set_by_urn(
67-
db, urn: str, user: Optional[UserData], owner_or_contributor: Optional[UserData], only_published: bool
68+
db, urn: str, user: Optional[UserData], owner_or_contributor: Optional[UserData], only_published: bool
6869
) -> Optional[ScoreSet]:
6970
"""
7071
Fetch one score set by URN, ensuring that the user has read permission.
@@ -103,6 +104,17 @@ async def fetch_score_set_by_urn(
103104
raise HTTPException(status_code=404, detail=f"score set with URN '{urn}' not found")
104105

105106
assert_permission(user, item, Action.READ)
107+
if(
108+
item
109+
and item.superseding_score_set
110+
and not owner_or_contributor
111+
and (
112+
urn_re.MAVEDB_OLD_TMP_URN_RE.fullmatch(item.superseding_score_set.urn)
113+
or urn_re.MAVEDB_TMP_URN_RE.fullmatch(item.superseding_score_set.urn)
114+
)
115+
):
116+
item.superseding_score_set = None
117+
106118
return item
107119

108120

@@ -128,9 +140,9 @@ def search_score_sets(search: ScoreSetsSearch, db: Session = Depends(deps.get_db
128140
response_model=list[score_set.ShortScoreSet],
129141
)
130142
def search_my_score_sets(
131-
search: ScoreSetsSearch, # = Body(..., embed=True),
132-
db: Session = Depends(deps.get_db),
133-
user_data: UserData = Depends(require_current_user),
143+
search: ScoreSetsSearch, # = Body(..., embed=True),
144+
db: Session = Depends(deps.get_db),
145+
user_data: UserData = Depends(require_current_user),
134146
) -> Any:
135147
"""
136148
Search score sets created by the current user..
@@ -146,10 +158,10 @@ def search_my_score_sets(
146158
response_model_exclude_none=True,
147159
)
148160
async def show_score_set(
149-
*,
150-
urn: str,
151-
db: Session = Depends(deps.get_db),
152-
user_data: UserData = Depends(get_current_user),
161+
*,
162+
urn: str,
163+
db: Session = Depends(deps.get_db),
164+
user_data: UserData = Depends(get_current_user),
153165
) -> Any:
154166
"""
155167
Fetch a single score set by URN.
@@ -165,17 +177,17 @@ async def show_score_set(
165177
200: {
166178
"content": {"text/csv": {}},
167179
"description": """Variant scores in CSV format, with four fixed columns (accession, hgvs_nt, hgvs_pro,"""
168-
""" and hgvs_splice), plus score columns defined by the score set.""",
180+
""" and hgvs_splice), plus score columns defined by the score set.""",
169181
}
170182
},
171183
)
172184
def get_score_set_scores_csv(
173-
*,
174-
urn: str,
175-
start: int = Query(default=None, description="Start index for pagination"),
176-
limit: int = Query(default=None, description="Number of variants to return"),
177-
db: Session = Depends(deps.get_db),
178-
user_data: Optional[UserData] = Depends(get_current_user),
185+
*,
186+
urn: str,
187+
start: int = Query(default=None, description="Start index for pagination"),
188+
limit: int = Query(default=None, description="Number of variants to return"),
189+
db: Session = Depends(deps.get_db),
190+
user_data: Optional[UserData] = Depends(get_current_user),
179191
) -> Any:
180192
"""
181193
Return scores from a score set, identified by URN, in CSV format.
@@ -219,17 +231,17 @@ def get_score_set_scores_csv(
219231
200: {
220232
"content": {"text/csv": {}},
221233
"description": """Variant counts in CSV format, with four fixed columns (accession, hgvs_nt, hgvs_pro,"""
222-
""" and hgvs_splice), plus score columns defined by the score set.""",
234+
""" and hgvs_splice), plus score columns defined by the score set.""",
223235
}
224236
},
225237
)
226238
async def get_score_set_counts_csv(
227-
*,
228-
urn: str,
229-
start: int = Query(default=None, description="Start index for pagination"),
230-
limit: int = Query(default=None, description="Number of variants to return"),
231-
db: Session = Depends(deps.get_db),
232-
user_data: Optional[UserData] = Depends(get_current_user),
239+
*,
240+
urn: str,
241+
start: int = Query(default=None, description="Start index for pagination"),
242+
limit: int = Query(default=None, description="Number of variants to return"),
243+
db: Session = Depends(deps.get_db),
244+
user_data: Optional[UserData] = Depends(get_current_user),
233245
) -> Any:
234246
"""
235247
Return counts from a score set, identified by URN, in CSV format.
@@ -272,10 +284,10 @@ async def get_score_set_counts_csv(
272284
response_model=list[mapped_variant.MappedVariant],
273285
)
274286
def get_score_set_mapped_variants(
275-
*,
276-
urn: str,
277-
db: Session = Depends(deps.get_db),
278-
user_data: Optional[UserData] = Depends(get_current_user),
287+
*,
288+
urn: str,
289+
db: Session = Depends(deps.get_db),
290+
user_data: Optional[UserData] = Depends(get_current_user),
279291
) -> Any:
280292
"""
281293
Return mapped variants from a score set, identified by URN.
@@ -293,10 +305,10 @@ def get_score_set_mapped_variants(
293305

294306
mapped_variants = (
295307
db.query(MappedVariant)
296-
.filter(ScoreSet.urn == urn)
297-
.filter(ScoreSet.id == Variant.score_set_id)
298-
.filter(Variant.id == MappedVariant.variant_id)
299-
.all()
308+
.filter(ScoreSet.urn == urn)
309+
.filter(ScoreSet.id == Variant.score_set_id)
310+
.filter(Variant.id == MappedVariant.variant_id)
311+
.all()
300312
)
301313

302314
if not mapped_variants:
@@ -316,10 +328,10 @@ def get_score_set_mapped_variants(
316328
response_model_exclude_none=True,
317329
)
318330
async def create_score_set(
319-
*,
320-
item_create: score_set.ScoreSetCreate,
321-
db: Session = Depends(deps.get_db),
322-
user_data: UserData = Depends(require_current_user_with_email),
331+
*,
332+
item_create: score_set.ScoreSetCreate,
333+
db: Session = Depends(deps.get_db),
334+
user_data: UserData = Depends(require_current_user_with_email),
323335
) -> Any:
324336
"""
325337
Create a score set.
@@ -461,9 +473,10 @@ async def create_score_set(
461473
for identifier in item_create.primary_publication_identifiers or []
462474
]
463475
publication_identifiers = [
464-
await find_or_create_publication_identifier(db, identifier.identifier, identifier.db_name)
465-
for identifier in item_create.secondary_publication_identifiers or []
466-
] + primary_publication_identifiers
476+
await find_or_create_publication_identifier(db, identifier.identifier,
477+
identifier.db_name)
478+
for identifier in item_create.secondary_publication_identifiers or []
479+
] + primary_publication_identifiers
467480

468481
# create a temporary `primary` attribute on each of our publications that indicates
469482
# to our association proxy whether it is a primary publication or not
@@ -603,13 +616,13 @@ async def create_score_set(
603616
response_model_exclude_none=True,
604617
)
605618
async def upload_score_set_variant_data(
606-
*,
607-
urn: str,
608-
counts_file: Optional[UploadFile] = File(None),
609-
scores_file: UploadFile = File(...),
610-
db: Session = Depends(deps.get_db),
611-
user_data: UserData = Depends(require_current_user_with_email),
612-
worker: ArqRedis = Depends(deps.get_worker),
619+
*,
620+
urn: str,
621+
counts_file: Optional[UploadFile] = File(None),
622+
scores_file: UploadFile = File(...),
623+
db: Session = Depends(deps.get_db),
624+
user_data: UserData = Depends(require_current_user_with_email),
625+
worker: ArqRedis = Depends(deps.get_worker),
613626
) -> Any:
614627
"""
615628
Upload scores and variant count files for a score set, and initiate processing these files to
@@ -660,12 +673,12 @@ async def upload_score_set_variant_data(
660673
"/score-sets/{urn}", response_model=score_set.ScoreSet, responses={422: {}}, response_model_exclude_none=True
661674
)
662675
async def update_score_set(
663-
*,
664-
urn: str,
665-
item_update: score_set.ScoreSetUpdate,
666-
db: Session = Depends(deps.get_db),
667-
user_data: UserData = Depends(require_current_user_with_email),
668-
worker: ArqRedis = Depends(deps.get_worker),
676+
*,
677+
urn: str,
678+
item_update: score_set.ScoreSetUpdate,
679+
db: Session = Depends(deps.get_db),
680+
user_data: UserData = Depends(require_current_user_with_email),
681+
worker: ArqRedis = Depends(deps.get_worker),
669682
) -> Any:
670683
"""
671684
Update a score set.
@@ -722,9 +735,10 @@ async def update_score_set(
722735
for identifier in item_update.primary_publication_identifiers or []
723736
]
724737
publication_identifiers = [
725-
await find_or_create_publication_identifier(db, identifier.identifier, identifier.db_name)
726-
for identifier in item_update.secondary_publication_identifiers or []
727-
] + primary_publication_identifiers
738+
await find_or_create_publication_identifier(db, identifier.identifier,
739+
identifier.db_name)
740+
for identifier in item_update.secondary_publication_identifiers or []
741+
] + primary_publication_identifiers
728742

729743
# create a temporary `primary` attribute on each of our publications that indicates
730744
# to our association proxy whether it is a primary publication or not
@@ -863,15 +877,15 @@ async def update_score_set(
863877
if item.variants:
864878
assert item.dataset_columns is not None
865879
score_columns = [
866-
"hgvs_nt",
867-
"hgvs_splice",
868-
"hgvs_pro",
869-
] + item.dataset_columns["score_columns"]
880+
"hgvs_nt",
881+
"hgvs_splice",
882+
"hgvs_pro",
883+
] + item.dataset_columns["score_columns"]
870884
count_columns = [
871-
"hgvs_nt",
872-
"hgvs_splice",
873-
"hgvs_pro",
874-
] + item.dataset_columns["count_columns"]
885+
"hgvs_nt",
886+
"hgvs_splice",
887+
"hgvs_pro",
888+
] + item.dataset_columns["count_columns"]
875889

876890
scores_data = pd.DataFrame(
877891
variants_to_csv_rows(item.variants, columns=score_columns, dtype="score_data")
@@ -914,10 +928,10 @@ async def update_score_set(
914928

915929
@router.delete("/score-sets/{urn}", responses={422: {}})
916930
async def delete_score_set(
917-
*,
918-
urn: str,
919-
db: Session = Depends(deps.get_db),
920-
user_data: UserData = Depends(require_current_user),
931+
*,
932+
urn: str,
933+
db: Session = Depends(deps.get_db),
934+
user_data: UserData = Depends(require_current_user),
921935
) -> Any:
922936
"""
923937
Delete a score set.
@@ -952,10 +966,10 @@ async def delete_score_set(
952966
response_model_exclude_none=True,
953967
)
954968
def publish_score_set(
955-
*,
956-
urn: str,
957-
db: Session = Depends(deps.get_db),
958-
user_data: UserData = Depends(require_current_user),
969+
*,
970+
urn: str,
971+
db: Session = Depends(deps.get_db),
972+
user_data: UserData = Depends(require_current_user),
959973
) -> Any:
960974
"""
961975
Publish a score set.

0 commit comments

Comments
 (0)