createdby-fix

This commit is contained in:
Untone 2023-11-30 11:27:06 +03:00
parent 685988c219
commit 1362eaa125
4 changed files with 7 additions and 4 deletions

View File

@ -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

View File

@ -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()))

View File

@ -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)

View File

@ -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),
)