From cc1133e2c757c57ad4c54be5501131133e8f33be Mon Sep 17 00:00:00 2001 From: Ed Date: Wed, 21 Dec 2022 20:58:54 +0100 Subject: [PATCH] Added option to leave a room, join telegram channel, fixes --- room.py | 28 ++++++++++++++++++++++++++-- tpl/base.html | 2 +- tpl/welcome.html | 15 ++++++++++----- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/room.py b/room.py index eae950f..e5cddff 100644 --- a/room.py +++ b/room.py @@ -142,7 +142,7 @@ async def renew_secret(request, order: Order): return redirect('/manage/welcome') @bp.route("/cancel_request") -async def renew_secret(request, order: Order): +async def cancel_request(request, order: Order): if not order: raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") @@ -161,7 +161,7 @@ async def renew_secret(request, order: Order): return redirect('/manage/welcome') @bp.route("/approve/") -async def reject_roomreq(request, code, order: Order): +async def approve_roomreq(request, code, order: Order): if not order: raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") @@ -189,6 +189,30 @@ async def reject_roomreq(request, code, order: Order): await order.send_answers() return redirect('/manage/welcome') + +@bp.route("/leave") +async def leave_room(request, order: Order): + if not order: + raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") + + if not order.room_id: + raise exceptions.BadRequest("You cannot leave a room without being in it.") + + if order.room_confirmed: + raise exceptions.BadRequest("You cannot leave a confirmed room.") + + if order.room_id == order.code: + raise exceptions.BadRequest("You cannot leave your own room.") + + room_owner = await get_order(code=order.room_id, insecure=True) + + await room_owner.edit_answer('room_members', (','.join([x for x in room_owner.room_members if x != order.code]) or None)) + await order.edit_answer('room_id', None) + + await room_owner.send_answers() + await order.send_answers() + + return redirect('/manage/welcome') @bp.route("/reject/") async def reject_roomreq(request, code, order: Order): diff --git a/tpl/base.html b/tpl/base.html index 00812f9..a91c9bd 100644 --- a/tpl/base.html +++ b/tpl/base.html @@ -14,7 +14,7 @@ mark {background:#0f0;} h1 img {max-height:1.4em;} .notice {padding:0.8em;border-radius:3px;background:#e53935;color:#eee;} - .notice a {color:#eee;font-decoration:underline;} + .notice a {color:#eee;text-decoration:underline;} .container {max-width:40em;padding:1em;box-sizing:border-box;} td > a[role=button] {padding: 0.3em 0.7em;} td {padding-left: 0.2em;padding-right: 0.2em;} diff --git a/tpl/welcome.html b/tpl/welcome.html index 38eed88..e171b54 100644 --- a/tpl/welcome.html +++ b/tpl/welcome.html @@ -4,6 +4,7 @@

{{order.name}}'s Booking

+

ℹ️ If you haven't done it yet, click here to join our chat on Telegram!

@@ -99,12 +100,12 @@ {% if quota.get_left(len(room_members)) == 0 %}

⚠️ There are no more {{[None,'single','double','triple','quadruple','quintuple'][len(room_members)]}}, therefore you will not be able to confirm this room. Please add or remove people until you reach an available room.

{% elif room.forbidden %} -

⚠️ There are roommates who still didn't pay for the order, therefore you will not be able to confirm this room. Please ask them to pay or kick them out from your room.

+

⚠️ There are roommates for which a payment was not received yet, you will be able to confirm this room only once all payments are completed.

{% endif %} {% endif %} - {% if order.room_owner %} -

+

+ {% if order.room_owner %} {% if len(room_members) == 1 and not order.room_confirmed %} Delete room {% endif %} @@ -112,8 +113,12 @@ {% if not order.room_confirmed %} 0 %}href="javascript:document.getElementById('modal-roomconfirm').setAttribute('open', 'true');"{% endif %}>Confirm {{[None,'single','double','triple','quadruple','quintuple'][len(room_members)]}} room {% endif %} -

- {% endif %} + {% else %} + {% if order.room_id and not order.room_confirmed %} + Leave room + {% endif %} + {% endif %} +

{# Pending roommates #} {% if pending_roommates %}