summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-11-23 18:38:50 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-11-23 18:38:50 -0300
commit82c16b35798537302fecbf40ed76b0051e23ddb3 (patch)
tree5f67c7ee22b830508eb25c52db95b7007ba8d7ca
parent958a916cb3ebb6d101cbdbd75473b1b11f30a3e5 (diff)
Simplify controller logic on PUT draft
It was checking for mail existence, but thats redundant since its also checking if draft_id was being sent. Also, its service responsibility to ensure operation consistency, not the controller. --Issue #512
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py5
-rw-r--r--service/pixelated/resources/mails_resource.py20
2 files changed, 6 insertions, 19 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 4348347e..f59034b8 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -289,9 +289,8 @@ class LeapMailStore(MailStore):
@defer.inlineCallbacks
def delete_mail(self, mail_id):
message = yield self._fetch_msg_from_soledad(mail_id)
- message_wrapper = message.get_wrapper()
- if message_wrapper.mdoc.doc_id:
- yield message_wrapper.delete(self.soledad)
+ if message and message.get_wrapper().mdoc.doc_id:
+ yield message.get_wrapper().delete(self.soledad)
@defer.inlineCallbacks
def get_mailbox_mail_ids(self, mailbox_name):
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index 5b5335b9..201350b6 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -183,23 +183,11 @@ class MailsResource(Resource):
err(error, 'error saving draft')
respond_json_deferred("", request, status_code=422)
- def defer_response(deferred):
- deferred.addCallback(lambda pixelated_mail: respond_json_deferred({'ident': pixelated_mail.ident}, request))
- deferred.addErrback(onError)
-
if draft_id:
- deferred_check = self._mail_service.mail_exists(draft_id)
-
- def return422otherwise(mail_exists):
- if not mail_exists:
- respond_json_deferred("", request, status_code=422)
- else:
- new_draft = self._draft_service.update_draft(draft_id, _mail)
- new_draft.addErrback(onError)
- defer_response(new_draft)
-
- deferred_check.addCallback(return422otherwise)
+ deferred = self._draft_service.update_draft(draft_id, _mail)
else:
- defer_response(self._draft_service.create_draft(_mail))
+ deferred = self._draft_service.create_draft(_mail)
+ deferred.addCallback(lambda pixelated_mail: respond_json_deferred({'ident': pixelated_mail.ident}, request))
+ deferred.addErrback(onError)
return server.NOT_DONE_YET