aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authorisation/groups
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-04-21 05:24:21 +0300
committerFrederick Muriuki Muriithi2023-04-21 05:24:21 +0300
commit2f6f54e215d7618ab9efa4ed17e09c633db07eab (patch)
tree1bb1eda425e276b6c4cdf9550572dd948b8d5443 /gn3/auth/authorisation/groups
parent95f067a542424b76022595a74d660a7e84158f38 (diff)
downloadgenenetwork3-2f6f54e215d7618ab9efa4ed17e09c633db07eab.tar.gz
auth: Attach linked data to specific resources.
Diffstat (limited to 'gn3/auth/authorisation/groups')
-rw-r--r--gn3/auth/authorisation/groups/views.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/gn3/auth/authorisation/groups/views.py b/gn3/auth/authorisation/groups/views.py
index 202df95..9e717a9 100644
--- a/gn3/auth/authorisation/groups/views.py
+++ b/gn3/auth/authorisation/groups/views.py
@@ -180,12 +180,16 @@ def unlinked_phenotype_data(
"ON lpd.data_link_id=pr.data_link_id "
"WHERE lpd.group_id=? AND pr.data_link_id IS NULL",
(str(group.group_id),))
- ids = tuple((
- row["SpeciesId"], row["InbredSetId"], row["PublishFreezeId"],
- row["PublishXRefId"]) for row in authcur.fetchall())
- if len(ids) < 1:
+ results = authcur.fetchall()
+ ids: dict[tuple[str, ...], str] = {
+ (
+ row["SpeciesId"], row["InbredSetId"], row["PublishFreezeId"],
+ row["PublishXRefId"]): row["data_link_id"]
+ for row in results
+ }
+ if len(ids.keys()) < 1:
return tuple()
- paramstr = ", ".join(["(%s, %s, %s, %s)"] * len(ids))
+ paramstr = ", ".join(["(%s, %s, %s, %s)"] * len(ids.keys()))
gn3cur.execute(
"SELECT spc.SpeciesId, spc.SpeciesName, iset.InbredSetId, "
"iset.InbredSetName, pf.Id AS PublishFreezeId, "
@@ -208,7 +212,7 @@ def unlinked_phenotype_data(
"ON pxr.PhenotypeId=phen.Id "
"WHERE (spc.SpeciesId, iset.InbredSetId, pf.Id, pxr.Id) "
f"IN ({paramstr})",
- tuple(item for sublist in ids for item in sublist))
+ tuple(item for sublist in ids.keys() for item in sublist))
return tuple({
**{key: value for key, value in row.items() if key not in
("Post_publication_description", "Pre_publication_description",
@@ -216,7 +220,10 @@ def unlinked_phenotype_data(
"description": (
row["Post_publication_description"] or
row["Pre_publication_description"] or
- row["Original_description"])
+ row["Original_description"]),
+ "data_link_id": ids[tuple(str(row[key]) for key in (
+ "SpeciesId", "InbredSetId", "PublishFreezeId",
+ "PublishXRefId"))]
} for row in gn3cur.fetchall())
@groups.route("/<string:resource_type>/unlinked-data")