aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
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">