From 76d631d9a73b0d02eeef436d236a903bcc52f91c Mon Sep 17 00:00:00 2001 From: BombinBM Date: Thu, 12 Dec 2024 18:43:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=20=D0=BE=D1=82=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BD=D0=BE=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Осталось только разобраться с базой данных и тестами --- print_service/routes/file.py | 11 ++++++----- print_service/routes/user.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/print_service/routes/file.py b/print_service/routes/file.py index dd3492c..35364dc 100644 --- a/print_service/routes/file.py +++ b/print_service/routes/file.py @@ -60,7 +60,8 @@ def validate_pages(cls, value: str): class SendInput(BaseModel): - surname: str = Field( + surname: str | None = Field( + default=None, description='Фамилия', example='Иванов', ) @@ -111,7 +112,7 @@ class ReceiveOutput(BaseModel): ) async def send( inp: SendInput, - _=Depends(UnionAuth(scopes=["print.file.send"]), allow_none=True), + user_auth=Depends(UnionAuth(scopes=["print.file.send"])), settings: Settings = Depends(get_settings), ): """Получить пин код для загрузки и скачивания файла. @@ -125,7 +126,7 @@ async def send( if not settings.ALLOW_STUDENT_NUMBER: user = user.filter(UnionMember.union_number != None) - if inp.number is not None: + if inp.number is not None and inp.surname is not None: user = user.filter( or_( func.upper(UnionMember.student_number) == inp.number.upper(), @@ -134,10 +135,10 @@ async def send( func.upper(UnionMember.surname) == inp.surname.upper(), ).one_or_none() else: - if not "print.file.send" in [scope["name"] for scope in user.get('session_scopes')]: + if not "print.file.send" in [scope["name"] for scope in user_auth.get('session_scopes')]: raise NotInUnion() - if not user: + if user is None: raise NotInUnion() try: pin = generate_pin(db.session) diff --git a/print_service/routes/user.py b/print_service/routes/user.py index cc77810..34a3a3c 100644 --- a/print_service/routes/user.py +++ b/print_service/routes/user.py @@ -46,7 +46,7 @@ class UpdateUserList(BaseModel): ) async def check_union_member( surname: constr(strip_whitespace=True, to_upper=True, min_length=1), - number: Optional[str] = constr(strip_whitespace=True, to_upper=True, min_length=1), + number: constr(strip_whitespace=True, to_upper=True, min_length=1), v: Optional[str] = __version__, ): """Проверяет наличие пользователя в списке."""