aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-03-06 10:16:35 +0300
committerFrederick Muriuki Muriithi2023-03-06 10:16:35 +0300
commit52956c15c9c7dcb631b55f75d77786b52d4f631b (patch)
tree518790fe972b2ac29d14915295d92b204fa1d18d
parent530822468be436f1da0024a4b0dd85e0a2f69b7f (diff)
downloadgenenetwork2-52956c15c9c7dcb631b55f75d77786b52d4f631b.tar.gz
oauth2: resources: List all users with access to the resource.
-rw-r--r--wqflask/wqflask/oauth2/resources.py33
-rw-r--r--wqflask/wqflask/templates/oauth2/view-resource.html73
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 @@
<div class="container-fluid">
<div class="row">
+ <h3>Resource Details</h3>
{%if error %}
<span class="glyphicon glyphicon-exclamation-sign text-danger">
</span>
@@ -41,6 +42,7 @@
</div>
<div class="row">
+ <h3>Resource Data</h3>
<table class="table">
<caption>Resource Data</caption>
<thead>
@@ -88,6 +90,7 @@
</div>
<div class="row">
+ <h3>Unlinked Data</h3>
<table class="table">
<caption>Link Data</caption>
<thead>
@@ -125,7 +128,7 @@
</td>
</tr>
{%else%}
- <span class="glyphicon glyphicon-info-sign text-danger">
+ <span class="glyphicon glyphicon-info-sign text-info">
</span>
&nbsp;
<strong class="text-info">No data to link.</strong>
@@ -135,6 +138,74 @@
</table>
</div>
+ <div class="row">
+ <h3>User Roles</h3>
+ {%if users_n_roles_error is defined%}
+ {{display_error("Users and Roles", users_n_roles_error)}}
+ {%else%}
+ <table class="table">
+ <caption>User Roles</caption>
+ <thead>
+ <tr>
+ <th>User Email</th>
+ <th>User Name</th>
+ <th>User Group</th>
+ <th colspan="2">Assigned Roles</th>
+ </tr>
+ </thead>
+ <tbody>
+ {%for user_row in users_n_roles%}
+ <tr>
+ <td rowspan="{{user_row.roles | length + 1}}">{{user_row.user.email}}</td>
+ <td rowspan="{{user_row.roles | length + 1}}">{{user_row.user.name}}</td>
+ <td rowspan="{{user_row.roles | length + 1}}">
+ {{user_row.user_group.group_name}}</td>
+ <th>Role</th>
+ <th>Action</th>
+ </tr>
+ {%for grole in user_row.roles%}
+ <tr>
+ <td>
+ <a href="{{url_for(
+ 'oauth2.group.group_role',
+ group_role_id=grole.group_role_id)}}"
+ title="Details for '{{grole.role.role_name}}' role">
+ {{grole.role.role_name}}
+ </a>
+ </td>
+ <td>
+ <form action="#/role/id/unassign/user" action="POST">
+ <input type="hidden" name="user_id"
+ value="{{user_row.user.user_id}}" />
+ <input type="hidden" name="group_role_id"
+ value="{{grole.group_role_id}}">
+ <input type="submit"
+ value="Unassign"
+ class="btn btn-danger"
+ {%if user_row.user.user_id==this_user.user_id%}
+ disabled="disabled"
+ {%endif%}>
+ </form>
+ </td>
+ </tr>
+ {%endfor%}
+ {%else%}
+ <tr>
+ <td colspan="5">
+ <span class="glyphicon glyphicon-info-sign text-info">
+ </span>
+ &nbsp;
+ <span class="text-info">
+ There are no users assigned any role for this resource.
+ </span>
+ </td>
+ </tr>
+ {%endfor%}
+ </tbody>
+ </table>
+ {%endif%}
+ </div>
+
</div>
</div>