From e8e5bf9e58368f9bdda0b22f23461e943ac1252a Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 10 Feb 2023 14:10:23 +0300 Subject: oauth2: data: Start on UI for linking data to groups. --- wqflask/wqflask/oauth2/data.py | 34 +++++++++++++++++++++ wqflask/wqflask/oauth2/routes.py | 2 ++ wqflask/wqflask/oauth2/users.py | 5 ++- wqflask/wqflask/templates/oauth2/data-list.html | 37 +++++++++++++++++++++++ wqflask/wqflask/templates/oauth2/profile_nav.html | 11 ++++++- wqflask/wqflask/templates/oauth2/view-user.html | 2 +- 6 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 wqflask/wqflask/oauth2/data.py create mode 100644 wqflask/wqflask/templates/oauth2/data-list.html diff --git a/wqflask/wqflask/oauth2/data.py b/wqflask/wqflask/oauth2/data.py new file mode 100644 index 00000000..44b65575 --- /dev/null +++ b/wqflask/wqflask/oauth2/data.py @@ -0,0 +1,34 @@ +"""Handle linking data to groups.""" + +from flask import Response, Blueprint, render_template + +from .request_utils import process_error +from .client import oauth2_get, oauth2_post + +data = Blueprint("data", __name__) + +@data.route("/list") +def list_data(): + + def __render__(**kwargs): + roles = kwargs.get("roles", []) + user_privileges = tuple( + privilege["privilege_id"] for role in roles + for privilege in role["privileges"]) + return render_template( + "oauth2/data-list.html", + groups=kwargs.get("groups", []), + data_items=kwargs.get("data_items", []), + user_privileges=kwargs.get("user_privileges",[]), + **{key:val for key,val in kwargs.items() + if key not in ("groups", "data_items", "user_privileges")}) + + groups = oauth2_get("oauth2/group/list").either( + lambda err: {"groups_error": process_error(err)}, + lambda grp: {"groups": grp}) + roles = oauth2_get("oauth2/roles").either( + lambda err: {"roles_error": process_error(err)}, + lambda roles: {"roles": roles}) + data_items = {} + + return __render__(**{**groups, **roles, **data_items}) diff --git a/wqflask/wqflask/oauth2/routes.py b/wqflask/wqflask/oauth2/routes.py index 93219bce..4c4b877b 100644 --- a/wqflask/wqflask/oauth2/routes.py +++ b/wqflask/wqflask/oauth2/routes.py @@ -1,6 +1,7 @@ """Routes for the OAuth2 auth system in GN3""" from flask import Blueprint +from .data import data from .users import users from .roles import roles from .groups import groups @@ -10,6 +11,7 @@ from .resources import resources oauth2 = Blueprint("oauth2", __name__, template_folder="templates/oauth2") oauth2.register_blueprint(toplevel, url_prefix="/") +oauth2.register_blueprint(data, url_prefix="/data") oauth2.register_blueprint(users, url_prefix="/user") oauth2.register_blueprint(roles, url_prefix="/role") oauth2.register_blueprint(groups, url_prefix="/group") diff --git a/wqflask/wqflask/oauth2/users.py b/wqflask/wqflask/oauth2/users.py index 28a495aa..d1bf0e5b 100644 --- a/wqflask/wqflask/oauth2/users.py +++ b/wqflask/wqflask/oauth2/users.py @@ -21,6 +21,9 @@ def user_profile(): def __render__(usr_dets, roles=[], **kwargs): return render_template( "oauth2/view-user.html", user_details=usr_dets, roles=roles, + user_privileges = tuple( + privilege["privilege_id"] for role in roles + for privilege in role["privileges"]), **kwargs) def __roles_success__(roles): @@ -29,7 +32,7 @@ def user_profile(): return oauth2_get("oauth2/user/group/join-request").either( lambda err: __render__( user_details, group_join_error=process_error(err)), - lambda gjr: __render__(usr_dets, group_join_request=gjr)) + lambda gjr: __render__(usr_dets, roles=roles, group_join_request=gjr)) return oauth2_get("oauth2/user/roles").either( lambda err: __render__(usr_dets, role_error=process_error(err)), diff --git a/wqflask/wqflask/templates/oauth2/data-list.html b/wqflask/wqflask/templates/oauth2/data-list.html new file mode 100644 index 00000000..ebe00843 --- /dev/null +++ b/wqflask/wqflask/templates/oauth2/data-list.html @@ -0,0 +1,37 @@ +{%extends "base.html"%} +{%from "oauth2/profile_nav.html" import profile_nav%} +{%from "oauth2/display_error.html" import display_error%} +{%block title%}View User{%endblock%} +{%block content%} +