aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/oauth2
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-06-10 12:34:12 -0500
committerFrederick Muriuki Muriithi2024-06-10 12:34:12 -0500
commitb5da5e3ed085e07dc7367f222cc7a1beade000a6 (patch)
tree5ae9132c9ecf845c49ec0f8847f8c06234bdb424 /gn2/wqflask/oauth2
parent0baa7cf4a5eb4abb3761e868ca48030db604649b (diff)
downloadgenenetwork2-b5da5e3ed085e07dc7367f222cc7a1beade000a6.tar.gz
Implement "Resource Role Page"
Show the page, providing all UI elements necessary, even if the elements themselves are not active.
Diffstat (limited to 'gn2/wqflask/oauth2')
-rw-r--r--gn2/wqflask/oauth2/resources.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/gn2/wqflask/oauth2/resources.py b/gn2/wqflask/oauth2/resources.py
index 42fdae37..70b49375 100644
--- a/gn2/wqflask/oauth2/resources.py
+++ b/gn2/wqflask/oauth2/resources.py
@@ -296,3 +296,38 @@ def edit_resource(resource_id: uuid.UUID):
def delete_resource(resource_id: uuid.UUID):
"""Delete the given resource."""
return "WOULD DELETE THE GIVEN RESOURCE"
+
+@resources.route("/<uuid:resource_id>/role/<uuid:role_id>", methods=["GET"])
+@require_oauth2
+def view_resource_role(resource_id: uuid.UUID, role_id: uuid.UUID):
+ """View resource role page."""
+ def __render_template__(**kwargs):
+ return render_ui("oauth2/view-resource-role.html", **kwargs)
+
+ def __fetch_all_roles__(resource, role):
+ return oauth2_get(f"auth/resource/{resource_id}/roles").either(
+ lambda error: __render_template__(
+ all_roles_error=process_error(error)),
+ lambda all_roles: __render_template__(
+ resource=resource,
+ role=role,
+ unassigned_privileges=[
+ priv for role in all_roles
+ for priv in role["privileges"]
+ if priv not in role["privileges"]
+ ]))
+
+ def __fetch_resource_role__(resource):
+ return oauth2_get(
+ f"auth/resource/{resource_id}/role/{role_id}").either(
+ lambda error: __render_template__(
+ resource=resource,
+ role_id=role_id,
+ role_error=process_error(error)),
+ lambda role: __fetch_all_roles__(resource, role))
+
+ return oauth2_get(
+ f"auth/resource/view/{resource_id}").either(
+ lambda error: __render_template__(
+ resource_error=process_error(error)),
+ lambda resource: __fetch_resource_role__(resource=resource))