Skip to content

Commit

Permalink
feat: add banned user status
Browse files Browse the repository at this point in the history
  • Loading branch information
ZolotarevAlexandr committed Nov 17, 2024
1 parent 9f2fadf commit ff0faca
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 53 deletions.
40 changes: 22 additions & 18 deletions locales/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-27 19:59+0300\n"
"PO-Revision-Date: 2024-10-27 19:59+0300\n"
"POT-Creation-Date: 2024-11-17 21:47+0300\n"
"PO-Revision-Date: 2024-11-17 21:48+0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
"Language-Team: en <LL@li.org>\n"
Expand Down Expand Up @@ -56,22 +56,26 @@ msgstr ""
msgid "I agree to and will abide by the stated rules."
msgstr "I agree to and will abide by the stated rules."

#: src/bot/constants.py:41
#: src/bot/constants.py:42
msgid ""
"You are banned and can't book the music room. In case you believe it's a "
"mistake, please contact: @"
msgstr ""
"You are banned and can't book the music room. In case you believe it's a "
"mistake, please contact: @"

#: src/bot/constants.py:45
msgid "Create a booking"
msgstr "Create a booking"

#: src/bot/constants.py:42
#: src/bot/constants.py:47
msgid "My bookings"
msgstr "My bookings"

#: src/bot/constants.py:43
#: src/bot/constants.py:49
msgid "Show the image with bookings"
msgstr "Show the image with bookings"

#: src/bot/dispatcher.py:16
msgid "⚡️ I don't understand you. Please, use /start command."
msgstr "⚡️ I don't understand you. Please, use /start command."

#: src/bot/menu.py:27
msgid "Instructions"
msgstr "Instructions"
Expand All @@ -84,15 +88,15 @@ msgstr "Location"
msgid "Telegram chat"
msgstr "Telegram chat"

#: src/bot/routers/admin.py:33
#: src/bot/routers/admin.py:34
msgid "You are the Lord of the Music Room! You can use the following commands:"
msgstr "You are the Lord of the Music Room! You can use the following commands:"

#: src/bot/routers/admin.py:51
#: src/bot/routers/admin.py:52
msgid "Here is the list of users."
msgstr "Here is the list of users."

#: src/bot/routers/admin.py:53
#: src/bot/routers/admin.py:54
msgid "Failed to export users."
msgstr "Failed to export users."

Expand Down Expand Up @@ -156,31 +160,31 @@ msgstr "You haven't confirmed the rules. Please, try again."
msgid "Next week"
msgstr "Next week"

#: src/bot/routers/schedule.py:43 src/bot/routers/schedule.py:74
#: src/bot/routers/schedule.py:45 src/bot/routers/schedule.py:76
msgid "Sending image for the current week..."
msgstr "Sending image for the current week..."

#: src/bot/routers/schedule.py:47
#: src/bot/routers/schedule.py:49
msgid "Do you want to see bookings for the next week?"
msgstr "Do you want to see bookings for the next week?"

#: src/bot/routers/schedule.py:76
#: src/bot/routers/schedule.py:78
msgid "Sending image for the next week..."
msgstr "Sending image for the next week..."

#: src/bot/routers/start_help_menu.py:29
msgid "Choose the action you're interested in."
msgstr "Choose the action you're interested in."

#: src/bot/routers/booking/create_booking_routes.py:48
#: src/bot/routers/booking/create_booking_routes.py:56
msgid "You must choose both start and end time"
msgstr "You must choose both start and end time"

#: src/bot/routers/booking/create_booking_routes.py:56
#: src/bot/routers/booking/create_booking_routes.py:64
msgid "You have successfully booked on <b>{date}, {timeslot}</b>."
msgstr "You have successfully booked on <b>{date}, {timeslot}</b>."

#: src/bot/routers/booking/create_booking_routes.py:60
#: src/bot/routers/booking/create_booking_routes.py:70
msgid "Error occurred: {error}"
msgstr "Error occurred: {error}"

Expand Down
36 changes: 19 additions & 17 deletions locales/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-27 19:59+0300\n"
"POT-Creation-Date: 2024-11-17 21:47+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -40,22 +40,24 @@ msgstr ""
msgid "I agree to and will abide by the stated rules."
msgstr ""

#: src/bot/constants.py:41
#: src/bot/constants.py:42
msgid ""
"You are banned and can't book the music room. In case you believe it's a "
"mistake, please contact: @"
msgstr ""

#: src/bot/constants.py:45
msgid "Create a booking"
msgstr ""

