From 6f3ed3704a8bbbbe672ae7db650408b2dec41d42 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 7 Mar 2024 14:29:45 +0300 Subject: [PATCH] get-my-shout-api-fix --- resolvers/editor.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/resolvers/editor.py b/resolvers/editor.py index 663714fb..434fda57 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -32,16 +32,15 @@ async def get_my_shout(_, info, shout_id: int): if not shout.published_at: user_id = info.context.get('user_id', '') roles = info.context.get('roles', []) - if not user_id: - error = 'unauthorized' + if 'editor' in roles or filter( + lambda x: x.id == author.id, [x for x in shout.authors] + ): + error = None else: - if 'editor' in roles or filter( - lambda x: x.id == author.id, [x for x in shout.authors] - ): - return {'error': None, 'shout': shout} - else: - error = 'forbidden' - return {'error': error, 'shout': shout} + error = 'forbidden' + shout = None + return {'error': error, 'shout': shout.dict()} + return {'error': 'no shout found', 'shout': None} @query.field('get_shouts_drafts')