@login_required required keyworded args
This commit is contained in:
parent
c12bd30c64
commit
dbaa88cefb
|
@ -14,7 +14,7 @@ from migration.tables.users import migrate as migrateUser
|
||||||
from migration.tables.users import migrate_2stage as migrateUser_2stage
|
from migration.tables.users import migrate_2stage as migrateUser_2stage
|
||||||
from orm.reaction import Reaction
|
from orm.reaction import Reaction
|
||||||
from orm import init_tables
|
from orm import init_tables
|
||||||
from mgiration.export import export_mdx
|
from migration.export import export_mdx
|
||||||
|
|
||||||
|
|
||||||
TODAY = datetime.strftime(datetime.now(tz=timezone.utc), "%Y%m%d")
|
TODAY = datetime.strftime(datetime.now(tz=timezone.utc), "%Y%m%d")
|
||||||
|
|
|
@ -127,81 +127,82 @@ def set_hidden(session, shout_id):
|
||||||
|
|
||||||
@mutation.field("createReaction")
|
@mutation.field("createReaction")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_reaction(_, info, inp):
|
async def create_reaction(_, info, reaction={}):
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
reaction = Reaction.create(**inp)
|
r = Reaction.create(**reaction)
|
||||||
session.add(reaction)
|
session.add(r)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
# self-regulation mechanics
|
# self-regulation mechanics
|
||||||
|
|
||||||
if check_to_hide(session, auth.user_id, reaction):
|
if check_to_hide(session, auth.user_id, r):
|
||||||
set_hidden(session, reaction.shout)
|
set_hidden(session, r.shout)
|
||||||
elif check_to_publish(session, auth.user_id, reaction):
|
elif check_to_publish(session, auth.user_id, r):
|
||||||
set_published(session, reaction.shout, reaction.createdBy)
|
set_published(session, r.shout, r.createdBy)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reactions_follow(auth.user_id, inp["shout"], True)
|
reactions_follow(auth.user_id, reaction["shout"], True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[resolvers.reactions] error on reactions autofollowing: {e}")
|
print(f"[resolvers.reactions] error on reactions autofollowing: {e}")
|
||||||
|
|
||||||
reaction.stat = {
|
r.stat = {
|
||||||
"commented": 0,
|
"commented": 0,
|
||||||
"reacted": 0,
|
"reacted": 0,
|
||||||
"rating": 0
|
"rating": 0
|
||||||
}
|
}
|
||||||
return {"reaction": reaction}
|
return {"reaction": r}
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("updateReaction")
|
@mutation.field("updateReaction")
|
||||||
@login_required
|
@login_required
|
||||||
async def update_reaction(_, info, inp):
|
async def update_reaction(_, info, reaction={}):
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).where(User.id == auth.user_id).first()
|
user = session.query(User).where(User.id == auth.user_id).first()
|
||||||
q = select(Reaction).filter(Reaction.id == inp.id)
|
q = select(Reaction).filter(Reaction.id == reaction['id'])
|
||||||
q = add_reaction_stat_columns(q)
|
q = add_reaction_stat_columns(q)
|
||||||
|
|
||||||
[reaction, reacted_stat, commented_stat, rating_stat] = session.execute(q).unique().one()
|
[r, reacted_stat, commented_stat, rating_stat] = session.execute(q).unique().one()
|
||||||
|
|
||||||
if not reaction:
|
if not r:
|
||||||
return {"error": "invalid reaction id"}
|
return {"error": "invalid reaction id"}
|
||||||
if reaction.createdBy != user.slug:
|
if r.createdBy != user.slug:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
|
|
||||||
reaction.body = inp["body"]
|
r.body = reaction["body"]
|
||||||
reaction.updatedAt = datetime.now(tz=timezone.utc)
|
r.updatedAt = datetime.now(tz=timezone.utc)
|
||||||
if reaction.kind != inp["kind"]:
|
if r.kind != reaction["kind"]:
|
||||||
# NOTE: change mind detection can be here
|
# NOTE: change mind detection can be here
|
||||||
pass
|
pass
|
||||||
if inp.get("range"):
|
if reaction.get("range"):
|
||||||
reaction.range = inp.get("range")
|
r.range = reaction.get("range")
|
||||||
session.commit()
|
session.commit()
|
||||||
reaction.stat = {
|
r.stat = {
|
||||||
"commented": commented_stat,
|
"commented": commented_stat,
|
||||||
"reacted": reacted_stat,
|
"reacted": reacted_stat,
|
||||||
"rating": rating_stat
|
"rating": rating_stat
|
||||||
}
|
}
|
||||||
|
|
||||||
return {"reaction": reaction}
|
return {"reaction": r}
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("deleteReaction")
|
@mutation.field("deleteReaction")
|
||||||
@login_required
|
@login_required
|
||||||
async def delete_reaction(_, info, rid):
|
async def delete_reaction(_, info, reaction=None):
|
||||||
|
# NOTE: reaction is id
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).where(User.id == auth.user_id).first()
|
user = session.query(User).where(User.id == auth.user_id).first()
|
||||||
reaction = session.query(Reaction).filter(Reaction.id == rid).first()
|
r = session.query(Reaction).filter(Reaction.id == reaction).first()
|
||||||
if not reaction:
|
if not r:
|
||||||
return {"error": "invalid reaction id"}
|
return {"error": "invalid reaction id"}
|
||||||
if reaction.createdBy != user.slug:
|
if r.createdBy != user.slug:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
reaction.deletedAt = datetime.now(tz=timezone.utc)
|
r.deletedAt = datetime.now(tz=timezone.utc)
|
||||||
session.commit()
|
session.commit()
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ input TopicInput {
|
||||||
|
|
||||||
input ReactionInput {
|
input ReactionInput {
|
||||||
kind: Int!
|
kind: Int!
|
||||||
shout: String!
|
shout: Int!
|
||||||
range: String
|
range: String
|
||||||
body: String
|
body: String
|
||||||
replyTo: Int
|
replyTo: Int
|
||||||
|
@ -187,7 +187,7 @@ type Mutation {
|
||||||
# reactions
|
# reactions
|
||||||
createReaction(reaction: ReactionInput!): Result!
|
createReaction(reaction: ReactionInput!): Result!
|
||||||
updateReaction(reaction: ReactionInput!): Result!
|
updateReaction(reaction: ReactionInput!): Result!
|
||||||
deleteReaction(id: Int!): Result!
|
deleteReaction(reaction: Int!): Result!
|
||||||
|
|
||||||
# collab
|
# collab
|
||||||
inviteCoauthor(author: String!, shout: Int!): Result!
|
inviteCoauthor(author: String!, shout: Int!): Result!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user