#: src/bot/constants.py:42
#: src/bot/constants.py:47
msgid "My bookings"
msgstr ""

#: src/bot/constants.py:43
#: src/bot/constants.py:49
msgid "Show the image with bookings"
msgstr ""

#: src/bot/dispatcher.py:16
msgid "⚡️ I don't understand you. Please, use /start command."
msgstr ""

#: src/bot/menu.py:27
msgid "Instructions"
msgstr ""
Expand All @@ -68,15 +70,15 @@ msgstr ""
msgid "Telegram chat"
msgstr ""

#: src/bot/routers/admin.py:33
#: src/bot/routers/admin.py:34
msgid "You are the Lord of the Music Room! You can use the following commands:"
msgstr ""

#: src/bot/routers/admin.py:51
#: src/bot/routers/admin.py:52
msgid "Here is the list of users."
msgstr ""

#: src/bot/routers/admin.py:53
#: src/bot/routers/admin.py:54
msgid "Failed to export users."
msgstr ""

Expand Down Expand Up @@ -132,31 +134,31 @@ msgstr ""
msgid "Next week"
msgstr ""

#: src/bot/routers/schedule.py:43 src/bot/routers/schedule.py:74
#: src/bot/routers/schedule.py:45 src/bot/routers/schedule.py:76
msgid "Sending image for the current week..."
msgstr ""

#: src/bot/routers/schedule.py:47
#: src/bot/routers/schedule.py:49
msgid "Do you want to see bookings for the next week?"
msgstr ""

#: src/bot/routers/schedule.py:76
#: src/bot/routers/schedule.py:78
msgid "Sending image for the next week..."
msgstr ""

#: src/bot/routers/start_help_menu.py:29
msgid "Choose the action you're interested in."
msgstr ""

#: src/bot/routers/booking/create_booking_routes.py:48
#: src/bot/routers/booking/create_booking_routes.py:56
msgid "You must choose both start and end time"
msgstr ""

#: src/bot/routers/booking/create_booking_routes.py:56
#: src/bot/routers/booking/create_booking_routes.py:64
msgid "You have successfully booked on <b>{date}, {timeslot}</b>."
msgstr ""

#: src/bot/routers/booking/create_booking_routes.py:60
#: src/bot/routers/booking/create_booking_routes.py:70
msgid "Error occurred: {error}"
msgstr ""

Expand Down
40 changes: 22 additions & 18 deletions locales/ru/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-26 20:57+0300\n"
"PO-Revision-Date: 2024-10-26 20:59+0300\n"
"POT-Creation-Date: 2024-11-17 21:47+0300\n"
"PO-Revision-Date: 2024-11-17 21:48+0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ru\n"
"Language-Team: ru <LL@li.org>\n"
Expand Down Expand Up @@ -56,22 +56,26 @@ msgstr ""
msgid "I agree to and will abide by the stated rules."
msgstr "Я согласен, и буду соблюдать правила"

#: src/bot/constants.py:41
#: src/bot/constants.py:42
msgid ""
"You are banned and can't book the music room. In case you believe it's a "
"mistake, please contact: @"
msgstr ""
"Вы заблокированы и не можете бронировать комнату. Если вы уверены, что это "
"ошибка, пожалуйста, обратитесь к: @"

#: src/bot/constants.py:45
msgid "Create a booking"
msgstr "Забронировать"

#: src/bot/constants.py:42
#: src/bot/constants.py:47
msgid "My bookings"
msgstr "Мои бронирования"

#: src/bot/constants.py:43
#: src/bot/constants.py:49
msgid "Show the image with bookings"
msgstr "Показать изображение с бронированиями"

#: src/bot/dispatcher.py:16
msgid "⚡️ I don't understand you. Please, use /start command."
msgstr "⚡️ Я не понимаю вас. Пожалуйста используйте команду /start"

#: src/bot/menu.py:27
msgid "Instructions"
msgstr "Инструкции"
Expand All @@ -84,15 +88,15 @@ msgstr "Местоположение"
msgid "Telegram chat"
msgstr "Telegram чат"

#: src/bot/routers/admin.py:33
#: src/bot/routers/admin.py:34
msgid "You are the Lord of the Music Room! You can use the following commands:"
msgstr "Вы Лорд музыкальной комнаты! Вы можете использовать следующие команды:"

#: src/bot/routers/admin.py:51
#: src/bot/routers/admin.py:52
msgid "Here is the list of users."
msgstr "Вот список пользователей."

