From 0a74ed0f630bea9133c87f8e7e4be7ef28f39493 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 16 Feb 2024 19:46:57 +0300 Subject: [PATCH] update-fix --- CHANGELOG.txt | 5 +++ pyproject.toml | 2 +- resolvers/reaction.py | 75 ++++++++++++++++++++++++----------------- schema/input.graphql | 1 + schema/mutation.graphql | 2 +- 5 files changed, 52 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index df1c8583..f13ef633 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,8 @@ +[0.3.1] +- enabling sentry +- long query log report added +- editor fixes + [0.3.0] - Shout.featured_at timestamp of the frontpage featuring event - added proposal accepting logics diff --git a/pyproject.toml b/pyproject.toml index a600cfdd..b05ef001 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "discoursio-core" -version = "0.3.0" +version = "0.3.1" description = "core module for discours.io" authors = ["discoursio devteam"] license = "MIT" diff --git a/resolvers/reaction.py b/resolvers/reaction.py index 541ed16d..bf0b8836 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -202,44 +202,57 @@ async def create_reaction(_, info, reaction): @mutation.field('update_reaction') @login_required -async def update_reaction(_, info, rid, reaction): - user_id = info.context['user_id'] - roles = info.context['roles'] - if user_id and roles: +async def update_reaction(_, info, reaction): + user_id = info.context.get('user_id') + roles = info.context.get('roles') + rid = reaction.get('id') + if rid and user_id and roles: + del reaction['id'] with local_session() as session: - q = select(Reaction).filter(Reaction.id == rid) + reaction_query = select(Reaction).filter(Reaction.id == int(rid)) aliased_reaction = aliased(Reaction) - q = add_stat_columns(q, aliased_reaction) - q = q.group_by(Reaction.id) + reaction_query = add_stat_columns(reaction_query, aliased_reaction) + reaction_query = reaction_query.group_by(Reaction.id) - [r, reacted_stat, commented_stat, likes_stat, dislikes_stat, _l] = session.execute(q).unique().first() + try: + [r, reacted_stat, commented_stat, likes_stat, dislikes_stat, _l] = session.execute(reaction_query).unique().first() - if not r: - return {'error': 'invalid reaction id'} - author = session.query(Author).filter(Author.user == user_id).first() - if author: - if r.created_by != author.id and 'editor' not in roles: - return {'error': 'access denied'} - body = reaction.get('body') - if body: - r.body = body - r.updated_at = int(time.time()) - if r.kind != reaction['kind']: - # TODO: change mind detection can be here - pass + if not r: + return {'error': 'invalid reaction id'} - session.commit() - r.stat = { - 'reacted': reacted_stat, - 'commented': commented_stat, - 'rating': int(likes_stat or 0) - int(dislikes_stat or 0), - } + author = session.query(Author).filter(Author.user == user_id).first() + if author: + if r.created_by != author.id and 'editor' not in roles: + return {'error': 'access denied'} - await notify_reaction(r.dict(), 'update') + body = reaction.get('body') + if body: + r.body = body + r.updated_at = int(time.time()) - return {'reaction': r} - else: - return {'error': 'not authorized'} + if r.kind != reaction['kind']: + # Определение изменения мнения может быть реализовано здесь + pass + + Reaction.update(r, reaction) + session.add(r) + session.commit() + + r.stat = { + 'reacted': reacted_stat, + 'commented': commented_stat, + 'rating': int(likes_stat or 0) - int(dislikes_stat or 0), + } + + await notify_reaction(r.dict(), 'update') + + return {'reaction': r} + else: + return {'error': 'not authorized'} + except Exception: + import traceback + + traceback.print_exc() return {'error': 'cannot create reaction'} diff --git a/schema/input.graphql b/schema/input.graphql index 6411e361..3d431cb5 100644 --- a/schema/input.graphql +++ b/schema/input.graphql @@ -31,6 +31,7 @@ input TopicInput { } input ReactionInput { + id: Int! kind: ReactionKind! shout: Int! quote: String diff --git a/schema/mutation.graphql b/schema/mutation.graphql index 718f5a3f..ab90cfad 100644 --- a/schema/mutation.graphql +++ b/schema/mutation.graphql @@ -19,7 +19,7 @@ type Mutation { # reaction create_reaction(reaction: ReactionInput!): CommonResult! - update_reaction(id: Int!, reaction: ReactionInput!): CommonResult! + update_reaction(reaction: ReactionInput!): CommonResult! delete_reaction(reaction_id: Int!): CommonResult! # collab