unpublish-fixing
This commit is contained in:
@@ -679,13 +679,28 @@ async def unpublish_shout(_: None, info: GraphQLResolveInfo, shout_id: int) -> C
|
||||
if not shout:
|
||||
return CommonResult(error="Shout not found", shout=None)
|
||||
|
||||
# Проверяем права доступа
|
||||
can_edit = any(author.id == author_id for author in shout.authors) or "editor" in roles
|
||||
# 🔍 Проверяем права доступа - добавляем логгирование для диагностики
|
||||
is_creator = shout.created_by == author_id
|
||||
is_author = any(author.id == author_id for author in shout.authors)
|
||||
is_editor = "editor" in roles
|
||||
|
||||
logger.info(f"Unpublish check for user {author_id}: is_creator={is_creator}, is_author={is_author}, is_editor={is_editor}, roles={roles}")
|
||||
|
||||
can_edit = is_creator or is_author or is_editor
|
||||
|
||||
if can_edit:
|
||||
shout.published_at = None # type: ignore[assignment]
|
||||
shout.updated_at = int(time.time()) # type: ignore[assignment]
|
||||
session.add(shout)
|
||||
|
||||
# 🔍 Обновляем связанный черновик - убираем ссылку на публикацию
|
||||
from orm.draft import Draft
|
||||
related_draft = session.query(Draft).where(Draft.shout == shout_id).first()
|
||||
if related_draft:
|
||||
related_draft.shout = None
|
||||
session.add(related_draft)
|
||||
logger.info(f"Updated related draft {related_draft.id} - removed shout reference")
|
||||
|
||||
session.commit()
|
||||
|
||||
# Инвалидация кэша
|
||||
|
||||
Reference in New Issue
Block a user