This commit is contained in:
parent
01d7dadd78
commit
a241a098b9
|
@ -57,13 +57,14 @@ async def reject_invite(_, info, invite_id: int):
|
||||||
|
|
||||||
@mutation.field("create_invite")
|
@mutation.field("create_invite")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_invite(_, info, slug: str = "", author_id: int = None, user: str = ""):
|
async def create_invite(_, info, slug: str = "", author_id: int = None):
|
||||||
user_id = info.context["user_id"]
|
user_id = info.context["user_id"]
|
||||||
|
|
||||||
# Check if the inviter is the owner of the shout
|
# Check if the inviter is the owner of the shout
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
||||||
if shout and shout.authors and user_id in [author.id for author in shout.authors]:
|
inviter = session.query(Author).filter(Author.user == user_id).first()
|
||||||
|
if inviter and shout and shout.authors and inviter.id == shout.authors[0]:
|
||||||
# Check if the author is a valid author
|
# Check if the author is a valid author
|
||||||
author = session.query(Author).filter(Author.id == author_id).first()
|
author = session.query(Author).filter(Author.id == author_id).first()
|
||||||
if author:
|
if author:
|
||||||
|
@ -71,7 +72,7 @@ async def create_invite(_, info, slug: str = "", author_id: int = None, user: st
|
||||||
existing_invite = (
|
existing_invite = (
|
||||||
session.query(Invite)
|
session.query(Invite)
|
||||||
.filter(
|
.filter(
|
||||||
Invite.inviter_id == user_id,
|
Invite.inviter_id == inviter.id,
|
||||||
Invite.author_id == author_id,
|
Invite.author_id == author_id,
|
||||||
Invite.shout_id == shout.id,
|
Invite.shout_id == shout.id,
|
||||||
Invite.status == InviteStatus.PENDING,
|
Invite.status == InviteStatus.PENDING,
|
||||||
|
@ -97,14 +98,14 @@ async def create_invite(_, info, slug: str = "", author_id: int = None, user: st
|
||||||
|
|
||||||
@mutation.field("remove_author")
|
@mutation.field("remove_author")
|
||||||
@login_required
|
@login_required
|
||||||
async def remove_author(_, info, slug: str = "", author_id: int = None, user: str = ""):
|
async def remove_author(_, info, slug: str = "", author_id: int = None):
|
||||||
user_id = info.context["user_id"]
|
user_id = info.context["user_id"]
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
author = session.query(Author).filter(Author.user == user_id).first()
|
author = session.query(Author).filter(Author.user == user_id).first()
|
||||||
if author:
|
if author:
|
||||||
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
||||||
# NOTE: owner should be first in a list
|
# NOTE: owner should be first in a list
|
||||||
if shout and author.id == shout.authors.index(0):
|
if shout and author.id == shout.authors[0]:
|
||||||
shout.authors = [author for author in shout.authors if author.id != author_id]
|
shout.authors = [author for author in shout.authors if author.id != author_id]
|
||||||
session.commit()
|
session.commit()
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -329,8 +329,8 @@ type Mutation {
|
||||||
delete_reaction(id: Int!): Result!
|
delete_reaction(id: Int!): Result!
|
||||||
|
|
||||||
# collab
|
# collab
|
||||||
create_invite(slug: String, author_id: Int, user: String): Result!
|
create_invite(slug: String, author_id: Int): Result!
|
||||||
remove_author(slug: String, author_id: Int, user: String): Result!
|
remove_author(slug: String, author_id: Int): Result!
|
||||||
remove_invite(invite_id: Int!): Result!
|
remove_invite(invite_id: Int!): Result!
|
||||||
accept_invite(invite_id: Int!): Result!
|
accept_invite(invite_id: Int!): Result!
|
||||||
reject_invite(invite_id: Int!): Result!
|
reject_invite(invite_id: Int!): Result!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user