This commit is contained in:
parent
7aaa9e8d8b
commit
0a74ed0f63
|
@ -1,3 +1,8 @@
|
||||||
|
[0.3.1]
|
||||||
|
- enabling sentry
|
||||||
|
- long query log report added
|
||||||
|
- editor fixes
|
||||||
|
|
||||||
[0.3.0]
|
[0.3.0]
|
||||||
- Shout.featured_at timestamp of the frontpage featuring event
|
- Shout.featured_at timestamp of the frontpage featuring event
|
||||||
- added proposal accepting logics
|
- added proposal accepting logics
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "discoursio-core"
|
name = "discoursio-core"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
description = "core module for discours.io"
|
description = "core module for discours.io"
|
||||||
authors = ["discoursio devteam"]
|
authors = ["discoursio devteam"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -202,44 +202,57 @@ async def create_reaction(_, info, reaction):
|
||||||
|
|
||||||
@mutation.field('update_reaction')
|
@mutation.field('update_reaction')
|
||||||
@login_required
|
@login_required
|
||||||
async def update_reaction(_, info, rid, reaction):
|
async def update_reaction(_, info, reaction):
|
||||||
user_id = info.context['user_id']
|
user_id = info.context.get('user_id')
|
||||||
roles = info.context['roles']
|
roles = info.context.get('roles')
|
||||||
if user_id and roles:
|
rid = reaction.get('id')
|
||||||
|
if rid and user_id and roles:
|
||||||
|
del reaction['id']
|
||||||
with local_session() as session:
|
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)
|
aliased_reaction = aliased(Reaction)
|
||||||
q = add_stat_columns(q, aliased_reaction)
|
reaction_query = add_stat_columns(reaction_query, aliased_reaction)
|
||||||
q = q.group_by(Reaction.id)
|
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:
|
if not r:
|
||||||
return {'error': 'invalid reaction id'}
|
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
|
|
||||||
|
|
||||||
session.commit()
|
author = session.query(Author).filter(Author.user == user_id).first()
|
||||||
r.stat = {
|
if author:
|
||||||
'reacted': reacted_stat,
|
if r.created_by != author.id and 'editor' not in roles:
|
||||||
'commented': commented_stat,
|
return {'error': 'access denied'}
|
||||||
'rating': int(likes_stat or 0) - int(dislikes_stat or 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
await notify_reaction(r.dict(), 'update')
|
body = reaction.get('body')
|
||||||
|
if body:
|
||||||
|
r.body = body
|
||||||
|
r.updated_at = int(time.time())
|
||||||
|
|
||||||
return {'reaction': r}
|
if r.kind != reaction['kind']:
|
||||||
else:
|
# Определение изменения мнения может быть реализовано здесь
|
||||||
return {'error': 'not authorized'}
|
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'}
|
return {'error': 'cannot create reaction'}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ input TopicInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
input ReactionInput {
|
input ReactionInput {
|
||||||
|
id: Int!
|
||||||
kind: ReactionKind!
|
kind: ReactionKind!
|
||||||
shout: Int!
|
shout: Int!
|
||||||
quote: String
|
quote: String
|
||||||
|
|
|
@ -19,7 +19,7 @@ type Mutation {
|
||||||
|
|
||||||
# reaction
|
# reaction
|
||||||
create_reaction(reaction: ReactionInput!): CommonResult!
|
create_reaction(reaction: ReactionInput!): CommonResult!
|
||||||
update_reaction(id: Int!, reaction: ReactionInput!): CommonResult!
|
update_reaction(reaction: ReactionInput!): CommonResult!
|
||||||
delete_reaction(reaction_id: Int!): CommonResult!
|
delete_reaction(reaction_id: Int!): CommonResult!
|
||||||
|
|
||||||
# collab
|
# collab
|
||||||
|
|
Loading…
Reference in New Issue
Block a user