This commit is contained in:
2022-11-30 23:20:08 +03:00
35 changed files with 617 additions and 782 deletions

View File

@@ -1,13 +1,13 @@
from datetime import datetime, timezone
from sqlalchemy import and_
from auth.authenticate import login_required
from base.orm import local_session
from base.resolvers import mutation
from orm.rbac import Resource
from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.collab import Collab
from services.inbox import MessagesStorage
from orm.topic import TopicFollower
from orm.topic import TopicFollower, Topic
from orm.user import User
from resolvers.zine.reactions import reactions_follow, reactions_unfollow
from services.zine.gittask import GitTask
@@ -49,7 +49,7 @@ async def create_shout(_, info, inp):
session.add(new_collab)
# NOTE: shout made by one first author
sa = ShoutAuthor.create(shout=new_shout.slug, user=user.slug)
sa = ShoutAuthor.create(shout=new_shout.id, user=user.id)
session.add(sa)
reactions_follow(user, new_shout.slug, True)
@@ -58,11 +58,16 @@ async def create_shout(_, info, inp):
topic_slugs.append(inp["mainTopic"])
for slug in topic_slugs:
st = ShoutTopic.create(shout=new_shout.slug, topic=slug)
topic = session.query(Topic).where(Topic.slug == slug).one()
st = ShoutTopic.create(shout=new_shout.id, topic=topic.id)
session.add(st)
tf = session.query(TopicFollower).where(follower=user.slug, topic=slug)
tf = session.query(TopicFollower).where(
and_(TopicFollower.follower == user.id, TopicFollower.topic == topic.id)
)
if not tf:
tf = TopicFollower.create(follower=user.slug, topic=slug, auto=True)
tf = TopicFollower.create(follower=user.id, topic=topic.id, auto=True)
session.add(tf)
new_shout.topic_slugs = topic_slugs
@@ -70,7 +75,7 @@ async def create_shout(_, info, inp):
session.commit()
GitTask(inp, user.username, user.email, "new shout %s" % (new_shout.slug))
GitTask(inp, user.username, user.email, "new shout %s" % new_shout.slug)
return {"shout": new_shout}
@@ -92,7 +97,7 @@ async def update_shout(_, info, inp):
if user_id not in authors:
scopes = auth.scopes
print(scopes)
if Resource.shout_id not in scopes:
if Resource.shout not in scopes:
return {"error": "access denied"}
else:
shout.update(inp)
@@ -100,7 +105,7 @@ async def update_shout(_, info, inp):
session.add(shout)
if inp.get("topics"):
# remove old links
links = session.query(ShoutTopic).where(ShoutTopic.shout == slug).all()
links = session.query(ShoutTopic).where(ShoutTopic.shout == shout.id).all()
for topiclink in links:
session.delete(topiclink)
# add new topic links