aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-04-20 10:00:09 +0300
committerFrederick Muriuki Muriithi2023-04-20 10:00:09 +0300
commita29c567aad3d579ec8f62ad824a979f5248f5c4d (patch)
tree25c67fc857cc1b4d828dbd35f48b5598b01e8772 /wqflask
parent86a1da54a1157f17fd5d6b62fc5c42c0ed6f342c (diff)
downloadgenenetwork2-a29c567aad3d579ec8f62ad824a979f5248f5c4d.tar.gz
Fix bugs: Add missing module. Make args mandatory
Add missing `wqflask.oauth2.ui` module Make arguments to the menu-generation macro mandatory going forward.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/oauth2/ui.py23
-rw-r--r--wqflask/wqflask/templates/oauth2/profile_nav.html2
2 files changed, 24 insertions, 1 deletions
diff --git a/wqflask/wqflask/oauth2/ui.py b/wqflask/wqflask/oauth2/ui.py
new file mode 100644
index 00000000..31b873be
--- /dev/null
+++ b/wqflask/wqflask/oauth2/ui.py
@@ -0,0 +1,23 @@
+"""UI utilities"""
+from flask import session, render_template
+
+from .client import oauth2_get
+
+def render_ui(templatepath: str, **kwargs):
+ """Handle repetitive UI rendering stuff."""
+ logged_in = ("oauth2_token" in session and bool(session["oauth2_token"]))
+ roles = kwargs.get("roles", tuple()) # Get roles if already provided
+ if logged_in and not bool(roles): # If not, try fetching them
+ roles_results = oauth2_get("oauth2/user/roles").either(
+ lambda err: {"roles_error": process_error(err)},
+ lambda roles: {"roles": roles})
+ kwargs = {**kwargs, **roles_results}
+ roles = kwargs.get("roles", tuple())
+ user_privileges = tuple(
+ privilege["privilege_id"] for role in roles
+ for privilege in role["privileges"])
+ kwargs = {
+ **kwargs, "roles": roles, "user_privileges": user_privileges,
+ "logged_in": logged_in
+ }
+ return render_template(templatepath, **kwargs)
diff --git a/wqflask/wqflask/templates/oauth2/profile_nav.html b/wqflask/wqflask/templates/oauth2/profile_nav.html
index 7260ec16..c8d018fd 100644
--- a/wqflask/wqflask/templates/oauth2/profile_nav.html
+++ b/wqflask/wqflask/templates/oauth2/profile_nav.html
@@ -1,4 +1,4 @@
-{%macro profile_nav(calling_page, logged_in=false, user_privileges=[])%}
+{%macro profile_nav(calling_page, logged_in, user_privileges)%}
<ul class="nav nav-pills">