get-my-shout-debug
This commit is contained in:
parent
94bf54b192
commit
883e98c3d3
|
@ -21,12 +21,12 @@ from services.search import search_service
|
||||||
@query.field("get_my_shout")
|
@query.field("get_my_shout")
|
||||||
@login_required
|
@login_required
|
||||||
async def get_my_shout(_, info, shout_id: int):
|
async def get_my_shout(_, info, shout_id: int):
|
||||||
with local_session() as session:
|
|
||||||
user_id = info.context.get("user_id", "")
|
user_id = info.context.get("user_id", "")
|
||||||
author_dict = info.context.get("author", {})
|
author_dict = info.context.get("author", {})
|
||||||
author_id = author_dict.get("id")
|
author_id = author_dict.get("id")
|
||||||
if not user_id:
|
if not user_id or not author_id:
|
||||||
return {"error": "unauthorized", "shout": None}
|
return {"error": "unauthorized", "shout": None}
|
||||||
|
with local_session() as session:
|
||||||
shout = (
|
shout = (
|
||||||
session.query(Shout)
|
session.query(Shout)
|
||||||
.filter(Shout.id == shout_id)
|
.filter(Shout.id == shout_id)
|
||||||
|
@ -41,7 +41,9 @@ async def get_my_shout(_, info, shout_id: int):
|
||||||
return {"error": "no author found", "shout": None}
|
return {"error": "no author found", "shout": None}
|
||||||
roles = info.context.get("roles", [])
|
roles = info.context.get("roles", [])
|
||||||
is_editor = "editor" in roles
|
is_editor = "editor" in roles
|
||||||
|
logger.debug('viewer is editor')
|
||||||
is_author = filter(lambda x: x.id == int(author_id), [x for x in shout.authors])
|
is_author = filter(lambda x: x.id == int(author_id), [x for x in shout.authors])
|
||||||
|
logger.debug('viewer is author')
|
||||||
can_edit = is_editor or is_author
|
can_edit = is_editor or is_author
|
||||||
if not can_edit:
|
if not can_edit:
|
||||||
return {"error": "forbidden", "shout": None}
|
return {"error": "forbidden", "shout": None}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user