publish fixes
This commit is contained in:
parent
6068199c0f
commit
e0bef72de9
|
@ -130,39 +130,44 @@ async def update_shout(_, info, shout_id, shout_input):
|
||||||
|
|
||||||
@mutation.field("publishShout")
|
@mutation.field("publishShout")
|
||||||
@login_required
|
@login_required
|
||||||
async def publish_shout(_, info, slug, inp):
|
async def publish_shout(_, info, shout_id, shout_input=None):
|
||||||
|
if shout_input is None:
|
||||||
|
shout_input = {}
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
||||||
if not shout:
|
if not shout:
|
||||||
return {"error": "shout not found"}
|
return {"error": "shout not found"}
|
||||||
|
|
||||||
else:
|
if shout.createdBy != auth.user_id:
|
||||||
shout.update(inp)
|
return {"error": "access denied"}
|
||||||
shout.visibility = "community"
|
|
||||||
shout.updatedAt = datetime.now(tz=timezone.utc)
|
if shout_input is not None:
|
||||||
session.commit()
|
shout.update(shout_input)
|
||||||
|
|
||||||
|
shout.visibility = "community"
|
||||||
|
shout.updatedAt = datetime.now(tz=timezone.utc)
|
||||||
|
shout.publishedAt = datetime.now(tz=timezone.utc)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
return {"shout": shout}
|
return {"shout": shout}
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("deleteShout")
|
@mutation.field("deleteShout")
|
||||||
@login_required
|
@login_required
|
||||||
async def delete_shout(_, info, slug):
|
async def delete_shout(_, info, shout_id):
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
||||||
authors = [a.id for a in shout.authors]
|
|
||||||
if not shout:
|
if not shout:
|
||||||
return {"error": "invalid shout slug"}
|
return {"error": "invalid shout id"}
|
||||||
if auth.user_id not in authors:
|
if auth.user_id != shout.createdBy:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
for a in authors:
|
for author_id in shout.authors:
|
||||||
reactions_unfollow(a.id, slug)
|
reactions_unfollow(author_id, shout_id)
|
||||||
shout.deletedAt = datetime.now(tz=timezone.utc)
|
shout.deletedAt = datetime.now(tz=timezone.utc)
|
||||||
session.add(shout)
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user