From a21cd4c10bbbd2267f33a4acb968ccc8eee0cc7c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 26 Jan 2023 09:35:59 +0300 Subject: oauth2: UI: Rework user dashboard UI Separate the roles, resources and group information from the overview page. --- wqflask/wqflask/oauth2/routes.py | 36 +++++++-- wqflask/wqflask/templates/oauth2/profile_nav.html | 35 +++++++++ .../wqflask/templates/oauth2/request_error.html | 31 ++++++++ wqflask/wqflask/templates/oauth2/resources.html | 31 ++++++++ wqflask/wqflask/templates/oauth2/roles.html | 26 +++++++ wqflask/wqflask/templates/oauth2/view-user.html | 90 ++++++---------------- 6 files changed, 176 insertions(+), 73 deletions(-) create mode 100644 wqflask/wqflask/templates/oauth2/profile_nav.html create mode 100644 wqflask/wqflask/templates/oauth2/request_error.html create mode 100644 wqflask/wqflask/templates/oauth2/resources.html create mode 100644 wqflask/wqflask/templates/oauth2/roles.html diff --git a/wqflask/wqflask/oauth2/routes.py b/wqflask/wqflask/oauth2/routes.py index 33282dc1..ad0c080e 100644 --- a/wqflask/wqflask/oauth2/routes.py +++ b/wqflask/wqflask/oauth2/routes.py @@ -55,7 +55,7 @@ def oauth2_get(uri_path: str) -> Either: if resp.status_code == 200: return Right(resp.json()) - return Left(resp.json()) + return Left(resp) def oauth2_post(uri_path: str, data: dict) -> Either: token = session.get("oauth2_token") @@ -67,7 +67,11 @@ def oauth2_post(uri_path: str, data: dict) -> Either: if resp.status_code == 200: return Right(resp.json()) - return Left(resp.json()) + return Left(resp) + +def __request_error__(response): + app.logger.error(f"{response}: {response.url} [{response.status_code}]") + return render_template("oauth2/request_error.html", response=response) @oauth2.route("/login", methods=["GET", "POST"]) def login(): @@ -166,10 +170,8 @@ def user_profile(): scope = SCOPE, token=session.get("oauth2_token")) roles = oauth2_get("oauth2/user-roles").either(lambda x: "Error", lambda x: x) - resources = [] return render_template( - "oauth2/view-user.html", user_details=user_details, - roles=roles, resources=resources) + "oauth2/view-user.html", user_details=user_details, roles=roles) @oauth2.route("/request-add-to-group", methods=["POST"]) @require_oauth2 @@ -225,3 +227,27 @@ def group_join_or_create(): groups = oauth2_get("oauth2/groups").either( lambda x: __raise_unimplemented__(), lambda x: x) return render_template("oauth2/group_join_or_create.html", groups=groups) + +@oauth2.route("/user-resources", methods=["GET"]) +def user_resources(): + def __success__(resources): + return render_template("oauth2/resources.html", resources=resources) + + return oauth2_get("oauth2/user-resources").either( + __request_error__, __success__) + +@oauth2.route("/user-roles", methods=["GET"]) +def user_roles(): + def __success__(roles): + return render_template("oauth2/roles.html", roles=roles) + + return oauth2_get("oauth2/user-roles").either( + __request_error__, __success__) + +@oauth2.route("/user-group", methods=["GET"]) +def user_group(): + def __success__(group): + return render_template("oauth2/group.html", group=group) + + return oauth2_get("oauth2/user-group").either( + __request_error__, __success__) diff --git a/wqflask/wqflask/templates/oauth2/profile_nav.html b/wqflask/wqflask/templates/oauth2/profile_nav.html new file mode 100644 index 00000000..7ec7691b --- /dev/null +++ b/wqflask/wqflask/templates/oauth2/profile_nav.html @@ -0,0 +1,35 @@ +{%macro profile_nav(calling_page)%} + +
+ +{%endmacro%} diff --git a/wqflask/wqflask/templates/oauth2/request_error.html b/wqflask/wqflask/templates/oauth2/request_error.html new file mode 100644 index 00000000..35842e68 --- /dev/null +++ b/wqflask/wqflask/templates/oauth2/request_error.html @@ -0,0 +1,31 @@ +{%extends "base.html"%} +{%from "oauth2/profile_nav.html" import profile_nav%} +{%block title%}View User{%endblock%} +{%block content%} ++ + + The user has no access to any resource. + +
+ {%endfor%} ++ + No roles attached to this user +
+ {%endfor%} +Name: {{user_details.name}}
-E-Mail: {{user_details.email}}
- {%if user_details.group%} -Group:{{user_details.group.group_name}}
- {%else%} -- - - User is not a member of a group. -
+ {%if user_details%} +Name: {{user_details.name}}
+E-Mail: {{user_details.email}}
+ {%if user_details.group%} +Group:{{user_details.group.group_name}}
+ {%else%} ++ + + User is not a member of a group. +
- - {%endif%} - {%else%} -No details found.
- {%endif%} -No details found.
+ {%endif%}The user has access to the following resources:
- {%for resource in resources %} - {{role}} - {%else%} -- - - The user has no access to any resource. - -
- {%endfor%} -- - No roles attached to this user -
- {%endfor%} -