def get_room_admins(room_id: int) -> Tuple[AdminInfo, ...]: """Получить кортеж с информацией о всех администраторах помещения""" try: room: Room = Room[room_id] except orm.ObjectNotFound as e: raise exceptions.NotExist(e) return tuple( AdminInfo(admin.id, admin.telegram_username) for admin in room.admins)
def get_allowed_users(room_id) -> Tuple[UserInfo, ...]: """Получение кортежа с краткой информацией о пользователях, имеющих доступ в аудиторию""" try: room: Room = Room[room_id] except orm.ObjectNotFound as e: raise exceptions.NotExist(e) allowed_users = room.allowed_users return tuple( UserInfo(user.id, user.first_name, user.last_name) for user in allowed_users)
def delete_admin_from_room(room_id: int, admin_id: int) -> None: """Удаляет администратора из указанного помещения""" try: admin: Admin = Admin[admin_id] room: Room = Room[room_id] except orm.ObjectNotFound as e: raise exceptions.NotExist(e) if admin not in room.admins: raise exceptions.BaseServiceException( "The admin is not in admins of the room") room.admins.remove(admin)
def add_admin_to_room(room_id: int, admin_id: int) -> None: """Добавляет администратора указанному помещению""" try: admin: Admin = Admin[admin_id] room: Room = Room[room_id] except orm.ObjectNotFound as e: raise exceptions.NotExist(e) if admin in room.admins: raise exceptions.AlreadyExist( "The admin has already in admins of the room") room.admins.add(admin)
def delete_user(command_string: str) -> UserInfo: """Удаление пользователя и получение информации о нем""" args: tuple = prepare_command_args(command_string) # (user_id) try: user_id: int = args[0] except IndexError: raise service_exceptions.BadNumberOfArgs() try: user = user_repository.get_user_by_id(user_id) except repo_exceptions.EntityNotFound: raise service_exceptions.NotExist() user_info = UserInfo(None, user.first_name, user.last_name) user_repository.delete_user_by_id(user_id) return user_info