Added option to leave a room, join telegram channel, fixes

This commit is contained in:
Ed 2022-12-21 20:58:54 +01:00
parent a5ac5b175f
commit cc1133e2c7
3 changed files with 37 additions and 8 deletions

28
room.py
View File

@ -142,7 +142,7 @@ async def renew_secret(request, order: Order):
return redirect('/manage/welcome') return redirect('/manage/welcome')
@bp.route("/cancel_request") @bp.route("/cancel_request")
async def renew_secret(request, order: Order): async def cancel_request(request, order: Order):
if not order: if not order:
raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") 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') return redirect('/manage/welcome')
@bp.route("/approve/<code>") @bp.route("/approve/<code>")
async def reject_roomreq(request, code, order: Order): async def approve_roomreq(request, code, order: Order):
if not order: if not order:
raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") 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() await order.send_answers()
return redirect('/manage/welcome') 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/<code>") @bp.route("/reject/<code>")
async def reject_roomreq(request, code, order: Order): async def reject_roomreq(request, code, order: Order):

View File

@ -14,7 +14,7 @@
mark {background:#0f0;} mark {background:#0f0;}
h1 img {max-height:1.4em;} h1 img {max-height:1.4em;}
.notice {padding:0.8em;border-radius:3px;background:#e53935;color:#eee;} .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;} .container {max-width:40em;padding:1em;box-sizing:border-box;}
td > a[role=button] {padding: 0.3em 0.7em;} td > a[role=button] {padding: 0.3em 0.7em;}
td {padding-left: 0.2em;padding-right: 0.2em;} td {padding-left: 0.2em;padding-right: 0.2em;}

View File

@ -4,6 +4,7 @@
<main class="container"> <main class="container">
<header> <header>
<h1>{{order.name}}'s Booking</h1> <h1>{{order.name}}'s Booking</h1>
<p class="notice" style="background:#0066AA;"> If you haven't done it yet, <a href="https://t.me/+H-vcfRyHQAxkODk8">click here to join our chat on Telegram!</a></p>
</header> </header>
<!-- Payment section --> <!-- Payment section -->
@ -99,12 +100,12 @@
{% if quota.get_left(len(room_members)) == 0 %} {% if quota.get_left(len(room_members)) == 0 %}
<p class="notice">⚠️ 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.</p> <p class="notice">⚠️ 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.</p>
{% elif room.forbidden %} {% elif room.forbidden %}
<p class="notice">⚠️ 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.</p> <p class="notice">⚠️ 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.</p>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if order.room_owner %} <p class="grid">
<p class="grid"> {% if order.room_owner %}
{% if len(room_members) == 1 and not order.room_confirmed %} {% if len(room_members) == 1 and not order.room_confirmed %}
<a href="/manage/room/delete" role="button">Delete room</a> <a href="/manage/room/delete" role="button">Delete room</a>
{% endif %} {% endif %}
@ -112,8 +113,12 @@
{% if not order.room_confirmed %} {% if not order.room_confirmed %}
<a role="button" {% if not room.forbidden and quota.get_left(len(room_members)) > 0 %}href="javascript:document.getElementById('modal-roomconfirm').setAttribute('open', 'true');"{% endif %}>Confirm <strong>{{[None,'single','double','triple','quadruple','quintuple'][len(room_members)]}}</strong> room</a> <a role="button" {% if not room.forbidden and quota.get_left(len(room_members)) > 0 %}href="javascript:document.getElementById('modal-roomconfirm').setAttribute('open', 'true');"{% endif %}>Confirm <strong>{{[None,'single','double','triple','quadruple','quintuple'][len(room_members)]}}</strong> room</a>
{% endif %} {% endif %}
</p> {% else %}
{% endif %} {% if order.room_id and not order.room_confirmed %}
<a href="/manage/room/leave" role="button">Leave room</a>
{% endif %}
{% endif %}
</p>
{# Pending roommates #} {# Pending roommates #}
{% if pending_roommates %} {% if pending_roommates %}