aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/oauth2/groups.py12
-rw-r--r--wqflask/wqflask/oauth2/request_utils.py14
-rw-r--r--wqflask/wqflask/oauth2/resources.py31
-rw-r--r--wqflask/wqflask/templates/oauth2/create-resource.html62
-rw-r--r--wqflask/wqflask/templates/oauth2/group.html2
-rw-r--r--wqflask/wqflask/templates/oauth2/resources.html45
6 files changed, 138 insertions, 28 deletions
diff --git a/wqflask/wqflask/oauth2/groups.py b/wqflask/wqflask/oauth2/groups.py
index 4d0bc4f5..f91a872b 100644
--- a/wqflask/wqflask/oauth2/groups.py
+++ b/wqflask/wqflask/oauth2/groups.py
@@ -4,7 +4,7 @@ from flask import (
from .checks import require_oauth2
from .client import oauth2_get, oauth2_post
from .request_utils import (
- user_details, handle_error, request_error, handle_success,
+ user_details, handle_error, request_error, process_error, handle_success,
raise_unimplemented)
groups = Blueprint("group", __name__)
@@ -12,20 +12,12 @@ groups = Blueprint("group", __name__)
@groups.route("/", methods=["GET"])
def user_group():
"""Get the user's group."""
- def __process_error__(error):
- if error.status_code == 404:
- return {
- "error": "NotFoundError",
- "error_message": ("Requested endpoint was not found on the "
- "API server.")
- }
- return error.json()
def __success__(group):
return oauth2_get(f"oauth2/group/members/{group['group_id']}").either(
lambda error: render_template(
"oauth2/group.html", group=group,
- user_error=__process_error__(error)),
+ user_error=process_error(error)),
lambda users: render_template(
"oauth2/group.html", group=group, users=users))
diff --git a/wqflask/wqflask/oauth2/request_utils.py b/wqflask/wqflask/oauth2/request_utils.py
index f471d133..aa073266 100644
--- a/wqflask/wqflask/oauth2/request_utils.py
+++ b/wqflask/wqflask/oauth2/request_utils.py
@@ -2,7 +2,8 @@
from typing import Optional
from flask import (
- flash, session, url_for, redirect, render_template, current_app as app)
+ flash, session, url_for, redirect, Response, render_template,
+ current_app as app)
from .client import oauth2_get
@@ -14,6 +15,17 @@ def user_details():
handle_error("oauth2.login"),
lambda usr_dets: usr_dets)
+def process_error(error: Response,
+ message: str=("Requested endpoint was not found on the API "
+ "server.")
+ ) -> dict:
+ if error.status_code == 404:
+ return {
+ "error": "NotFoundError",
+ "error_message": message
+ }
+ return error.json()
+
def request_error(response):
app.logger.error(f"{response}: {response.url} [{response.status_code}]")
return render_template("oauth2/request_error.html", response=response)
diff --git a/wqflask/wqflask/oauth2/resources.py b/wqflask/wqflask/oauth2/resources.py
index be3e1622..28a5a362 100644
--- a/wqflask/wqflask/oauth2/resources.py
+++ b/wqflask/wqflask/oauth2/resources.py
@@ -1,10 +1,10 @@
import uuid
-from flask import Blueprint, render_template
+from flask import request, Blueprint, render_template
-from .client import oauth2_get
from .checks import require_oauth2
-from .request_utils import request_error
+from .client import oauth2_get, oauth2_post
+from .request_utils import request_error, process_error
resources = Blueprint("resource", __name__)
@@ -18,11 +18,32 @@ def user_resources():
return oauth2_get("oauth2/user/resources").either(
request_error, __success__)
-@resources.route("/create", methods=["GET"])
+@resources.route("/create", methods=["GET", "POST"])
@require_oauth2
def create_resource():
"""Create a new resource."""
- return "WOULD CREATE A NEW RESOURCE."
+ def __render_template__(categories=[], error=None):
+ return render_template(
+ "oauth2/create-resource.html",
+ resource_categories=categories,
+ resource_category_error=error)
+
+ if request.method == "GET":
+ return oauth2_get("oauth2/resource/categories").either(
+ lambda error: __render_template__(error=process_error(
+ error, "Could not retrieve resource categories")),
+ lambda cats: __render_template__(categories=cats))
+
+ from flask import jsonify
+ def __perr__(error):
+ print(f"ERROR: {process_error(error)}")
+ return jsonify(process_error(error))
+ def __psuc__(succ):
+ print(f"SUCCESS: {succ.json()}")
+ return jsonify(succ.json())
+ return oauth2_post(
+ "oauth2/resource/create", data=request.form).either(
+ __perr__, __psuc__)
@resources.route("/view/<uuid:resource_id>", methods=["GET"])
@require_oauth2
diff --git a/wqflask/wqflask/templates/oauth2/create-resource.html b/wqflask/wqflask/templates/oauth2/create-resource.html
new file mode 100644
index 00000000..9d9a8cd3
--- /dev/null
+++ b/wqflask/wqflask/templates/oauth2/create-resource.html
@@ -0,0 +1,62 @@
+{%extends "base.html"%}
+{%from "oauth2/profile_nav.html" import profile_nav%}
+
+{%block title%}Create Resource{%endblock%}
+{%block css%}
+<link rel="stylesheet" type="text/css" href="/static/new/css/mytooltip.css" />
+{%endblock%}
+
+{%block content%}
+<div class="container" style="min-width: 1250px;">
+ {{profile_nav("resources")}}
+
+ {{flash_me()}}
+
+ <div class="container-fluid">
+ <div class="row">
+ {%if resource_category_error%}
+ <p>
+ <span class="glyphicon glyphicon-exclamation-sign text-danger"></span>
+ &nbsp;
+ <span class="text-danger">{{resource_category_error.error}}</span>:
+ {{resource_category_error.error_message}}
+ </p>
+ {%else%}
+ <form method="POST"
+ action="{{url_for('oauth2.resource.create_resource')}}">
+
+ <div class="form-group mytooltip">
+ <label for="resource_name" class="form-label">Name</label>
+ <input type="text" name="resource_name" class="form-control"
+ required="required" />
+ <span class="mytooltiptext">
+ The resource name, e.g. the experiment name.
+ </span>
+ </div>
+
+
+ <div class="form-group">
+ {%for category in resource_categories%}
+ <div class="radio mytooltip">
+ <label for="resource_name" class="form-label"
+ style="text-transform: capitalize;">
+ <input type="radio" name="resource_category" required="required"
+ value="{{category.resource_category_id}}" />
+ {{category.resource_category_key}}
+ </label>
+ <span class="mytooltiptext">
+ {{category.resource_category_description}}
+ </span>
+ </div>
+ {%endfor%}
+ </div>
+
+ <input class="btn btn-primary" type="submit" value="Create" />
+
+ </form>
+ {%endif%}
+ </div>
+ </div>
+
+</div>
+{%endblock%}
diff --git a/wqflask/wqflask/templates/oauth2/group.html b/wqflask/wqflask/templates/oauth2/group.html
index 8db5b0d9..e7a79933 100644
--- a/wqflask/wqflask/templates/oauth2/group.html
+++ b/wqflask/wqflask/templates/oauth2/group.html
@@ -81,7 +81,7 @@
</span>
&nbsp;
<strong class="text-danger">{{user_error.error}}</strong>
- {{user_error.error_message}}
+ {{user_error.error_description}}
{%else%}
No users found for this group
{%endif%}
diff --git a/wqflask/wqflask/templates/oauth2/resources.html b/wqflask/wqflask/templates/oauth2/resources.html
index 44774fda..19730f6b 100644
--- a/wqflask/wqflask/templates/oauth2/resources.html
+++ b/wqflask/wqflask/templates/oauth2/resources.html
@@ -3,7 +3,7 @@
{%block title%}View User{%endblock%}
{%block content%}
<div class="container" style="min-width: 1250px;">
- {{profile_nav("dashboard")}}
+ {{profile_nav("resources")}}
<h3>Resources</h3>
{{flash_me()}}
@@ -17,16 +17,39 @@
</div>
<div class="row">
- {%for resource in resources %}
- {{resource.resource_name}} - {{resource.resource_category}} - {{resource.group}}
- {%else%}
- <p>
- <span class="glyphicon glyphicon-warning-sign"></span>&nbsp;
- <span class="text-warning">
- The user has no access to any resource.
- </span>
- </p>
- {%endfor%}
+ <table class="table">
+ <caption>Resources</caption>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Category</th>
+ <th>Group</th>
+ </tr>
+ </thead>
+ <tbody>
+ {%for resource in resources %}
+ <tr>
+ <td>
+ <a href="url_for('oauth2.resources.view', resource_id=resource.resource_id)"
+ title="View resource {{resource.resource_name}}">
+ {{resource.resource_name}}
+ </a>
+ </td>
+ <td>{{resource.resource_category.resource_category_key}}</td>
+ <td>{{resource.group.group_name}}</td>
+ </tr>
+ {%else%}
+ <tr>
+ <td colspan="3">
+ <span class="glyphicon glyphicon-warning-sign"></span>&nbsp;
+ <span class="text-warning">
+ The user has no access to any resource.
+ </span>
+ </td>
+ </tr>
+ {%endfor%}
+ </tbody>
+ </table>
</div>
</div>