diff options
author | Jefferson Stachelski <jstachel@thoughtworks.com> | 2015-09-25 19:05:01 -0300 |
---|---|---|
committer | Jefferson Stachelski <jstachel@thoughtworks.com> | 2015-09-25 19:06:48 -0300 |
commit | 6df9e2c2646975ffc7c312f675591870eb4b2ad8 (patch) | |
tree | c1251c6d4710240fd78b4ba24f10120ac9d300f8 /service/pixelated/adapter | |
parent | d186b0204f738367d530514707d0f95a6d4bf865 (diff) |
Issue #470 handling the update draft
Deleting the new draft created if the old one was not found to fix the
duplication drafts
Diffstat (limited to 'service/pixelated/adapter')
-rw-r--r-- | service/pixelated/adapter/errors/__init__.py | 3 | ||||
-rw-r--r-- | service/pixelated/adapter/services/draft_service.py | 13 |
2 files changed, 14 insertions, 2 deletions
diff --git a/service/pixelated/adapter/errors/__init__.py b/service/pixelated/adapter/errors/__init__.py new file mode 100644 index 00000000..31ad4947 --- /dev/null +++ b/service/pixelated/adapter/errors/__init__.py @@ -0,0 +1,3 @@ +class DuplicatedDraftException(Exception): + def __init__(self, message): + super(Exception, self).__init__(message) diff --git a/service/pixelated/adapter/services/draft_service.py b/service/pixelated/adapter/services/draft_service.py index c3a14928..65794f04 100644 --- a/service/pixelated/adapter/services/draft_service.py +++ b/service/pixelated/adapter/services/draft_service.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from twisted.internet import defer +from pixelated.adapter.errors import DuplicatedDraftException class DraftService(object): @@ -32,8 +33,16 @@ class DraftService(object): @defer.inlineCallbacks def update_draft(self, ident, input_mail): new_draft = yield self.create_draft(input_mail) - yield self._mail_store.delete_mail(ident) - defer.returnValue(new_draft) + try: + yield self._mail_store.delete_mail(ident) + defer.returnValue(new_draft) + except Exception as error: + errorMessage = error.args[0].getErrorMessage() + + if errorMessage == 'Need to create doc before deleting': + yield self._mail_store.delete_mail(new_draft.ident) + raise DuplicatedDraftException(errorMessage) + # pixelated_mail = yield self.create_draft(input_mail) # yield (yield self._mailboxes.drafts).remove(ident) # defer.returnValue(pixelated_mail) |