delete-shout-tolerate
All checks were successful
Deploy on push / deploy (push) Successful in 25s

This commit is contained in:
Untone 2024-02-27 14:29:28 +03:00
parent 52f46555a7
commit 8d058b4902

View File

@ -250,30 +250,31 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
@mutation.field('delete_shout') @mutation.field('delete_shout')
@login_required @login_required
async def delete_shout(_, info, shout_id): async def delete_shout(_, info, shout_id):
user_id = info.context['user_id'] user_id = info.context.get('user_id')
roles = info.context['roles'] roles = info.context.get('roles')
with local_session() as session: if user_id:
author = session.query(Author).filter(Author.user == user_id).first() with local_session() as session:
shout = session.query(Shout).filter(Shout.id == shout_id).first() author = session.query(Author).filter(Author.user == user_id).first()
if not shout: shout = session.query(Shout).filter(Shout.id == shout_id).first()
return {'error': 'invalid shout id'} if not shout:
if author and shout: return {'error': 'invalid shout id'}
if ( if author and shout:
shout.created_by is not author.id if (
and author.id not in shout.authors shout.created_by is not author.id
and 'editor' not in roles and author.id not in shout.authors
): and 'editor' not in roles
return {'error': 'access denied'} ):
return {'error': 'access denied'}
for author_id in shout.authors: for author_id in shout.authors:
reactions_unfollow(author_id, shout_id) reactions_unfollow(author_id, shout_id)
shout_dict = shout.dict() shout_dict = shout.dict()
shout_dict['deleted_at'] = int(time.time()) shout_dict['deleted_at'] = int(time.time())
Shout.update(shout, shout_dict) Shout.update(shout, shout_dict)
session.add(shout) session.add(shout)
session.commit() session.commit()
await notify_shout(shout_dict, 'delete') await notify_shout(shout_dict, 'delete')
return {} return {}