From 94513310831875a72d21b3e17af9541a328cabd6 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 1 Oct 2024 13:28:49 -0500 Subject: Extract privileges and use them for access control --- uploader/phenotypes/views.py | 8 ++- uploader/templates/phenotypes/view-dataset.html | 5 +- uploader/templates/phenotypes/view-phenotype.html | 63 ++++++++++++++++++++--- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py index 7fc3b08..63e0b84 100644 --- a/uploader/phenotypes/views.py +++ b/uploader/phenotypes/views.py @@ -200,7 +200,11 @@ def view_phenotype(# pylint: disable=[unused-argument] "xref_id": xref_id } ).then( - lambda resource: render_template( + 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, @@ -210,7 +214,7 @@ def view_phenotype(# pylint: disable=[unused-argument] population["Id"], dataset["Id"], xref_id), - resource=resource, + privileges=privileges, activelink="view-phenotype") ).either( make_either_error_handler( diff --git a/uploader/templates/phenotypes/view-dataset.html b/uploader/templates/phenotypes/view-dataset.html index 959b02a..e2ccb60 100644 --- a/uploader/templates/phenotypes/view-dataset.html +++ b/uploader/templates/phenotypes/view-dataset.html @@ -51,10 +51,9 @@

Phenotype Data

This dataset has a total of {{phenotype_count}} phenotypes.

-

+

- Limit access here, according to the authorisation privileges the user has on - this dataset!

+ Display pagination controls here …

diff --git a/uploader/templates/phenotypes/view-phenotype.html b/uploader/templates/phenotypes/view-phenotype.html index 5aef6c1..03935f5 100644 --- a/uploader/templates/phenotypes/view-phenotype.html +++ b/uploader/templates/phenotypes/view-phenotype.html @@ -24,18 +24,67 @@ {{flash_all_messages()}}
- {{resource}} -
+
+
Basic Phenotype Details
-
-

Dataset

- {{dataset}} +
+ + + + + + + + + + + + + +
Phenotype{{phenotype.Post_publication_description or phenotype.Pre_publication_abbreviation or phenotype.Original_description}} +
Cross-Reference ID{{phenotype.xref_id}}
Collation{{dataset.FullName}}
+
-

Phenotype

- {{phenotype}} +
+
Phenotype Data
+ {%if "group:resource:view-resource" in privileges%} + + + + + + + + + + + + + + {%for item in phenotype.data%} + + + + + + + + + {%endfor%} + +
#SampleValueSymbolSEN
{{loop.index}}{{item.StrainName}}{{item.value}}{{item.Symbol or "-"}}{{item.error or "-"}}{{item.count or "-"}}
+ {%else%} +

+ + You do not currently have privileges to view this phenotype in greater + detail. +

+ {%endif%} +
+ {%endblock%} {%block sidebarcontents%} -- cgit v1.2.3