update-fix
All checks were successful
Deploy to core / deploy (push) Successful in 1m37s

This commit is contained in:
Untone 2024-02-16 19:46:57 +03:00
parent 7aaa9e8d8b
commit 0a74ed0f63
5 changed files with 52 additions and 33 deletions

View File

@ -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

View File

@ -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"

View File

@ -202,33 +202,42 @@ 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
Reaction.update(r, reaction)
session.add(r)
session.commit()
r.stat = {
'reacted': reacted_stat,
'commented': commented_stat,
@ -240,6 +249,10 @@ async def update_reaction(_, info, rid, reaction):
return {'reaction': r}
else:
return {'error': 'not authorized'}
except Exception:
import traceback
traceback.print_exc()
return {'error': 'cannot create reaction'}

View File

@ -31,6 +31,7 @@ input TopicInput {
}
input ReactionInput {
id: Int!
kind: ReactionKind!
shout: Int!
quote: String

View File

@ -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