context user fix

This commit is contained in:
Igor Lobanov
2022-12-01 15:45:19 +01:00
parent 8464398aaf
commit 25924ac136
13 changed files with 190 additions and 174 deletions

View File

@@ -1,4 +1,5 @@
from auth.authenticate import login_required
from auth.credentials import AuthCredentials
from base.resolvers import mutation
# from resolvers.community import community_follow, community_unfollow
from resolvers.zine.profile import author_follow, author_unfollow
@@ -9,17 +10,18 @@ from resolvers.zine.topics import topic_follow, topic_unfollow
@mutation.field("follow")
@login_required
async def follow(_, info, what, slug):
user = info.context["request"].user
auth: AuthCredentials = info.context["request"].auth
try:
if what == "AUTHOR":
author_follow(user, slug)
author_follow(auth.user_id, slug)
elif what == "TOPIC":
topic_follow(user, slug)
topic_follow(auth.user_id, slug)
elif what == "COMMUNITY":
# community_follow(user, slug)
pass
elif what == "REACTIONS":
reactions_follow(user, slug)
reactions_follow(auth.user_id, slug)
except Exception as e:
return {"error": str(e)}
@@ -29,18 +31,18 @@ async def follow(_, info, what, slug):
@mutation.field("unfollow")
@login_required
async def unfollow(_, info, what, slug):
user = info.context["request"].user
auth: AuthCredentials = info.context["request"].auth
try:
if what == "AUTHOR":
author_unfollow(user, slug)
author_unfollow(auth.user_id, slug)
elif what == "TOPIC":
topic_unfollow(user, slug)
topic_unfollow(auth.user_id, slug)
elif what == "COMMUNITY":
# community_unfollow(user, slug)
pass
elif what == "REACTIONS":
reactions_unfollow(user, slug)
reactions_unfollow(auth.user_id, slug)
except Exception as e:
return {"error": str(e)}