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:
|
if auth and auth.logged_in:
|
||||||
# Существующие данные auth остаются
|
info.context["author"] = auth.author
|
||||||
pass
|
info.context["user_id"] = auth.author.get("id")
|
||||||
else:
|
else:
|
||||||
# Очищаем данные автора из контекста если авторизация отсутствует
|
# Очищаем данные автора из контекста если авторизация отсутствует
|
||||||
info.context["author"] = None
|
info.context["author"] = None
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from graphql import GraphQLResolveInfo
|
||||||
from sqlalchemy import nulls_last, text
|
from sqlalchemy import nulls_last, text
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
from sqlalchemy.sql.expression import and_, asc, case, desc, func, select
|
from sqlalchemy.sql.expression import and_, asc, case, desc, func, select
|
||||||
|
@ -353,7 +354,7 @@ def apply_filters(q, filters):
|
||||||
|
|
||||||
|
|
||||||
@query.field("get_shout")
|
@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.
|
Получение публикации по slug или id.
|
||||||
|
|
||||||
|
@ -404,7 +405,7 @@ def apply_sorting(q, options):
|
||||||
|
|
||||||
@query.field("load_shouts_by")
|
@query.field("load_shouts_by")
|
||||||
@login_accepted
|
@login_accepted
|
||||||
async def load_shouts_by(_, info, options):
|
async def load_shouts_by(_, info: GraphQLResolveInfo, options):
|
||||||
"""
|
"""
|
||||||
Загрузка публикаций с фильтрацией, сортировкой и пагинацией.
|
Загрузка публикаций с фильтрацией, сортировкой и пагинацией.
|
||||||
|
|
||||||
|
|
|
@ -107,26 +107,28 @@ def login_accepted(f):
|
||||||
info = args[1]
|
info = args[1]
|
||||||
req = info.context.get("request")
|
req = info.context.get("request")
|
||||||
|
|
||||||
# Пробуем получить данные авторизации
|
logger.debug("login_accepted: Проверка авторизации пользователя.")
|
||||||
user_id, user_roles = await check_auth(req)
|
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:
|
if user_id and user_roles:
|
||||||
# Если пользователь авторизован, добавляем его данные в контекст
|
logger.info(f"login_accepted: Пользователь авторизован: {user_id} с ролями {user_roles}")
|
||||||
logger.info(f" got {user_id} roles: {user_roles}")
|
|
||||||
info.context["user_id"] = user_id.strip()
|
info.context["user_id"] = user_id.strip()
|
||||||
info.context["roles"] = user_roles
|
info.context["roles"] = user_roles
|
||||||
|
|
||||||
# Пробуем получить профиль автора
|
# Пробуем получить профиль автора
|
||||||
author = await get_cached_author_by_user_id(user_id, get_with_stat)
|
author = await get_cached_author_by_user_id(user_id, get_with_stat)
|
||||||
if not author:
|
if author:
|
||||||
logger.warning(f"author profile not found for user {user_id}")
|
logger.debug(f"login_accepted: Найден профиль автора: {author}")
|
||||||
info.context["author"] = author
|
# Предполагается, что `author` является объектом с атрибутом `id`
|
||||||
|
info.context["author"] = author.dict()
|
||||||
else:
|
else:
|
||||||
# Для неавторизованных пользователей очищаем контекст
|
logger.error(f"login_accepted: Профиль автора не найден для пользователя {user_id}. Используем базовые данные.")# Используем базовую информацию об автор
|
||||||
|
else:
|
||||||
|
logger.debug("login_accepted: Пользователь не авторизован. Очищаем контекст.")
|
||||||
info.context["user_id"] = None
|
info.context["user_id"] = None
|
||||||
info.context["roles"] = None
|
info.context["roles"] = None
|
||||||
info.context["author"] = None
|
info.context["author"] = None
|
||||||
|
|
||||||
return await f(*args, **kwargs)
|
return await f(*args, **kwargs)
|
||||||
|
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
Loading…
Reference in New Issue
Block a user