From 76dbafba86dda96b7ba2f93fc7e07eea3ca48302 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 19 Aug 2015 11:10:21 -0700 Subject: Send a rejection email when the incoming email couldn't be processed. --- lib/gitlab/email_receiver.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email_receiver.rb b/lib/gitlab/email_receiver.rb index 3dd8942a262..a0b4ff87e02 100644 --- a/lib/gitlab/email_receiver.rb +++ b/lib/gitlab/email_receiver.rb @@ -5,7 +5,7 @@ module Gitlab class EmailUnparsableError < ProcessingError; end class EmptyEmailError < ProcessingError; end class UserNotFoundError < ProcessingError; end - class UserNotAuthorizedLevelError < ProcessingError; end + class UserNotAuthorizedError < ProcessingError; end class NoteableNotFoundError < ProcessingError; end class AutoGeneratedEmailError < ProcessingError; end class SentNotificationNotFound < ProcessingError; end @@ -21,20 +21,20 @@ module Gitlab raise EmailUnparsableError, e end - def process + def execute + raise SentNotificationNotFound unless sent_notification + raise EmptyEmailError if @raw.blank? raise AutoGeneratedEmailError if message.header.to_s =~ /auto-(generated|replied)/ - raise SentNotificationNotFound unless sent_notification - author = sent_notification.recipient raise UserNotFoundError unless author project = sent_notification.project - raise UserNotAuthorizedLevelError unless author.can?(:create_note, project) + raise UserNotAuthorizedError unless author.can?(:create_note, project) raise NoteableNotFoundError unless sent_notification.noteable @@ -54,7 +54,11 @@ module Gitlab ).execute unless note.persisted? - raise InvalidNote, note.errors.full_messages.join("\n") + message = "The comment could not be created for the following reasons:" + note.errors.full_messages.each do |error| + message << "\n\n- #{error}" + end + raise InvalidNote, message end end -- cgit v1.2.1