invites-fix4
This commit is contained in:
parent
5f48ec465a
commit
71f26a76c3
|
@ -7,6 +7,7 @@
|
||||||
- Исправлена ошибка в функции `admin_get_invites` в файле `resolvers/admin.py` - добавлено значение по умолчанию для поля `slug` в объектах `Author`, чтобы избежать ошибки "Cannot return null for non-nullable field Author.slug"
|
- Исправлена ошибка в функции `admin_get_invites` в файле `resolvers/admin.py` - добавлено значение по умолчанию для поля `slug` в объектах `Author`, чтобы избежать ошибки "Cannot return null for non-nullable field Author.slug"
|
||||||
- Исправлена ошибка в функции `admin_get_invites` - заменен несуществующий атрибут `Shout.created_by_author` на правильное получение автора через поле `created_by`
|
- Исправлена ошибка в функции `admin_get_invites` - заменен несуществующий атрибут `Shout.created_by_author` на правильное получение автора через поле `created_by`
|
||||||
- Исправлена функция `admin_delete_invites_batch` - завершена реализация для корректной обработки пакетного удаления приглашений
|
- Исправлена функция `admin_delete_invites_batch` - завершена реализация для корректной обработки пакетного удаления приглашений
|
||||||
|
- Исправлена ошибка в функции `get_shouts_with_links` в файле `resolvers/reader.py` - добавлено значение по умолчанию для поля `slug` у авторов публикаций в полях `authors` и `created_by`, чтобы избежать ошибки "Cannot return null for non-nullable field Author.slug"
|
||||||
|
|
||||||
### Улучшения админ-панели для приглашений
|
### Улучшения админ-панели для приглашений
|
||||||
|
|
||||||
|
|
|
@ -519,7 +519,7 @@ async def admin_get_shouts(
|
||||||
"id": getattr(author, "id", None),
|
"id": getattr(author, "id", None),
|
||||||
"email": getattr(author, "email", None),
|
"email": getattr(author, "email", None),
|
||||||
"name": getattr(author, "name", None),
|
"name": getattr(author, "name", None),
|
||||||
"slug": getattr(author, "slug", None),
|
"slug": getattr(author, "slug", None) or f"user-{getattr(author, 'id', 'unknown')}",
|
||||||
}
|
}
|
||||||
for author in (
|
for author in (
|
||||||
getattr(shout, "authors", [])
|
getattr(shout, "authors", [])
|
||||||
|
@ -803,14 +803,50 @@ async def admin_get_invites(
|
||||||
|
|
||||||
# Добавляем информацию о создателе публикации, если она доступна
|
# Добавляем информацию о создателе публикации, если она доступна
|
||||||
if created_by_author:
|
if created_by_author:
|
||||||
invite_dict["shout"]["created_by"] = {
|
# Создаем новый словарь для shout
|
||||||
|
shout_dict = {}
|
||||||
|
|
||||||
|
# Копируем основные поля
|
||||||
|
if isinstance(invite_dict["shout"], dict):
|
||||||
|
shout_info = invite_dict["shout"]
|
||||||
|
shout_dict["id"] = shout_info.get("id")
|
||||||
|
shout_dict["title"] = shout_info.get("title")
|
||||||
|
shout_dict["slug"] = shout_info.get("slug")
|
||||||
|
else:
|
||||||
|
# Если это не словарь, берем данные напрямую из объекта invite.shout
|
||||||
|
shout_dict["id"] = invite.shout.id
|
||||||
|
shout_dict["title"] = invite.shout.title
|
||||||
|
shout_dict["slug"] = invite.shout.slug
|
||||||
|
|
||||||
|
# Добавляем информацию о создателе
|
||||||
|
shout_dict["created_by"] = {
|
||||||
"id": created_by_author.id,
|
"id": created_by_author.id,
|
||||||
"name": created_by_author.name or "Без имени",
|
"name": created_by_author.name or "Без имени",
|
||||||
"email": created_by_author.email,
|
"email": created_by_author.email,
|
||||||
"slug": created_by_author.slug or f"user-{created_by_author.id}",
|
"slug": created_by_author.slug or f"user-{created_by_author.id}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
invite_dict["shout"] = shout_dict
|
||||||
else:
|
else:
|
||||||
invite_dict["shout"]["created_by"] = None
|
# Создаем новый словарь для shout
|
||||||
|
shout_dict = {}
|
||||||
|
|
||||||
|
# Копируем основные поля
|
||||||
|
if isinstance(invite_dict["shout"], dict):
|
||||||
|
shout_info = invite_dict["shout"]
|
||||||
|
shout_dict["id"] = shout_info.get("id")
|
||||||
|
shout_dict["title"] = shout_info.get("title")
|
||||||
|
shout_dict["slug"] = shout_info.get("slug")
|
||||||
|
else:
|
||||||
|
# Если это не словарь, берем данные напрямую из объекта invite.shout
|
||||||
|
shout_dict["id"] = invite.shout.id
|
||||||
|
shout_dict["title"] = invite.shout.title
|
||||||
|
shout_dict["slug"] = invite.shout.slug
|
||||||
|
|
||||||
|
# Указываем, что created_by отсутствует
|
||||||
|
shout_dict["created_by"] = None
|
||||||
|
|
||||||
|
invite_dict["shout"] = shout_dict
|
||||||
|
|
||||||
result_invites.append(invite_dict)
|
result_invites.append(invite_dict)
|
||||||
|
|
||||||
|
@ -1057,11 +1093,12 @@ async def admin_delete_invites_batch(
|
||||||
logger.info(f"Пакетное удаление приглашений: удалено {deleted_count} приглашений")
|
logger.info(f"Пакетное удаление приглашений: удалено {deleted_count} приглашений")
|
||||||
|
|
||||||
# Формируем результат
|
# Формируем результат
|
||||||
result = {"success": True, "error": None}
|
success = deleted_count > 0
|
||||||
|
error = None
|
||||||
if errors:
|
if errors:
|
||||||
result["error"] = f"Удалено {deleted_count} приглашений. Ошибки: {', '.join(errors)}"
|
error = f"Удалено {deleted_count} приглашений. Ошибки: {', '.join(errors)}"
|
||||||
|
|
||||||
return result
|
return {"success": success, "error": error}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Ошибка при пакетном удалении приглашений: {e!s}")
|
logger.error(f"Ошибка при пакетном удалении приглашений: {e!s}")
|
||||||
|
|
|
@ -227,7 +227,7 @@ def get_shouts_with_links(info: GraphQLResolveInfo, q: select, limit: int = 20,
|
||||||
shout_dict["created_by"] = {
|
shout_dict["created_by"] = {
|
||||||
"id": main_author_id,
|
"id": main_author_id,
|
||||||
"name": a.name,
|
"name": a.name,
|
||||||
"slug": a.slug,
|
"slug": a.slug or f"user-{main_author_id}",
|
||||||
"pic": a.pic,
|
"pic": a.pic,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ def get_shouts_with_links(info: GraphQLResolveInfo, q: select, limit: int = 20,
|
||||||
shout_dict["updated_by"] = {
|
shout_dict["updated_by"] = {
|
||||||
"id": updated_author.id,
|
"id": updated_author.id,
|
||||||
"name": updated_author.name,
|
"name": updated_author.name,
|
||||||
"slug": updated_author.slug,
|
"slug": updated_author.slug or f"user-{updated_author.id}",
|
||||||
"pic": updated_author.pic,
|
"pic": updated_author.pic,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
@ -259,7 +259,7 @@ def get_shouts_with_links(info: GraphQLResolveInfo, q: select, limit: int = 20,
|
||||||
shout_dict["deleted_by"] = {
|
shout_dict["deleted_by"] = {
|
||||||
"id": deleted_author.id,
|
"id": deleted_author.id,
|
||||||
"name": deleted_author.name,
|
"name": deleted_author.name,
|
||||||
"slug": deleted_author.slug,
|
"slug": deleted_author.slug or f"user-{deleted_author.id}",
|
||||||
"pic": deleted_author.pic,
|
"pic": deleted_author.pic,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
@ -315,9 +315,13 @@ def get_shouts_with_links(info: GraphQLResolveInfo, q: select, limit: int = 20,
|
||||||
# logger.debug(f"Final main_topic for shout#{shout_id}: {main_topic}")
|
# logger.debug(f"Final main_topic for shout#{shout_id}: {main_topic}")
|
||||||
|
|
||||||
if has_field(info, "authors") and hasattr(row, "authors"):
|
if has_field(info, "authors") and hasattr(row, "authors"):
|
||||||
shout_dict["authors"] = (
|
authors_data = orjson.loads(row.authors) if isinstance(row.authors, str) else row.authors
|
||||||
orjson.loads(row.authors) if isinstance(row.authors, str) else row.authors
|
# Проверяем и добавляем значение по умолчанию для slug, если оно пустое
|
||||||
)
|
if authors_data:
|
||||||
|
for author in authors_data:
|
||||||
|
if not author.get("slug"):
|
||||||
|
author["slug"] = f"user-{author.get('id', 'unknown')}"
|
||||||
|
shout_dict["authors"] = authors_data
|
||||||
|
|
||||||
if has_field(info, "media") and shout.media:
|
if has_field(info, "media") and shout.media:
|
||||||
# Обработка поля media
|
# Обработка поля media
|
||||||
|
|
Loading…
Reference in New Issue
Block a user