diff options
author | Frederick Muriuki Muriithi | 2023-04-17 09:24:54 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-04-17 09:24:54 +0300 |
commit | 85abf12d364c626af9177deb0398849845bcc6c3 (patch) | |
tree | 923b61bab797b2924d6c7423f3890d95d4f779d6 /gn3/auth/authorisation/groups | |
parent | dbf0f9f0d34c9969aa6ae76f556745a9eb122106 (diff) | |
download | genenetwork3-85abf12d364c626af9177deb0398849845bcc6c3.tar.gz |
auth: Delete code that is no longer used
Diffstat (limited to 'gn3/auth/authorisation/groups')
-rw-r--r-- | gn3/auth/authorisation/groups/data.py | 99 | ||||
-rw-r--r-- | gn3/auth/authorisation/groups/views.py | 16 |
2 files changed, 1 insertions, 114 deletions
diff --git a/gn3/auth/authorisation/groups/data.py b/gn3/auth/authorisation/groups/data.py index 0c821d3..453cc71 100644 --- a/gn3/auth/authorisation/groups/data.py +++ b/gn3/auth/authorisation/groups/data.py @@ -9,105 +9,6 @@ from gn3.auth.authorisation.groups import Group from gn3.auth.authorisation.checks import authorised_p from gn3.auth.authorisation.errors import InvalidData, NotFoundError -def __fetch_grouped_data__( - conn: authdb.DbConnection, dataset_type: str) -> Sequence[dict[str, Any]]: - """Retrieve ids for all data that are linked to groups in the auth db.""" - with authdb.cursor(conn) as cursor: - cursor.execute( - "SELECT dataset_type, dataset_or_trait_id FROM linked_group_data " - "WHERE LOWER(dataset_type)=?", - (dataset_type,)) - return tuple(dict(row) for row in cursor.fetchall()) - -def __fetch_ungrouped_mrna_data__( - conn: gn3db.Connection, grouped_data, offset: int) -> Sequence[dict]: - """Fetch ungrouped mRNA Assay data.""" - query = ("SELECT psf.Id, psf.Name AS dataset_name, " - "psf.FullName AS dataset_fullname, " - "ifiles.GN_AccesionId AS accession_id FROM ProbeSetFreeze AS psf " - "INNER JOIN InfoFiles AS ifiles ON psf.Name=ifiles.InfoPageName") - params: tuple[Any, ...] = tuple() - if bool(grouped_data): - clause = ", ".join(["%s"] * len(grouped_data)) - query = f"{query} WHERE psf.Id NOT IN ({clause})" - params = tuple(item["dataset_or_trait_id"] for item in grouped_data) - - query = f"{query} LIMIT 100 OFFSET %s" - with conn.cursor(DictCursor) as cursor: - cursor.execute(query, (params + (offset,))) - return tuple(dict(row) for row in cursor.fetchall()) - -def __fetch_ungrouped_geno_data__( - conn: gn3db.Connection, grouped_data, offset: int) -> Sequence[dict]: - """Fetch ungrouped Genotype data.""" - query = ("SELECT gf.Id, gf.Name AS dataset_name, " - "gf.FullName AS dataset_fullname, " - "ifiles.GN_AccesionId AS accession_id FROM GenoFreeze AS gf " - "INNER JOIN InfoFiles AS ifiles ON gf.Name=ifiles.InfoPageName") - params: tuple[Any, ...] = tuple() - if bool(grouped_data): - clause = ", ".join(["%s"] * len(grouped_data)) - query = f"{query} WHERE gf.Id NOT IN ({clause})" - params = tuple(item["dataset_or_trait_id"] for item in grouped_data) - - query = f"{query} LIMIT 100 OFFSET %s" - with conn.cursor(DictCursor) as cursor: - cursor.execute(query, (params + (offset,))) - return tuple(dict(row) for row in cursor.fetchall()) - -def __fetch_ungrouped_pheno_data__( - conn: gn3db.Connection, grouped_data, offset: int) -> Sequence[dict]: - """Fetch ungrouped Phenotype data.""" - query = ("SELECT " - "pxf.Id, iset.InbredSetName, pf.Name AS dataset_name, " - "pf.FullName AS dataset_fullname, " - "pf.ShortName AS dataset_shortname " - "FROM PublishXRef AS pxf " - "INNER JOIN InbredSet AS iset " - "ON pxf.InbredSetId=iset.InbredSetId " - "LEFT JOIN PublishFreeze AS pf " - "ON iset.InbredSetId=pf.InbredSetId") - params: tuple[Any, ...] = tuple() - if bool(grouped_data): - clause = ", ".join(["%s"] * len(grouped_data)) - query = f"{query} WHERE pxf.Id NOT IN ({clause})" - params = tuple(item["dataset_or_trait_id"] for item in grouped_data) - - query = f"{query} LIMIT 100 OFFSET %s" - with conn.cursor(DictCursor) as cursor: - cursor.execute(query, (params + (offset,))) - return tuple(dict(row) for row in cursor.fetchall()) - -def __fetch_ungrouped_data__( - conn: gn3db.Connection, dataset_type: str, - ungrouped: Sequence[dict[str, Any]], - offset) -> Sequence[dict[str, Any]]: - """Fetch any ungrouped data.""" - fetch_fns = { - "mrna": __fetch_ungrouped_mrna_data__, - "genotype": __fetch_ungrouped_geno_data__, - "phenotype": __fetch_ungrouped_pheno_data__ - } - return fetch_fns[dataset_type](conn, ungrouped, offset) - -@authorised_p(("system:data:link-to-group",), - error_description=( - "You do not have sufficient privileges to link data to (a) " - "group(s)."), - oauth2_scope="profile group resource") -def retrieve_ungrouped_data( - authconn: authdb.DbConnection, - gn3conn: gn3db.Connection, - dataset_type: str, - offset: int = 0) -> Sequence[dict]: - """Retrieve any data not linked to any group.""" - if dataset_type not in ("mrna", "genotype", "phenotype"): - raise InvalidData( - "Requested dataset type is invalid. Expected one of " - "'mrna', 'genotype' or 'phenotype'.") - grouped_data = __fetch_grouped_data__(authconn, dataset_type) - return __fetch_ungrouped_data__(gn3conn, dataset_type, grouped_data, offset) - def __fetch_mrna_data_by_ids__( conn: gn3db.Connection, dataset_ids: tuple[str, ...]) -> tuple[ dict, ...]: diff --git a/gn3/auth/authorisation/groups/views.py b/gn3/auth/authorisation/groups/views.py index e933bcd..0ff2903 100644 --- a/gn3/auth/authorisation/groups/views.py +++ b/gn3/auth/authorisation/groups/views.py @@ -12,7 +12,7 @@ from gn3 import db_utils as gn3dbutils from gn3.auth.dictify import dictify from gn3.auth.db_utils import with_db_connection -from .data import link_data_to_group, retrieve_ungrouped_data +from .data import link_data_to_group from .models import ( Group, user_group, all_groups, DUMMY_GROUP, GroupRole, group_by_id, join_requests, group_role_by_id, GroupCreationError, @@ -199,20 +199,6 @@ def unlinked_data(resource_type: str) -> Response: return jsonify(tuple()) -@groups.route("/<string:dataset_type>/ungrouped-data", methods=["GET"]) -@require_oauth("profile group resource") -def ungrouped_data(dataset_type: str) -> Response: - """View data not linked to any group.""" - if dataset_type not in ("all", "mrna", "genotype", "phenotype"): - raise AuthorisationError(f"Invalid dataset type {dataset_type}") - - with require_oauth.acquire("profile group resource") as _the_token: - with gn3dbutils.database_connection(current_app.config["SQL_URI"]) as gn3conn: - return jsonify(with_db_connection(partial( - retrieve_ungrouped_data, gn3conn=gn3conn, - dataset_type=dataset_type, - offset = int(request.args.get("offset", 0))))) - @groups.route("/data/link", methods=["POST"]) @require_oauth("profile group resource") def link_data() -> Response: |