From bcc845d44bac5866f021320cf15f0d0b2ca341c0 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 9 Feb 2023 14:01:14 +0300 Subject: oauth2: Remove create/join options with active request If a user has an active join request, then do not provide them with the option to create a new group, or even to request to join another group. --- wqflask/wqflask/oauth2/groups.py | 20 +++++++++++++++++--- .../templates/oauth2/group_join_or_create.html | 13 +++++++++++++ wqflask/wqflask/templates/oauth2/view-user.html | 9 +++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/wqflask/wqflask/oauth2/groups.py b/wqflask/wqflask/oauth2/groups.py index b49cb550..ee4e490b 100644 --- a/wqflask/wqflask/oauth2/groups.py +++ b/wqflask/wqflask/oauth2/groups.py @@ -54,9 +54,23 @@ def join_or_create(): if bool(usr_dets["group"]): flash("You are already a member of a group.", "alert-info") return redirect(url_for("oauth2.user.user_profile")) - groups = oauth2_get("oauth2/group/list").either( - lambda x: raise_unimplemented(), lambda x: x) - return render_template("oauth2/group_join_or_create.html", groups=groups) + def __group_error__(err): + return render_template( + "oauth2/group_join_or_create.html", groups=[], + groups_error=process_error(err)) + def __group_success__(groups): + return oauth2_get("oauth2/user/group/join-request").either( + __gjr_error__, partial(__gjr_success__, groups=groups)) + def __gjr_error__(err): + return render_template( + "oauth2/group_join_or_create.html", groups=[], + gjr_error=process_error(err)) + def __gjr_success__(gjr, groups): + return render_template( + "oauth2/group_join_or_create.html", groups=groups, + group_join_request=gjr) + return oauth2_get("oauth2/group/list").either( + __group_error__, __group_success__) @groups.route("/delete/", methods=["GET", "POST"]) @require_oauth2 diff --git a/wqflask/wqflask/templates/oauth2/group_join_or_create.html b/wqflask/wqflask/templates/oauth2/group_join_or_create.html index 73f7a5de..f3abc4ec 100644 --- a/wqflask/wqflask/templates/oauth2/group_join_or_create.html +++ b/wqflask/wqflask/templates/oauth2/group_join_or_create.html @@ -10,6 +10,18 @@ {{flash_me()}} + {%if group_join_request is defined %} +

+ +   + You have an active request to join a group. +

+ +

+ You cannot create a group, or request to join a new group until your + currently active request has been either accepted or rejected. +

+ {%else%}

You can

{%if groups | length > 0 %} @@ -79,5 +91,6 @@ + {%endif%} {%endblock%} diff --git a/wqflask/wqflask/templates/oauth2/view-user.html b/wqflask/wqflask/templates/oauth2/view-user.html index 72821108..7360e4d2 100644 --- a/wqflask/wqflask/templates/oauth2/view-user.html +++ b/wqflask/wqflask/templates/oauth2/view-user.html @@ -22,11 +22,20 @@ User is not a member of a group.

+ {%if group_join_request is defined %} +

+ +   + You have an active join request to a group. +

+ {%else%}

Join or Create group

+ {%endif%} + {%endif%} {%else%}

No details found.

-- cgit v1.2.3