From 52956c15c9c7dcb631b55f75d77786b52d4f631b Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 6 Mar 2023 10:16:35 +0300 Subject: oauth2: resources: List all users with access to the resource. --- wqflask/wqflask/oauth2/resources.py | 33 ++++++++-- .../wqflask/templates/oauth2/view-resource.html | 73 +++++++++++++++++++++- 2 files changed, 99 insertions(+), 7 deletions(-) diff --git a/wqflask/wqflask/oauth2/resources.py b/wqflask/wqflask/oauth2/resources.py index 872a29c6..be0cb475 100644 --- a/wqflask/wqflask/oauth2/resources.py +++ b/wqflask/wqflask/oauth2/resources.py @@ -51,18 +51,39 @@ def create_resource(): @require_oauth2 def view_resource(resource_id: uuid.UUID): """View the given resource.""" - # Display the resource's details - # Provide edit/delete options - # Metadata edit maybe? + def __this_user_success__(resource, unlinked_data, users_n_roles, user): + return render_template( + "oauth2/view-resource.html", resource=resource, + unlinked_data=unlinked_data, users_n_roles=users_n_roles, + this_user=user) + + def __users_n_roles_success__(resource, unlinked_data, users_n_roles): + return oauth2_get("oauth2/user").either( + lambda err: render_template( + "oauth2/view-resources.html", + this_user_error=process_error(err)), + lambda usr_dets: __this_user_success__( + resource, unlinked_data, users_n_roles, usr_dets)) + + def __unlinked_success__(resource, unlinked_data): + return oauth2_get(f"oauth2/resource/{resource_id}/users").either( + lambda err: render_template( + "oauth2/view-resource.html", resource=resource, + unlinked_data=unlinked_data, + users_n_roles_error=process_error(err)), + lambda users_n_roles: __users_n_roles_success__( + resource, unlinked_data, users_n_roles)) + return render_template( + "oauth2/view-resource.html", resource=resource, error=None, + unlinked_data=unlinked) + def __resource_success__(resource): dataset_type = resource["resource_category"]["resource_category_key"] return oauth2_get(f"oauth2/group/{dataset_type}/unlinked-data").either( lambda err: render_template( "oauth2/view-resource.html", resource=resource, unlinked_error=process_error(err)), - lambda unlinked: render_template( - "oauth2/view-resource.html", resource=resource, error=None, - unlinked_data=unlinked)) + lambda unlinked: __unlinked_success__(resource, unlinked)) return oauth2_get(f"oauth2/resource/view/{resource_id}").either( lambda err: render_template("oauth2/view-resource.html", diff --git a/wqflask/wqflask/templates/oauth2/view-resource.html b/wqflask/wqflask/templates/oauth2/view-resource.html index fb44560b..e8a3d8cb 100644 --- a/wqflask/wqflask/templates/oauth2/view-resource.html +++ b/wqflask/wqflask/templates/oauth2/view-resource.html @@ -12,6 +12,7 @@
+

Resource Details

{%if error %} @@ -41,6 +42,7 @@
+

Resource Data

@@ -88,6 +90,7 @@
+

Unlinked Data

Resource Data
@@ -125,7 +128,7 @@ {%else%} - +   No data to link. @@ -135,6 +138,74 @@
Link Data
+
+

User Roles

+ {%if users_n_roles_error is defined%} + {{display_error("Users and Roles", users_n_roles_error)}} + {%else%} + + + + + + + + + + + + {%for user_row in users_n_roles%} + + + + + + + + {%for grole in user_row.roles%} + + + + + {%endfor%} + {%else%} + + + + {%endfor%} + +
User Roles
User EmailUser NameUser GroupAssigned Roles
{{user_row.user.email}}{{user_row.user.name}} + {{user_row.user_group.group_name}}RoleAction
+ + {{grole.role.role_name}} + + +
+ + + +
+
+ + +   + + There are no users assigned any role for this resource. + +
+ {%endif%} +
+
-- cgit v1.2.3