[email] Return 201 only if message is accepted

This commit is contained in:
maike 2020-07-06 15:14:10 +02:00 committed by dl6tom
parent 3e565caf69
commit 1aad0b30e1
2 changed files with 5 additions and 16 deletions

View file

@ -5,8 +5,6 @@
from kibicara.platforms.email.model import EmailRecipients, Email from kibicara.platforms.email.model import EmailRecipients, Email
from kibicara.platformapi import Censor, Spawner, Message from kibicara.platformapi import Censor, Spawner, Message
from logging import getLogger from logging import getLogger
import email
import datetime
logger = getLogger(__name__) logger = getLogger(__name__)

View file

@ -49,21 +49,10 @@ async def test_create(response: Response, hood=Depends(get_hood)):
@router.get('/{test_id}') @router.get('/{test_id}')
async def test_read(test=Depends(get_email_bot)): async def test_read(test=Depends(get_email_bot)):
return test return test
@router.delete('/{test_id}', status_code=status.HTTP_204_NO_CONTENT)
async def test_delete(test=Depends(get_email_bot)):
spawner.stop(test)
await test.delete()
@router.get('/{test_id}/messages/')
async def test_message_read_all(test=Depends(get_email_bot)):
return spawner.get(test).messages
""" """
@router.post('/messages/', status_code=status.HTTP_201_CREATED) @router.post('/messages/')
async def email_message_create(message: BodyMessage): async def email_message_create(message: BodyMessage):
# get bot via "To:" header # get bot via "To:" header
email_bot = await get_email_bot(message.to) email_bot = await get_email_bot(message.to)
@ -71,5 +60,7 @@ async def email_message_create(message: BodyMessage):
if message.secret is not email_bot.secret: if message.secret is not email_bot.secret:
return status.HTTP_401_UNAUTHORIZED return status.HTTP_401_UNAUTHORIZED
# pass message.text to bot.py # pass message.text to bot.py
await spawner.get(email_bot).publish(Message(message.text)) if await spawner.get(email_bot).publish(Message(message.text)):
#return {} # why is this important? return status.HTTP_201_CREATED
else:
return status.HTTP_406_NOT_ACCEPTABLE