This commit is contained in:
parent
471781f942
commit
1a371b191a
1
.cursorignore
Normal file
1
.cursorignore
Normal file
|
@ -0,0 +1 @@
|
|||
# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv)
|
|
@ -84,8 +84,8 @@ def login_accepted(func):
|
|||
|
||||
# Если есть авторизация, добавляем данные автора в контекст
|
||||
if auth and auth.logged_in:
|
||||
# Существующие данные auth остаются
|
||||
pass
|
||||
info.context["author"] = auth.author
|
||||
info.context["user_id"] = auth.author.get("id")
|
||||
else:
|
||||
# Очищаем данные автора из контекста если авторизация отсутствует
|
||||
info.context["author"] = None
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
import time
|
||||
|
||||
from graphql import GraphQLResolveInfo
|
||||
from sqlalchemy import nulls_last, text
|
||||
from sqlalchemy.orm import aliased
|
||||
from sqlalchemy.sql.expression import and_, asc, case, desc, func, select
|
||||
|
@ -353,7 +354,7 @@ def apply_filters(q, filters):
|
|||
|
||||
|
||||
@query.field("get_shout")
|
||||
async def get_shout(_, info, slug="", shout_id=0):
|
||||
async def get_shout(_, info: GraphQLResolveInfo, slug="", shout_id=0):
|
||||
"""
|
||||
Получение публикации по slug или id.
|
||||
|
||||
|
@ -404,7 +405,7 @@ def apply_sorting(q, options):
|
|||
|
||||
@query.field("load_shouts_by")
|
||||
@login_accepted
|
||||
async def load_shouts_by(_, info, options):
|
||||
async def load_shouts_by(_, info: GraphQLResolveInfo, options):
|
||||
"""
|
||||
Загрузка публикаций с фильтрацией, сортировкой и пагинацией.
|
||||
|
||||
|
|
|
@ -106,27 +106,29 @@ def login_accepted(f):
|
|||
async def decorated_function(*args, **kwargs):
|
||||
info = args[1]
|
||||
req = info.context.get("request")
|
||||
|
||||
# Пробуем получить данные авторизации
|
||||
|
||||
logger.debug("login_accepted: Проверка авторизации пользователя.")
|
||||
user_id, user_roles = await check_auth(req)
|
||||
|
||||
logger.debug(f"login_accepted: user_id={user_id}, user_roles={user_roles}")
|
||||
|
||||
if user_id and user_roles:
|
||||
# Если пользователь авторизован, добавляем его данные в контекст
|
||||
logger.info(f" got {user_id} roles: {user_roles}")
|
||||
logger.info(f"login_accepted: Пользователь авторизован: {user_id} с ролями {user_roles}")
|
||||
info.context["user_id"] = user_id.strip()
|
||||
info.context["roles"] = user_roles
|
||||
|
||||
# Пробуем получить профиль автора
|
||||
author = await get_cached_author_by_user_id(user_id, get_with_stat)
|
||||
if not author:
|
||||
logger.warning(f"author profile not found for user {user_id}")
|
||||
info.context["author"] = author
|
||||
if author:
|
||||
logger.debug(f"login_accepted: Найден профиль автора: {author}")
|
||||
# Предполагается, что `author` является объектом с атрибутом `id`
|
||||
info.context["author"] = author.dict()
|
||||
else:
|
||||
logger.error(f"login_accepted: Профиль автора не найден для пользователя {user_id}. Используем базовые данные.")# Используем базовую информацию об автор
|
||||
else:
|
||||
# Для неавторизованных пользователей очищаем контекст
|
||||
logger.debug("login_accepted: Пользователь не авторизован. Очищаем контекст.")
|
||||
info.context["user_id"] = None
|
||||
info.context["roles"] = None
|
||||
info.context["author"] = None
|
||||
|
||||
return await f(*args, **kwargs)
|
||||
|
||||
return decorated_function
|
||||
|
|
Loading…
Reference in New Issue
Block a user