aboutsummaryrefslogtreecommitdiff
path: root/uploader
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-25 18:52:55 -0500
committerFrederick Muriuki Muriithi2024-09-25 18:52:55 -0500
commitdc062fc61edac7a7333c7f3e6f3ed8f2c9961a44 (patch)
tree5784f898f18ce1d1a80d9e0fd7cb387fb8f740b0 /uploader
parent64d78239ab4839a331c4aaec4c0d7e8d1d179e53 (diff)
downloadgn-uploader-dc062fc61edac7a7333c7f3e6f3ed8f2c9961a44.tar.gz
Setup auth with dataset creation.
Diffstat (limited to 'uploader')
-rw-r--r--uploader/genotypes/views.py40
1 files changed, 35 insertions, 5 deletions
diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py
index 3c20b52..7b5994e 100644
--- a/uploader/genotypes/views.py
+++ b/uploader/genotypes/views.py
@@ -9,6 +9,7 @@ from flask import (flash,
current_app as app)
from uploader.ui import make_template_renderer
+from uploader.oauth2.client import oauth2_post
from uploader.authorisation import require_login
from uploader.db_utils import database_connection
from uploader.species.models import all_species, species_by_id
@@ -177,8 +178,37 @@ def create_dataset(species: dict, population: dict, **kwargs):# pylint: disable=
form["geno-dataset-fullname"],
form["geno-dataset-shortname"])
- flash("Successfully created genotype dataset."
- "alert-success")
- return redirect(url_for("species.populations.genotypes.list_genotypes",
- species_id=species["SpeciesId"],
- population_id=population["Id"]))
+ def __success__(_success):
+ flash("Successfully created genotype dataset." "alert-success")
+ return redirect(url_for(
+ "species.populations.genotypes.list_genotypes",
+ species_id=species["SpeciesId"],
+ population_id=population["Id"]))
+
+ def __fail__(error):
+ msg = "There was an error creating the genotype dataset."
+ if issubclass(type(error), Exception):
+ app.logger.debug("\n\n%s (Exception)\n\n", msg, exc_info=True)
+ raise error
+ if issubclass(type(error), Response):
+ try:
+ _data = error.json()
+ except Exception as _exc:
+ raise Exception(error.content) from _exc
+ raise Exception(_data)
+
+ app.logger.debug("\n\n%s\n\n", msg)
+ raise Exception(error)
+
+ return oauth2_post(
+ "auth/resource/genotypes/create",
+ json={
+ **dict(request.form),
+ "species_id": species["SpeciesId"],
+ "population_id": population["Id"],
+ "dataset_name": form["geno-dataset-name"],
+ "dataset_fullname": form["geno-dataset-fullname"],
+ "dataset_shortname": form["geno-dataset-shortname"],
+ "public": "on"
+ }
+ ).either(__fail__, __success__)