This commit is contained in:
@@ -9,11 +9,10 @@ import time
|
||||
from functools import wraps
|
||||
from typing import Any, Callable
|
||||
|
||||
from graphql.error import GraphQLError
|
||||
from starlette.requests import Request
|
||||
|
||||
from auth.email import send_auth_email
|
||||
from auth.exceptions import InvalidPasswordError, InvalidTokenError, ObjectNotExistError
|
||||
from auth.exceptions import AuthorizationError, InvalidPasswordError, InvalidTokenError, ObjectNotExistError
|
||||
from auth.identity import Identity
|
||||
from auth.internal import verify_internal_auth
|
||||
from auth.jwtcodec import JWTCodec
|
||||
@@ -759,13 +758,13 @@ class AuthService:
|
||||
user_id, user_roles, is_admin = await self.check_auth(req)
|
||||
|
||||
if not user_id:
|
||||
msg = "Требуется авторизация"
|
||||
raise GraphQLError(msg)
|
||||
logger.info("[login_required] Авторизация не пройдена - токен отсутствует или недействителен")
|
||||
raise AuthorizationError("Требуется авторизация")
|
||||
|
||||
# Проверяем роль reader
|
||||
if "reader" not in user_roles and not is_admin:
|
||||
msg = "У вас нет необходимых прав для доступа"
|
||||
raise GraphQLError(msg)
|
||||
logger.info(f"[login_required] Недостаточно прав - роли: {user_roles}, требуется 'reader'")
|
||||
raise AuthorizationError("У вас нет необходимых прав для доступа")
|
||||
|
||||
logger.info(f"Авторизован пользователь {user_id} с ролями: {user_roles}")
|
||||
info.context["roles"] = user_roles
|
||||
|
||||
Reference in New Issue
Block a user