diff options
author | Victor Shyba <victor.shyba@gmail.com> | 2015-11-23 19:51:12 -0300 |
---|---|---|
committer | Victor Shyba <victor.shyba@gmail.com> | 2015-11-23 19:51:12 -0300 |
commit | 27e3ca71f920083e8bf1599facc2cc4638f8efcf (patch) | |
tree | 2b1da538e01c110df510ab58b766106124abfc48 /service/pixelated/resources | |
parent | 82c16b35798537302fecbf40ed76b0051e23ddb3 (diff) |
Return 422 if deletion failed
This is needed for protecting against concurrent saves on drafts.
--Issue #512
Diffstat (limited to 'service/pixelated/resources')
-rw-r--r-- | service/pixelated/resources/mails_resource.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py index 201350b6..34dd042a 100644 --- a/service/pixelated/resources/mails_resource.py +++ b/service/pixelated/resources/mails_resource.py @@ -183,11 +183,17 @@ class MailsResource(Resource): err(error, 'error saving draft') respond_json_deferred("", request, status_code=422) + def updateCallback(pixelated_mail): + if not pixelated_mail: + respond_json_deferred("", request, status_code=422) + else: + respond_json_deferred({'ident': pixelated_mail.ident}, request) + if draft_id: deferred = self._draft_service.update_draft(draft_id, _mail) else: deferred = self._draft_service.create_draft(_mail) - deferred.addCallback(lambda pixelated_mail: respond_json_deferred({'ident': pixelated_mail.ident}, request)) + deferred.addCallback(updateCallback) deferred.addErrback(onError) return server.NOT_DONE_YET |