create-reaction-unauthorized-handling
All checks were successful
Deploy on push / deploy (push) Successful in 26s

This commit is contained in:
Untone 2024-05-18 12:38:46 +03:00
parent c80229b7b9
commit 0f5df77d28
3 changed files with 15 additions and 12 deletions

View File

@ -207,7 +207,8 @@ async def create_reaction(_, info, reaction):
info.context.get("user_id")
author_id = info.context.get("author", {}).get("id")
shout_id = reaction.get("shout")
if not author_id:
return {"error": "Unauthorized"}
if not shout_id:
return {"error": "Shout ID is required to create a reaction."}

View File

@ -20,7 +20,10 @@ REDIS_TTL = 86400 # 1 день в секундах
index_settings = {
"settings": {
"index": {"number_of_shards": 1, "auto_expand_replicas": "0-all"},
"index": {
"number_of_shards": 1,
"auto_expand_replicas": "0-all"
},
"analysis": {
"analyzer": {
"ru": {
@ -37,13 +40,13 @@ index_settings = {
"mappings": {
"properties": {
"body": {"type": "text", "analyzer": "ru"},
#"cover": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
#"created_at": {"type": "long"},
#"created_by": {"type": "long"},
#"featured_at": {"type": "long"},
#"id": {"type": "long"},
#"lang": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
#"layout": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
# "cover": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
# "created_at": {"type": "long"},
# "created_by": {"type": "long"},
# "featured_at": {"type": "long"},
# "id": {"type": "long"},
# "lang": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
# "layout": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
"lead": {"type": "text", "analyzer": "ru"},
"media": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
# "oid": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},

View File

@ -94,9 +94,8 @@ def after_reaction_update(mapper, connection, reaction: Reaction):
for author_with_stat in get_with_stat(author_query):
asyncio.create_task(cache_author(author_with_stat.dict()))
shout = connection.execute(
select(Shout).select_from(Shout).where(Shout.id == reaction.shout)
).first()
shout_query = select(Shout).select_from(Shout).where(Shout.id == reaction.shout)
[shout] = connection.execute(shout_query)
if shout:
after_shout_update(mapper, connection, shout)
except Exception as exc: