aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/oauth2/request_utils.py6
-rw-r--r--wqflask/wqflask/oauth2/resources.py22
-rw-r--r--wqflask/wqflask/templates/oauth2/view-resource.html32
3 files changed, 59 insertions, 1 deletions
diff --git a/wqflask/wqflask/oauth2/request_utils.py b/wqflask/wqflask/oauth2/request_utils.py
index d4b2c23f..ed523614 100644
--- a/wqflask/wqflask/oauth2/request_utils.py
+++ b/wqflask/wqflask/oauth2/request_utils.py
@@ -58,3 +58,9 @@ def handle_success(
return redirect(url_for(redirect_uri, **kwargs))
return __handler__
+
+def flash_error(error):
+ flash(f"{error['error']}: {error['error_description']}", "alert-danger")
+
+def flash_success(success):
+ flash(f"{success['description']}", "alert-success")
diff --git a/wqflask/wqflask/oauth2/resources.py b/wqflask/wqflask/oauth2/resources.py
index aacde369..1bce85ef 100644
--- a/wqflask/wqflask/oauth2/resources.py
+++ b/wqflask/wqflask/oauth2/resources.py
@@ -5,7 +5,8 @@ from flask import (
from .checks import require_oauth2
from .client import oauth2_get, oauth2_post
-from .request_utils import request_error, process_error
+from .request_utils import (
+ flash_error, flash_success, request_error, process_error)
resources = Blueprint("resource", __name__)
@@ -239,6 +240,25 @@ def unassign_role(resource_id: uuid.UUID) -> Response:
flash(aserr.args[0], "alert-danger")
return redirect(url_for("oauth2.resources.view_resource", resource_id=resource_id))
+@resources.route("/toggle/<uuid:resource_id>", methods=["POST"])
+@require_oauth2
+def toggle_public(resource_id: uuid.UUID):
+ """Toggle the given resource's public status."""
+ def __handle_error__(err):
+ flash_error(process_error(err))
+ return redirect(url_for(
+ "oauth2.resource.view_resource", resource_id=resource_id))
+
+ def __handle_success__(success):
+ flash_success(success)
+ return redirect(url_for(
+ "oauth2.resource.view_resource", resource_id=resource_id))
+
+ return oauth2_post(
+ f"oauth2/resource/{resource_id}/toggle-public", data={}).either(
+ lambda err: __handle_error__(err),
+ lambda suc: __handle_success__(suc))
+
@resources.route("/edit/<uuid:resource_id>", methods=["GET"])
@require_oauth2
def edit_resource(resource_id: uuid.UUID):
diff --git a/wqflask/wqflask/templates/oauth2/view-resource.html b/wqflask/wqflask/templates/oauth2/view-resource.html
index 14e7872b..a1e49d34 100644
--- a/wqflask/wqflask/templates/oauth2/view-resource.html
+++ b/wqflask/wqflask/templates/oauth2/view-resource.html
@@ -27,6 +27,7 @@
<th>Name</th>
<th>Category</th>
<th>Group</th>
+ <th colspan="3" style="text-align: center;">Actions</th>
</tr>
</thead>
@@ -35,6 +36,37 @@
<td>{{resource.resource_name}}</td>
<td>{{resource.resource_category.resource_category_description}}</td>
<td>{{resource.group.group_name}}</td>
+ <td>
+ <form method="POST"
+ action="{{url_for(
+ 'oauth2.resource.toggle_public',
+ resource_id=resource.resource_id)}}">
+
+ <div class="input-group">
+ {%if resource.public%}
+ <input type="submit" value="Make Private"
+ class="btn btn-success" />
+ {%else%}
+ <input type="submit" value="Make Public"
+ class="btn btn-danger" />
+ {%endif%}
+ </div>
+ </form>
+ </td>
+ <td>
+ <a href="{{url_for(
+ 'oauth2.resource.edit_resource',
+ resource_id=resource.resource_id)}}"
+ title="Edit resource"
+ class="btn btn-warning">Edit</a>
+ </td>
+ <td>
+ <a href="{{url_for(
+ 'oauth2.resource.delete_resource',
+ resource_id=resource.resource_id)}}"
+ title="Edit resource"
+ class="btn btn-danger">Delete</a>
+ </td>
</tr>
</tbody>
</table>