aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-02-10 14:10:23 +0300
committerFrederick Muriuki Muriithi2023-02-10 14:10:23 +0300
commite8e5bf9e58368f9bdda0b22f23461e943ac1252a (patch)
tree220f7bf213c523bec3066da76fb10fbf9206bb68 /wqflask
parentf788d00ad05ad8f3703b81356df1e31e32e0cb3a (diff)
downloadgenenetwork2-e8e5bf9e58368f9bdda0b22f23461e943ac1252a.tar.gz
oauth2: data: Start on UI for linking data to groups.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/oauth2/data.py34
-rw-r--r--wqflask/wqflask/oauth2/routes.py2
-rw-r--r--wqflask/wqflask/oauth2/users.py5
-rw-r--r--wqflask/wqflask/templates/oauth2/data-list.html37
-rw-r--r--wqflask/wqflask/templates/oauth2/profile_nav.html11
-rw-r--r--wqflask/wqflask/templates/oauth2/view-user.html2
6 files changed, 88 insertions, 3 deletions
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%}
+<div class="container" style="min-width: 1250px;">
+ {{profile_nav("data")}}
+
+ {{flash_me()}}
+
+ <div class="container-fluid">
+ <div class="row">
+ <form method="POST" action="#/data/list/items">
+ <legend>Link Data to Group</legend>
+ <div class="form-group">
+ <label class="form-label" for="sel-group-id">Group</label>
+ <select id="sel-group-id" name="group_id" required="required"
+ {%if groups | count == 0 or groups_error is defined %}
+ disabled="disabled"
+ {%endif%}>
+ <option value="">Select Group</option>
+ {%for group in groups %}
+ <option value="{{group.group_id}}">{{group.group_name}}</option>
+ {%endfor%}
+ </select>
+ {%if groups_error is defined%}
+ {{display_error("Groups Error", groups_error)}}
+ {%endif%}
+ </div>
+
+ <input type="submit" value="Next" class="btn btn-primary" />
+ </form>
+ </div>
+ </div>
+
+</div>
+{%endblock%}
diff --git a/wqflask/wqflask/templates/oauth2/profile_nav.html b/wqflask/wqflask/templates/oauth2/profile_nav.html
index 5c69a17d..69eb1024 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)%}
+{%macro profile_nav(calling_page, user_privileges=[])%}
<ul class="nav nav-pills">
@@ -30,6 +30,15 @@
<a href="{{url_for('oauth2.resource.user_resources')}}">Resources</a>
</li>
+ {%if "system:data:link-to-group" in user_privileges %}
+ <li role="presentation"
+ {%if calling_page == "data"%}
+ class="active"
+ {%endif%}>
+ <a href="{{url_for('oauth2.data.list_data')}}">Link Data</a>
+ </li>
+ {%endif%}
+
</ul>
{%endmacro%}
diff --git a/wqflask/wqflask/templates/oauth2/view-user.html b/wqflask/wqflask/templates/oauth2/view-user.html
index 6a7d6be5..34526b14 100644
--- a/wqflask/wqflask/templates/oauth2/view-user.html
+++ b/wqflask/wqflask/templates/oauth2/view-user.html
@@ -3,7 +3,7 @@
{%block title%}View User{%endblock%}
{%block content%}
<div class="container" style="min-width: 1250px;">
- {{profile_nav("dashboard")}}
+ {{profile_nav("dashboard", user_privileges)}}
<h3>View User</h3>
{{flash_me()}}