update-tolerate

This commit is contained in:
Untone 2024-02-27 16:28:54 +03:00
parent 2e68128dfc
commit eb295549fb

View File

@ -173,8 +173,11 @@ def patch_topics(session, shout, topics_input):
@mutation.field('update_shout') @mutation.field('update_shout')
@login_required @login_required
async def update_shout(_, info, shout_id, shout_input=None, publish=False): async def update_shout(_, info, shout_id, shout_input=None, publish=False):
user_id = info.context['user_id'] try:
roles = info.context['roles'] user_id = info.context.get('user_id')
if not user_id:
return {"error": "unauthorized"}
roles = info.context.get('roles')
shout_input = shout_input or {} shout_input = shout_input or {}
with local_session() as session: with local_session() as session:
author = session.query(Author).filter(Author.user == user_id).first() author = session.query(Author).filter(Author.user == user_id).first()
@ -182,6 +185,7 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
shout_id = shout_id or shout_input.get('id') shout_id = shout_id or shout_input.get('id')
slug = shout_input.get('slug') slug = shout_input.get('slug')
if slug: if slug:
shout_by_id = session.query(Shout).filter(Shout.id == shout_id).first() shout_by_id = session.query(Shout).filter(Shout.id == shout_id).first()
if shout_by_id and slug != shout_by_id.slug: if shout_by_id and slug != shout_by_id.slug:
same_slug_shout = ( same_slug_shout = (
@ -199,6 +203,7 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
c += 1 c += 1
slug += f'-{c}' slug += f'-{c}'
shout_input['slug'] = slug shout_input['slug'] = slug
if isinstance(author, Author) and isinstance(shout_id, int): if isinstance(author, Author) and isinstance(shout_id, int):
shout = ( shout = (
session.query(Shout) session.query(Shout)
@ -243,7 +248,10 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
search_service.index(shout) search_service.index(shout)
return {'shout': shout_dict} return {'shout': shout_dict}
logger.debug(f' cannot update with data: {shout_input}') except Exception as exc:
logger.error(exc)
logger.error(f' cannot update with data: {shout_input}')
return {'error': 'cant update shout'} return {'error': 'cant update shout'}