From bb83fdde2cff7abd8571350966fa78545b1831ef Mon Sep 17 00:00:00 2001
From: Frederick Muriuki Muriithi
Date: Mon, 17 Jun 2024 13:56:29 -0500
Subject: Delete request to obsoleted endpoint.
---
gn2/wqflask/oauth2/ui.py | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
(limited to 'gn2/wqflask/oauth2/ui.py')
diff --git a/gn2/wqflask/oauth2/ui.py b/gn2/wqflask/oauth2/ui.py
index cf2e9af7..e31d87d9 100644
--- a/gn2/wqflask/oauth2/ui.py
+++ b/gn2/wqflask/oauth2/ui.py
@@ -7,12 +7,7 @@ from .request_utils import process_error
def render_ui(templatepath: str, **kwargs):
"""Handle repetitive UI rendering stuff."""
- roles = kwargs.get("roles", tuple()) # Get roles if already provided
- if user_logged_in() and not bool(roles): # If not, try fetching them
- roles_results = oauth2_get("auth/system/roles").either(
- lambda err: {"roles_error": process_error(err)},
- lambda roles: {"roles": roles})
- kwargs = {**kwargs, **roles_results}
+ roles = kwargs.get("roles", tuple()) # Get roles
user_privileges = tuple(
privilege["privilege_id"] for role in roles
for privilege in role["privileges"])
--
cgit v1.2.3
From 7ed51c24678d2b880081f81ad4439e7ebcb0d19d Mon Sep 17 00:00:00 2001
From: Frederick Muriuki Muriithi
Date: Mon, 17 Jun 2024 13:58:13 -0500
Subject: Use privilege objects rather than IDS.
---
gn2/wqflask/oauth2/ui.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
(limited to 'gn2/wqflask/oauth2/ui.py')
diff --git a/gn2/wqflask/oauth2/ui.py b/gn2/wqflask/oauth2/ui.py
index e31d87d9..90d65e0b 100644
--- a/gn2/wqflask/oauth2/ui.py
+++ b/gn2/wqflask/oauth2/ui.py
@@ -9,8 +9,7 @@ def render_ui(templatepath: str, **kwargs):
"""Handle repetitive UI rendering stuff."""
roles = kwargs.get("roles", tuple()) # Get roles
user_privileges = tuple(
- privilege["privilege_id"] for role in roles
- for privilege in role["privileges"])
+ privilege for role in roles for privilege in role["privileges"])
kwargs = {
**kwargs, "roles": roles, "user_privileges": user_privileges
}
--
cgit v1.2.3
From 6d39ea99231aa0d07726a013c9a17c89a72e407a Mon Sep 17 00:00:00 2001
From: John Nduli
Date: Tue, 6 Aug 2024 08:10:04 +0300
Subject: fix: pass in proper list of priviledge_ids
---
gn2/wqflask/oauth2/ui.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(limited to 'gn2/wqflask/oauth2/ui.py')
diff --git a/gn2/wqflask/oauth2/ui.py b/gn2/wqflask/oauth2/ui.py
index 90d65e0b..d70a13ec 100644
--- a/gn2/wqflask/oauth2/ui.py
+++ b/gn2/wqflask/oauth2/ui.py
@@ -8,8 +8,11 @@ from .request_utils import process_error
def render_ui(templatepath: str, **kwargs):
"""Handle repetitive UI rendering stuff."""
roles = kwargs.get("roles", tuple()) # Get roles
+ if not roles:
+ roles = oauth2_get("auth/system/roles").either(
+ lambda _err: roles, lambda auth_roles: auth_roles)
user_privileges = tuple(
- privilege for role in roles for privilege in role["privileges"])
+ privilege["privilege_id"] for role in roles for privilege in role["privileges"])
kwargs = {
**kwargs, "roles": roles, "user_privileges": user_privileges
}
--
cgit v1.2.3
From 4aa2d88b2915323398c5b14a64e10f822df9a93e Mon Sep 17 00:00:00 2001
From: John Nduli
Date: Tue, 6 Aug 2024 08:36:28 +0300
Subject: fix: use bearer token to query auth server
---
gn2/wqflask/oauth2/ui.py | 5 ++++-
gn2/wqflask/static/new/javascript/auth/search_mrna.js | 5 +++++
gn2/wqflask/templates/oauth2/data-list-mrna.html | 2 ++
3 files changed, 11 insertions(+), 1 deletion(-)
(limited to 'gn2/wqflask/oauth2/ui.py')
diff --git a/gn2/wqflask/oauth2/ui.py b/gn2/wqflask/oauth2/ui.py
index d70a13ec..89739fe3 100644
--- a/gn2/wqflask/oauth2/ui.py
+++ b/gn2/wqflask/oauth2/ui.py
@@ -1,6 +1,8 @@
"""UI utilities"""
from flask import session, render_template
+from gn2.wqflask.oauth2 import session
+
from .client import oauth2_get
from .client import user_logged_in
from .request_utils import process_error
@@ -13,7 +15,8 @@ def render_ui(templatepath: str, **kwargs):
lambda _err: roles, lambda auth_roles: auth_roles)
user_privileges = tuple(
privilege["privilege_id"] for role in roles for privilege in role["privileges"])
+ user_token = session.user_token().either(lambda _err: "", lambda token: token["access_token"])
kwargs = {
- **kwargs, "roles": roles, "user_privileges": user_privileges
+ **kwargs, "roles": roles, "user_privileges": user_privileges, "bearer_token": user_token
}
return render_template(templatepath, **kwargs)
diff --git a/gn2/wqflask/static/new/javascript/auth/search_mrna.js b/gn2/wqflask/static/new/javascript/auth/search_mrna.js
index 76b2dc6b..ed264bb4 100644
--- a/gn2/wqflask/static/new/javascript/auth/search_mrna.js
+++ b/gn2/wqflask/static/new/javascript/auth/search_mrna.js
@@ -15,12 +15,17 @@ function search_mrna() {
selected = JSON.parse(document.getElementById(
"tbl-link").getAttribute("data-datasets"));
species_name = document.getElementById("txt-species-name").value
+ bearer_token = document.getElementById("bearer_token").value
search_endpoint = "/auth/data/mrna/search"
search_table = new TableDataSource(
"#tbl-search", "data-datasets", search_checkbox);
$.ajax(
form.action,
{
+
+ "beforeSend": function (xhr) {
+ xhr.setRequestHeader('Authorization', 'Bearer ' + bearer_token);
+ },
"method": "POST",
"contentType": "application/json; charset=utf-8",
"dataType": "json",
diff --git a/gn2/wqflask/templates/oauth2/data-list-mrna.html b/gn2/wqflask/templates/oauth2/data-list-mrna.html
index 728e95d4..0ee9d27e 100644
--- a/gn2/wqflask/templates/oauth2/data-list-mrna.html
+++ b/gn2/wqflask/templates/oauth2/data-list-mrna.html
@@ -95,6 +95,8 @@
action="{{search_uri}}"
method="POST">
+
+