aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-02-07 13:02:07 +0300
committerFrederick Muriuki Muriithi2023-02-07 13:02:07 +0300
commit63474180915d3d39d5d649dd2eef8d5fa54773c4 (patch)
tree2fe0ccc357d20486336a9351aff9bd000ccb2e5b
parentc236eded0a4316a7a3e61d4af9b745860d70e2d2 (diff)
downloadgenenetwork2-63474180915d3d39d5d649dd2eef8d5fa54773c4.tar.gz
oauth2: groups: Enable user to request to be added to group.
-rw-r--r--wqflask/wqflask/oauth2/users.py26
-rw-r--r--wqflask/wqflask/templates/oauth2/group_join_or_create.html2
2 files changed, 22 insertions, 6 deletions
diff --git a/wqflask/wqflask/oauth2/users.py b/wqflask/wqflask/oauth2/users.py
index 4b267c9f..67d6b27f 100644
--- a/wqflask/wqflask/oauth2/users.py
+++ b/wqflask/wqflask/oauth2/users.py
@@ -1,8 +1,9 @@
-from flask import Blueprint, render_template
+from flask import (
+ flash, request, url_for, redirect, Response, Blueprint, render_template)
from .checks import require_oauth2
-from .client import oauth2_get, oauth2_client
-from .request_utils import user_details, request_error
+from .client import oauth2_get, oauth2_post, oauth2_client
+from .request_utils import user_details, request_error, process_error
users = Blueprint("user", __name__)
@@ -19,5 +20,20 @@ def user_profile():
@users.route("/request-add-to-group", methods=["POST"])
@require_oauth2
-def request_add_to_group():
- return "WOULD SEND MESSAGE TO HAVE YOU ADDED TO GROUP..."
+def request_add_to_group() -> Response:
+ """Request to be added to a group."""
+ form = request.form
+ group_id = form["group"]
+
+ def __error__(error):
+ err = process_error(error)
+ flash(f"{err['error']}: {err['error_message']}", "alert-danger")
+ return redirect(url_for("oauth2.user.user_profile"))
+
+ def __success__(response):
+ flash(f"{response['message']} (Response ID: {response['request_id']})",
+ "alert-success")
+ return redirect(url_for("oauth2.user.user_profile"))
+
+ return oauth2_post(f"oauth2/group/requests/join/{group_id}",
+ data=form).either(__error__, __success__)
diff --git a/wqflask/wqflask/templates/oauth2/group_join_or_create.html b/wqflask/wqflask/templates/oauth2/group_join_or_create.html
index 0ec5674b..73f7a5de 100644
--- a/wqflask/wqflask/templates/oauth2/group_join_or_create.html
+++ b/wqflask/wqflask/templates/oauth2/group_join_or_create.html
@@ -27,7 +27,7 @@
<legend>Request to be added to group</legend>
<div class="form-group">
<label class="control-label" for="group">Group</label>
- <select class="form-control" id="group" required="required">
+ <select class="form-control" id="group" required="required" name="group">
<option value="">Select a group</option>
{%for group in groups%}
<option value="{{group.group_id}}">{{group.group_name}}</option>