diff --git a/resolvers/create/collab.py b/resolvers/create/collab.py index df509452..c51c9be2 100644 --- a/resolvers/create/collab.py +++ b/resolvers/create/collab.py @@ -20,7 +20,7 @@ async def get_collabs(_, info): @mutation.field("inviteCoauthor") @login_required -async def invite_coauthor(_, info, author: str, shout: int): +async def invite_coauthor(_, info, author: int = 0, shout: int = 0): auth: AuthCredentials = info.context["request"].auth with local_session() as session: @@ -43,21 +43,19 @@ async def invite_coauthor(_, info, author: str, shout: int): @mutation.field("removeCoauthor") @login_required -async def remove_coauthor(_, info, author: str, shout: int): +async def remove_coauthor(_, info, author: int = 0, shout: int = 0): auth: AuthCredentials = info.context["request"].auth with local_session() as session: - s = session.query(Shout).where(Shout.id == shout).one() - if not s: - raise ObjectNotExist("invalid shout id") - if auth.user_id != s.createdBy: + s = session.query(Shout).where(Shout.id == shout).one() # raises Error when not found + if auth.user_id not in s.authors: raise BaseHttpException("only owner can remove coauthors") else: c = session.query(Collab).where(Collab.shout == shout).one() - ca = session.query(CollabAuthor).join(User).where(c.shout == shout, User.slug == author).one() + ca = session.query(CollabAuthor).join(User).where(c.shout == shout, User.id == author).one() session.remve(ca) - c.invites = filter(lambda x: x.slug == author, c.invites) - c.authors = filter(lambda x: x.slug == author, c.authors) + c.invites = filter(lambda x: x.id == author, c.invites) + c.authors = filter(lambda x: x.id == author, c.authors) session.add(c) session.commit() diff --git a/resolvers/zine/reactions.py b/resolvers/zine/reactions.py index a6e0f0dd..55b4e095 100644 --- a/resolvers/zine/reactions.py +++ b/resolvers/zine/reactions.py @@ -14,9 +14,9 @@ def add_reaction_stat_columns(q): return add_common_stat_columns(q) -def reactions_follow(user_id, slug: str, auto=False): +def reactions_follow(user_id, shout_id: int, auto=False): with local_session() as session: - shout = session.query(Shout).where(Shout.slug == slug).one() + shout = session.query(Shout).where(Shout.id == shout_id).one() following = ( session.query(ShoutReactionsFollower).where(and_( @@ -35,9 +35,9 @@ def reactions_follow(user_id, slug: str, auto=False): session.commit() -def reactions_unfollow(user_id, slug): +def reactions_unfollow(user_id: int, shout_id: int): with local_session() as session: - shout = session.query(Shout).where(Shout.slug == slug).one() + shout = session.query(Shout).where(Shout.id == shout_id).one() following = ( session.query(ShoutReactionsFollower).where(and_( @@ -129,7 +129,7 @@ def set_hidden(session, shout_id): @login_required async def create_reaction(_, info, reaction={}): auth: AuthCredentials = info.context["request"].auth - + reaction['createdBy'] = auth.user_id with local_session() as session: r = Reaction.create(**reaction) session.add(r) diff --git a/schema.graphql b/schema.graphql index 839e9ebb..015f2b02 100644 --- a/schema.graphql +++ b/schema.graphql @@ -129,7 +129,7 @@ input TopicInput { } input ReactionInput { - kind: Int! + kind: ReactionKind! shout: Int! range: String body: String