reaction-creation-fix
This commit is contained in:
parent
4ce0f47bab
commit
f7839bf2df
|
@ -20,7 +20,7 @@ async def get_collabs(_, info):
|
||||||
|
|
||||||
@mutation.field("inviteCoauthor")
|
@mutation.field("inviteCoauthor")
|
||||||
@login_required
|
@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
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
|
@ -43,21 +43,19 @@ async def invite_coauthor(_, info, author: str, shout: int):
|
||||||
|
|
||||||
@mutation.field("removeCoauthor")
|
@mutation.field("removeCoauthor")
|
||||||
@login_required
|
@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
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
s = session.query(Shout).where(Shout.id == shout).one()
|
s = session.query(Shout).where(Shout.id == shout).one() # raises Error when not found
|
||||||
if not s:
|
if auth.user_id not in s.authors:
|
||||||
raise ObjectNotExist("invalid shout id")
|
|
||||||
if auth.user_id != s.createdBy:
|
|
||||||
raise BaseHttpException("only owner can remove coauthors")
|
raise BaseHttpException("only owner can remove coauthors")
|
||||||
else:
|
else:
|
||||||
c = session.query(Collab).where(Collab.shout == shout).one()
|
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)
|
session.remve(ca)
|
||||||
c.invites = filter(lambda x: x.slug == author, c.invites)
|
c.invites = filter(lambda x: x.id == author, c.invites)
|
||||||
c.authors = filter(lambda x: x.slug == author, c.authors)
|
c.authors = filter(lambda x: x.id == author, c.authors)
|
||||||
session.add(c)
|
session.add(c)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,9 @@ def add_reaction_stat_columns(q):
|
||||||
return add_common_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:
|
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 = (
|
following = (
|
||||||
session.query(ShoutReactionsFollower).where(and_(
|
session.query(ShoutReactionsFollower).where(and_(
|
||||||
|
@ -35,9 +35,9 @@ def reactions_follow(user_id, slug: str, auto=False):
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def reactions_unfollow(user_id, slug):
|
def reactions_unfollow(user_id: int, shout_id: int):
|
||||||
with local_session() as session:
|
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 = (
|
following = (
|
||||||
session.query(ShoutReactionsFollower).where(and_(
|
session.query(ShoutReactionsFollower).where(and_(
|
||||||
|
@ -129,7 +129,7 @@ def set_hidden(session, shout_id):
|
||||||
@login_required
|
@login_required
|
||||||
async def create_reaction(_, info, reaction={}):
|
async def create_reaction(_, info, reaction={}):
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
reaction['createdBy'] = auth.user_id
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
r = Reaction.create(**reaction)
|
r = Reaction.create(**reaction)
|
||||||
session.add(r)
|
session.add(r)
|
||||||
|
|
|
@ -129,7 +129,7 @@ input TopicInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
input ReactionInput {
|
input ReactionInput {
|
||||||
kind: Int!
|
kind: ReactionKind!
|
||||||
shout: Int!
|
shout: Int!
|
||||||
range: String
|
range: String
|
||||||
body: String
|
body: String
|
||||||
|
|
Loading…
Reference in New Issue
Block a user