collab invite/remove author, topics migration fix

This commit is contained in:
2022-06-22 08:28:42 +03:00
parent ace22f5e8b
commit f92be99bce
10 changed files with 72 additions and 10 deletions

View File

@@ -7,7 +7,8 @@ from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_autho
topics_by_community, topics_by_slugs
from resolvers.comments import create_comment, delete_comment, update_comment, rate_comment
from resolvers.collab import get_shout_proposals, create_proposal, delete_proposal, \
update_proposal, rate_proposal, decline_proposal, disable_proposal, accept_proposal
update_proposal, rate_proposal, decline_proposal, disable_proposal, accept_proposal, \
invite_author, remove_author
from resolvers.editor import create_shout, delete_shout, update_shout
from resolvers.community import create_community, delete_community, get_community, get_communities
@@ -72,5 +73,7 @@ __all__ = [
"disable_proposal",
"accept_proposal",
"decline_proposal",
"delete_proposal"
"delete_proposal",
"invite_author",
"remove_author"
]

View File

@@ -189,3 +189,56 @@ async def decline_proposal(_, info, id):
await ProposalStorage.put(result)
return {}
@mutation.field("inviteAuthor")
@login_required
async def invite_author(_, author_slug, shout):
auth = info.context["request"].auth
user_id = auth.user_id
with local_session() as session:
shout = session.query(Shout).filter(Shout.slug == shout).first()
if not shout:
return {"error": "invalid shout slug"}
authors = [author.id for author in shout.authors]
if user_id not in authors:
return {"error": "access denied"}
author = session.query(User).filter(User.slug == author_slug).first()
if author.id in authors:
return {"error": "already added"}
shout.authors.append(author)
session.commit()
# result = Result("INVITED")
# FIXME: await ShoutStorage.put(result)
# TODO: email notify
return {}
@mutation.field("removeAuthor")
@login_required
async def invite_author(_, author_slug, shout):
auth = info.context["request"].auth
user_id = auth.user_id
with local_session() as session:
shout = session.query(Shout).filter(Shout.slug == shout).first()
if not shout:
return {"error": "invalid shout slug"}
authors = [author.id for author in shout.authors]
if user_id not in authors:
return {"error": "access denied"}
author = session.query(User).filter(User.slug == author_slug).first()
if author.id not in authors:
return {"error": "not in authors"}
shout.authors.remove(author)
session.commit()
# result = Result("INVITED")
# FIXME: await ShoutStorage.put(result)
# TODO: email notify
return {}