reaction-by-fix2
All checks were successful
Deploy on push / deploy (push) Successful in 46s

This commit is contained in:
Untone 2025-04-26 15:47:44 +03:00
parent 3b3cc1c1d8
commit 631ad47fe8
2 changed files with 3 additions and 7 deletions

View File

@ -51,16 +51,12 @@ class Draft(Base):
# auto # auto
updated_at: int | None = Column(Integer, nullable=True, index=True) updated_at: int | None = Column(Integer, nullable=True, index=True)
deleted_at: int | None = Column(Integer, nullable=True, index=True) deleted_at: int | None = Column(Integer, nullable=True, index=True)
# Переименовываем колонки ID
updated_by: int | None = Column("updated_by", ForeignKey("author.id"), nullable=True) updated_by: int | None = Column("updated_by", ForeignKey("author.id"), nullable=True)
deleted_by: int | None = Column("deleted_by", ForeignKey("author.id"), nullable=True) deleted_by: int | None = Column("deleted_by", ForeignKey("author.id"), nullable=True)
# --- Relationships --- # --- Relationships ---
# Загружаем этих авторов сразу, т.к. они часто нужны и их немного (обычно 1)
created_by = relationship("Author", foreign_keys=[created_by], lazy="joined", innerjoin=True)
updated_by = relationship("Author", foreign_keys=[updated_by], lazy="joined")
deleted_by = relationship("Author", foreign_keys=[deleted_by], lazy="joined")
# Оставляем lazy="select" (по умолчанию) для коллекций, будем загружать их через joinedload в запросах # Оставляем lazy="select" (по умолчанию) для коллекций, будем загружать их через joinedload в запросах
authors = relationship(Author, secondary="draft_author", lazy="select") authors = relationship(Author, secondary="draft_author", lazy="select")
topics = relationship(Topic, secondary="draft_topic", lazy="select") topics = relationship(Topic, secondary="draft_topic", lazy="select")

View File

@ -241,7 +241,7 @@ async def delete_draft(_, info, draft_id: int):
draft = session.query(Draft).filter(Draft.id == draft_id).first() draft = session.query(Draft).filter(Draft.id == draft_id).first()
if not draft: if not draft:
return {"error": "Draft not found"} return {"error": "Draft not found"}
if author_id != draft.created_by and draft.authors.filter(Author.id == author_id).count() == 0: if author_id != draft.created_by_id and draft.authors.filter(Author.id == author_id).count() == 0:
return {"error": "You are not allowed to delete this draft"} return {"error": "You are not allowed to delete this draft"}
session.delete(draft) session.delete(draft)
session.commit() session.commit()