#: src/bot/routers/admin.py:53
#: src/bot/routers/admin.py:54
msgid "Failed to export users."
msgstr "Не удалось экспортировать список пользователей"

Expand Down Expand Up @@ -152,31 +156,31 @@ msgstr "Вы не подтвердили согласие с правилами.
msgid "Next week"
msgstr "Следующая неделя"

#: src/bot/routers/schedule.py:43 src/bot/routers/schedule.py:74
#: src/bot/routers/schedule.py:45 src/bot/routers/schedule.py:76
msgid "Sending image for the current week..."
msgstr "Отправляю изображение для этой недели..."

#: src/bot/routers/schedule.py:47
#: src/bot/routers/schedule.py:49
msgid "Do you want to see bookings for the next week?"
msgstr "Вы хотите увидеть бронирования на следующей неделе?"

#: src/bot/routers/schedule.py:76
#: src/bot/routers/schedule.py:78
msgid "Sending image for the next week..."
msgstr "Отправляю изображение для следующей недели..."

#: src/bot/routers/start_help_menu.py:29
msgid "Choose the action you're interested in."
msgstr "Выберите действие"

#: src/bot/routers/booking/create_booking_routes.py:47
#: src/bot/routers/booking/create_booking_routes.py:56
msgid "You must choose both start and end time"
msgstr "Вы должны выбрать время начала и окончания бронирования"

#: src/bot/routers/booking/create_booking_routes.py:55
#: src/bot/routers/booking/create_booking_routes.py:64
msgid "You have successfully booked on <b>{date}, {timeslot}</b>."
msgstr "Вы успешно забронировали комнату на <b>{date}, {timeslot}</b>."

#: src/bot/routers/booking/create_booking_routes.py:59
#: src/bot/routers/booking/create_booking_routes.py:70
msgid "Error occurred: {error}"
msgstr "Возникла ошибка: {error}"

Expand Down
1 change: 1 addition & 0 deletions src/api/users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def get_list_of_all_users(verified: VerifiedDep, as_bot: bool = False):
raise ForbiddenException()

users = await user_repository.get_all_users()
users = list(filter(lambda u: u.status != UserStatus.BANNED, users))
users.sort(key=lambda x: x.name or "")

document: Document = create_docx()
Expand Down
5 changes: 5 additions & 0 deletions src/bot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
)
rules_confirmation_message = __("""I agree to and will abide by the stated rules.""")

# TODO: Specify contact information or change message
ban_message = __(
"You are banned and can't book the music room. In case you believe it's a mistake, " "please contact: @"
)

create_booking_message = __("Create a booking")
create_booking_message_en = "Create a booking"
my_bookings_message = __("My bookings")
Expand Down
6 changes: 6 additions & 0 deletions src/bot/routers/booking/create_booking_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@

from src.bot import constants
from src.bot.api import api_client
from src.bot.constants import ban_message
from src.bot.i18n import I18NFormat
from src.bot.routers.booking import router
from src.bot.routers.booking.states import CreateBookingStates
from src.bot.routers.booking.widgets.calendar import CustomCalendar
from src.bot.routers.booking.widgets.time_range import TimeRangeWidget
from src.schemas import UserStatus


@router.message(any_state, Command("create_booking"))
@router.message(
any_state, (F.text == constants.create_booking_message) | (F.text == constants.create_booking_message_en)
)
async def start_booking(_message: Message, dialog_manager: DialogManager):
user = await api_client.get_me(_message.from_user.id)
if user.status == UserStatus.BANNED:
await _message.answer(str(ban_message))
return
await dialog_manager.start(
CreateBookingStates.choose_date,
mode=StartMode.NEW_STACK,
Expand Down
5 changes: 5 additions & 0 deletions src/schemas/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@


class UserStatus(StrEnum):
BANNED = "banned"
FREE = "free"
MIDDLE = "middle"
SENIOR = "senior"
LORD = "lord"

def max_hours_to_book_per_day(self) -> int | None:
if self == UserStatus.BANNED:
return 0
if self == UserStatus.FREE:
return 2
elif self == UserStatus.MIDDLE:
Expand All @@ -21,6 +24,8 @@ def max_hours_to_book_per_day(self) -> int | None:
return None

def max_hours_to_book_per_week(self) -> int | None:
if self == UserStatus.BANNED:
return 0
if self == UserStatus.FREE:
return 4
elif self == UserStatus.MIDDLE:
Expand Down

0 comments on commit ff0faca

Please sign in to comment.