aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authorisation
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-04-10 10:08:54 +0300
committerFrederick Muriuki Muriithi2023-04-10 10:29:03 +0300
commitacde4fc57250cf2ecc0bb12b34d523d8cf306c3e (patch)
tree87546c23615e89cd58c18d635047d09dda4e471b /gn3/auth/authorisation
parente636acc412fef6b1d5aa08ac701bbadc3be52b80 (diff)
downloadgenenetwork3-acde4fc57250cf2ecc0bb12b34d523d8cf306c3e.tar.gz
Enable search, filtering out selected, but not linked data
When a user selects some datasets and does a new search, we filter out the selected datasets too, even though they are yet to be linked.
Diffstat (limited to 'gn3/auth/authorisation')
-rw-r--r--gn3/auth/authorisation/data/genotypes.py16
-rw-r--r--gn3/auth/authorisation/data/views.py23
2 files changed, 28 insertions, 11 deletions
diff --git a/gn3/auth/authorisation/data/genotypes.py b/gn3/auth/authorisation/data/genotypes.py
index fe06726..8f901a5 100644
--- a/gn3/auth/authorisation/data/genotypes.py
+++ b/gn3/auth/authorisation/data/genotypes.py
@@ -21,14 +21,17 @@ def linked_genotype_data(conn: authdb.DbConnection) -> Iterable[dict]:
"You do not have sufficient privileges to link data to (a) "
"group(s)."),
oauth2_scope="profile group resource")
-def ungrouped_genotype_data(
+def ungrouped_genotype_data(# pylint: disable=[too-many-arguments]
authconn: authdb.DbConnection, gn3conn: gn3db.Connection,
- search_query: str, limit: int = 10000, offset: int = 0) -> tuple[
+ search_query: str, selected: tuple[dict, ...] = tuple(),
+ limit: int = 10000, offset: int = 0) -> tuple[
dict, ...]:
"""Retrieve genotype data that is not linked to any user group."""
params = tuple(
(row["SpeciesId"], row["InbredSetId"], row["GenoFreezeId"])
- for row in linked_genotype_data(authconn))
+ for row in linked_genotype_data(authconn)) + tuple(
+ (row["SpeciesId"], row["InbredSetId"], row["GenoFreezeId"])
+ for row in selected)
query = (
"SELECT s.SpeciesId, iset.InbredSetId, iset.InbredSetName, "
"gf.Id AS GenoFreezeId, gf.Name AS dataset_name, "
@@ -50,14 +53,13 @@ def ungrouped_genotype_data(
if bool(search_query):
query = query + (
- "CONCAT(gf.Name, ' ', gf.FullName, ' ', gf.ShortName) LIKE '%%?%%' ")
- params = params + ((search_query,),)# type: ignore[operator]
+ "CONCAT(gf.Name, ' ', gf.FullName, ' ', gf.ShortName) LIKE %s ")
+ params = params + ((f"%{search_query}%",),)# type: ignore[operator]
query = query + f"LIMIT {int(limit)} OFFSET {int(offset)}"
- final_params = tuple(item for sublist in params for item in sublist)
with gn3conn.cursor(DictCursor) as cursor:
cursor.execute(
- query, final_params)
+ query, tuple(item for sublist in params for item in sublist))
return tuple(row for row in cursor.fetchall())
@authorised_p(
diff --git a/gn3/auth/authorisation/data/views.py b/gn3/auth/authorisation/data/views.py
index 55a7373..9a924b4 100644
--- a/gn3/auth/authorisation/data/views.py
+++ b/gn3/auth/authorisation/data/views.py
@@ -313,13 +313,28 @@ def migrate_users_data() -> Response:
def __search_mrna__():
pass
+def __request_key__(key: str, default: Any = ""):
+ if bool(request.json):
+ return request.json.get(#type: ignore[union-attr]
+ key, request.args.get(key, request.form.get(key, default)))
+ return request.args.get(key, request.form.get(key, default))
+
+def __request_key_list__(key: str, default: tuple[Any, ...] = tuple()):
+ if bool(request.json):
+ return (request.json.get(key,[])#type: ignore[union-attr]
+ or request.args.getlist(key) or request.form.getlist(key)
+ or list(default))
+ return (request.args.getlist(key)
+ or request.form.getlist(key) or list(default))
+
def __search_genotypes__():
- query = request.form.get("query", request.args.get("query", ""))
- limit = int(request.form.get("limit", request.args.get("limit", 10000)))
- offset = int(request.form.get("offset", request.args.get("offset", 0)))
+ query = __request_key__("query", "")
+ limit = int(__request_key__("limit", 10000))
+ offset = int(__request_key__("offset", 0))
with gn3db.database_connection() as gn3conn:
__ungrouped__ = partial(
ungrouped_genotype_data, gn3conn=gn3conn, search_query=query,
+ selected=__request_key_list__("selected"),
limit=limit, offset=offset)
return jsonify(with_db_connection(__ungrouped__))
@@ -330,7 +345,7 @@ def __search_phenotypes__():
@require_oauth("profile group resource")
def search_unlinked_data():
"""Search for various unlinked data."""
- dataset_type = request.form["dataset_type"]
+ dataset_type = request.json["dataset_type"]
search_fns = {
"mrna": __search_mrna__,
"genotype": __search_genotypes__,