aboutsummaryrefslogtreecommitdiff
path: root/uploader/phenotypes
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-10-07 16:43:53 -0500
committerFrederick Muriuki Muriithi2024-10-07 16:43:53 -0500
commit40dfa6d36fae873bd8a49e8a0943be64ef4d2196 (patch)
treeb4548fb57b181bdd85fa64075594d5e56b4e3686 /uploader/phenotypes
parentb591d477050c61171f452a795d5526e03993413d (diff)
downloadgn-uploader-40dfa6d36fae873bd8a49e8a0943be64ef4d2196.tar.gz
Handle "No linked resource" error cleanly.
Display the page even if there is no linked resource, but keep the sensitive information hidden in such cases.
Diffstat (limited to 'uploader/phenotypes')
-rw-r--r--uploader/phenotypes/views.py44
1 files changed, 27 insertions, 17 deletions
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index 312179e..ddf6908 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -1,6 +1,7 @@
"""Views handling ('classical') phenotypes."""
from functools import wraps
+from requests.models import Response
from MySQLdb.cursors import DictCursor
from flask import (flash,
request,
@@ -197,6 +198,31 @@ def view_phenotype(# pylint: disable=[unused-argument]
**kwargs
):
"""View an individual phenotype from the dataset."""
+ def __render__(privileges):
+ return render_template(
+ "phenotypes/view-phenotype.html",
+ species=species,
+ population=population,
+ dataset=dataset,
+ phenotype=phenotype_by_id(conn,
+ species["SpeciesId"],
+ population["Id"],
+ dataset["Id"],
+ xref_id),
+ privileges=(privileges
+ ### For demo! Do not commit this part
+ + ("group:resource:edit-resource",
+ "group:resource:delete-resource",)
+ ### END: For demo! Do not commit this part
+ ),
+ activelink="view-phenotype")
+
+ def __fail__(error):
+ if isinstance(error, Response) and error.json() == "No linked resource!":
+ return __render__(tuple())
+ return make_either_error_handler(
+ "There was an error fetching the roles and privileges.")(error)
+
with database_connection(app.config["SQL_URI"]) as conn:
return oauth2_post(
"/auth/resource/phenotypes/individual/linked-resource",
@@ -210,23 +236,7 @@ def view_phenotype(# pylint: disable=[unused-argument]
lambda resource: tuple(
privilege["privilege_id"] for role in resource["roles"]
for privilege in role["privileges"])
- ).then(
- lambda privileges: render_template(
- "phenotypes/view-phenotype.html",
- species=species,
- population=population,
- dataset=dataset,
- phenotype=phenotype_by_id(conn,
- species["SpeciesId"],
- population["Id"],
- dataset["Id"],
- xref_id),
- privileges=privileges,
- activelink="view-phenotype")
- ).either(
- make_either_error_handler(
- "There was an error fetching the roles and privileges."),
- lambda resp: resp)
+ ).then(__render__).either(__fail__, lambda resp: resp)
@phenotypesbp.route(