This commit is contained in:
@@ -7,7 +7,7 @@ from sqlalchemy.orm import aliased, joinedload
|
||||
from orm.author import Author
|
||||
from orm.reaction import Reaction, ReactionKind
|
||||
from orm.shout import Shout, ShoutReactionsFollower
|
||||
from services.auth import login_required
|
||||
from services.auth import login_required, add_author_role
|
||||
from services.db import local_session
|
||||
from services.notify import notify_reaction
|
||||
from services.schema import mutation, query
|
||||
@@ -98,18 +98,18 @@ def is_published_author(session, author_id):
|
||||
)
|
||||
|
||||
|
||||
def check_to_publish(session, author_id, reaction):
|
||||
def check_to_publish(session, approver_id, reaction):
|
||||
"""set shout to public if publicated approvers amount > 4"""
|
||||
if not reaction.reply_to and reaction.kind in [
|
||||
ReactionKind.ACCEPT.value,
|
||||
ReactionKind.LIKE.value,
|
||||
ReactionKind.PROOF.value,
|
||||
]:
|
||||
if is_published_author(session, author_id):
|
||||
if is_published_author(session, approver_id):
|
||||
# now count how many approvers are voted already
|
||||
approvers_reactions = session.query(Reaction).where(Reaction.shout == reaction.shout).all()
|
||||
approvers = [
|
||||
author_id,
|
||||
approver_id,
|
||||
]
|
||||
for ar in approvers_reactions:
|
||||
a = ar.created_by
|
||||
@@ -142,10 +142,12 @@ def check_to_hide(session, reaction):
|
||||
return False
|
||||
|
||||
|
||||
def set_published(session, shout_id):
|
||||
def set_published(session, shout_id, approver_id):
|
||||
s = session.query(Shout).where(Shout.id == shout_id).first()
|
||||
s.published_at = int(time.time())
|
||||
s.published_by = approver_id
|
||||
s.visibility = text("public")
|
||||
add_author_role(s.created_by)
|
||||
session.add(s)
|
||||
session.commit()
|
||||
|
||||
@@ -233,7 +235,7 @@ async def create_reaction(_, info, reaction):
|
||||
if check_to_hide(session, r):
|
||||
set_hidden(session, r.shout)
|
||||
elif check_to_publish(session, author.id, r):
|
||||
set_published(session, r.shout)
|
||||
set_published(session, r.shout, author.id)
|
||||
|
||||
try:
|
||||
reactions_follow(author.id, reaction["shout"], True)
|
||||
|
Reference in New Issue
Block a user