diff --git a/resolvers/editor.py b/resolvers/editor.py index 43a94e8b..3d92ee59 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -175,12 +175,12 @@ def patch_topics(session, shout, topics_input): @mutation.field('update_shout') @login_required async def update_shout(_, info, shout_id, shout_input=None, publish=False): + user_id = info.context.get('user_id') + roles = info.context.get('roles', []) + shout_input = shout_input or {} + if not user_id: + return {"error": "unauthorized"} try: - user_id = info.context.get('user_id') - if not user_id: - return {"error": "unauthorized"} - roles = info.context.get('roles', []) - shout_input = shout_input or {} with local_session() as session: author = session.query(Author).filter(Author.user == user_id).first() current_time = int(time.time()) @@ -206,7 +206,7 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False): ) shout_input['slug'] = slug - if isinstance(author, Author) and isinstance(shout_id, int): + if author and isinstance(shout_id, int): shout = ( session.query(Shout) .options(joinedload(Shout.authors), joinedload(Shout.topics)) diff --git a/resolvers/reader.py b/resolvers/reader.py index f5c0ff5a..d41e1266 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -229,6 +229,7 @@ async def load_shouts_by(_, _info, options): return shouts + @login_required @query.field('load_shouts_drafts') async def load_shouts_drafts(_, info):