From c7675b5e28135f2fdd1f6a2f8347cc0050345590 Mon Sep 17 00:00:00 2001 From: Stranck Date: Mon, 20 May 2024 12:29:45 +0200 Subject: [PATCH] Added room deadline --- app.py | 1 + config.example.py | 2 ++ room.py | 11 ++++++++++- tpl/blocks/room.html | 26 +++++++++++++------------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index b8d719f..ee099b3 100644 --- a/app.py +++ b/app.py @@ -82,6 +82,7 @@ async def main_start(*_): app.ctx.tpl = Environment(loader=FileSystemLoader("tpl"), autoescape=True) app.ctx.tpl.globals.update(time=time) app.ctx.tpl.globals.update(PROPIC_DEADLINE=PROPIC_DEADLINE) + app.ctx.tpl.globals.update(ROOM_DEADLINE=ROOM_DEADLINE) app.ctx.tpl.globals.update(LOCALES=LOCALES) app.ctx.tpl.globals.update(ITEMS_ID_MAP=ITEMS_ID_MAP) app.ctx.tpl.globals.update(ITEM_VARIATIONS_MAP=ITEM_VARIATIONS_MAP) diff --git a/config.example.py b/config.example.py index 247ebec..8a6427c 100644 --- a/config.example.py +++ b/config.example.py @@ -17,6 +17,8 @@ PROPIC_MAX_FILE_SIZE = 5 * 1024 * 1024 # 5MB PROPIC_MAX_SIZE = (2048, 2048) # (Width, Height) PROPIC_MIN_SIZE = (125, 125) # (Width, Height) +ROOM_DEADLINE = 9999999999 + # This is used for feedback sending inside of the app. Feedbacks will be sent to the specified chat using the bot api id. TG_BOT_API = '123456789:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' TG_CHAT_ID = -1234567 diff --git a/room.py b/room.py index a0f41c2..2fa7024 100644 --- a/room.py +++ b/room.py @@ -6,9 +6,18 @@ from config import headers import os from image_util import generate_room_preview, get_room from utils import confirm_room_by_order +from time import time bp = Blueprint("room", url_prefix="/manage/room") +@bp.middleware +async def deadline_check(request: Request): + order = await get_order(request) + if not order: + raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") + if time() > ROOM_DEADLINE and not await isSessionAdmin(request, order): + raise exceptions.BadRequest("The deadline has passed. You cannot modify the room at this moment.") + @bp.post("/create") async def room_create_post(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!") @@ -304,7 +313,7 @@ async def confirm_room(request, order: Order, quotas: Quotas): #if quotas.get_left(len(order.room_members)) == 0: # raise exceptions.BadRequest("There are no more rooms of this size to reserve.") - confirm_room_by_order(order, request) + await confirm_room_by_order(order, request) return redirect('/manage/welcome') diff --git a/tpl/blocks/room.html b/tpl/blocks/room.html index 4fca1dd..521747b 100644 --- a/tpl/blocks/room.html +++ b/tpl/blocks/room.html @@ -40,7 +40,7 @@ {% if person.status == 'pending' %}

UNPAID

{% endif %} - {% if order.room_owner and person.code != order.code and (not order.room_confirmed) %}KICK{% endif %} + {% if order.room_owner and person.code != order.code and (not order.room_confirmed) and (time() <= ROOM_DEADLINE or isSessionAdmin) %}KICK{% endif %} {% if person.status != 'paid' %} @@ -51,7 +51,7 @@ {# {% if order.room_id == order.code and not order.room_confirmed and len(room_members) < 5%} #} {% if order.room_id == order.code and not order.room_confirmed and len(room_members) < order.room_person_no %}
- +

Invite

@@ -63,13 +63,13 @@
{% elif order.pending_room %}

You have have asked to join the room of another member. Wait for them to confirm or reject your request.

-
Cancel pending join request + ROOM_DEADLINE and not isSessionAdmin else ''}}>Cancel pending join request {% else %}

🎲 If you don't join a room or create your one within the room deadline, we will randomly put you into a room with free spots.

To join a room, ask somebody to send you their room code.

- Create a room - Join a room + ROOM_DEADLINE and not isSessionAdmin else ''}}>Create a room + ROOM_DEADLINE and not isSessionAdmin else ''}}>Join a room

{% endif %} @@ -83,17 +83,17 @@ {% if order.room_owner %} {% 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 #} + {# ROOM_DEADLINE and not isSessionAdmin else ''}} {% if not room.forbidden and quota.get_left(len(room_members)) > 0 %}href="javascript:document.getElementById('modal-roomconfirm').setAttribute('open', 'true');"{% endif %}>Confirm {{[None,'single','double','triple','quadruple','quintuple'][len(room_members)]}} room #} - Rename room - 1) else ''}} >Delete room - Confirm {{[None,'single','double','triple','quadruple','quintuple'][order.room_person_no]}} room + ROOM_DEADLINE and not isSessionAdmin else ''}}>Rename room + 1) or (time() > ROOM_DEADLINE and not isSessionAdmin) else ''}} >Delete room + ROOM_DEADLINE and not isSessionAdmin else ''}} {% if not room.forbidden and len(room_members) == order.room_person_no %}href="javascript:document.getElementById('modal-roomconfirm').setAttribute('open', 'true');"{% endif %}>Confirm {{[None,'single','double','triple','quadruple','quintuple'][order.room_person_no]}} room {% else %} - {# Share #} + {# ROOM_DEADLINE and not isSessionAdmin else ''}} href="javascript:navigator.share({title: 'Furizon room', text:'Viewing room {{order.room_name}}', url: `${window.location.protocol}//${window.location.host}/manage/room/view/{{order.code}}}`});">Share #} {% endif %} {% else %} {% if order.room_id and not order.room_confirmed %} - Leave room + ROOM_DEADLINE and not isSessionAdmin else ''}}>Leave room {% endif %} {% endif %}

@@ -111,8 +111,8 @@ UNPAID {% endif %} {% if order.room_owner %} - Approve - Reject + ROOM_DEADLINE and not isSessionAdmin else ''}}>Approve + ROOM_DEADLINE and not isSessionAdmin else ''}}>Reject {% endif %}