From 1362eaa1258ea4d7363ad83f929792ff6e83cdf3 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 30 Nov 2023 11:27:06 +0300 Subject: [PATCH] createdby-fix --- CHANGELOG.txt | 2 ++ orm/user.py | 2 +- resolvers/collab.py | 6 +++--- resolvers/reader.py | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6a6f7ae7..9791ef65 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,7 +1,9 @@ [0.2.17] - schema: enum types workaround, ReactionKind, InviteStatus, ShoutVisibility +- schema: Shout.created_by, Shout.updated_by fixes - resovlers: optimized reacted shouts updates query + [0.2.16] - resolvers: collab inviting logics - resolvers: queries and mutations revision and renaming diff --git a/orm/user.py b/orm/user.py index f6735528..8f926258 100644 --- a/orm/user.py +++ b/orm/user.py @@ -24,7 +24,7 @@ class User(Base): # preferred_username = Column(String, nullable=False) picture = Column(String) revoked_timestamp = Column(Integer) - roles = Column(JSON) + roles = Column(String, default="author, reader") signup_methods = Column(String, default="magic_link_login") created_at = Column(Integer, default=lambda: int(time.time())) updated_at = Column(Integer, default=lambda: int(time.time())) diff --git a/resolvers/collab.py b/resolvers/collab.py index 0098ecd4..e8a619fd 100644 --- a/resolvers/collab.py +++ b/resolvers/collab.py @@ -64,7 +64,7 @@ async def create_invite(_, info, slug: str = "", author_id: int = None): with local_session() as session: shout = session.query(Shout).filter(Shout.slug == slug).first() inviter = session.query(Author).filter(Author.user == user_id).first() - if inviter and shout and shout.authors and inviter.id == shout.authors[0]: + if inviter and shout and shout.authors and inviter.id == shout.created_by: # Check if the author is a valid author author = session.query(Author).filter(Author.id == author_id).first() if author: @@ -105,7 +105,7 @@ async def remove_author(_, info, slug: str = "", author_id: int = None): if author: shout = session.query(Shout).filter(Shout.slug == slug).first() # NOTE: owner should be first in a list - if shout and author.id == shout.authors[0]: + if shout and author.id == shout.created_by: shout.authors = [author for author in shout.authors if author.id != author_id] session.commit() return {} @@ -125,7 +125,7 @@ async def remove_invite(_, info, invite_id: int): invite = session.query(Invite).filter(Invite.id == invite_id).first() shout = session.query(Shout).filter(Shout.id == invite.shout_id).first() if shout and shout.deleted_at is None and invite: - if invite.inviter_id == author.id or author.id == shout.authors.index(0): + if invite.inviter_id == author.id or author.id == shout.created_by: if invite.status == InviteStatus.PENDING.value: # Delete the invite session.delete(invite) diff --git a/resolvers/reader.py b/resolvers/reader.py index cebc85e4..b77126dd 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -201,6 +201,7 @@ async def load_shouts_feed(_, info, options): q = ( select(Shout) .options( + joinedload(Shout.created_by, Author.id == Shout.created_by), joinedload(Shout.authors), joinedload(Shout.topics), )