summaryrefslogtreecommitdiff
path: root/lib/gitlab/email/handler.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/email/handler.rb')
-rw-r--r--lib/gitlab/email/handler.rb57
1 files changed, 9 insertions, 48 deletions
diff --git a/lib/gitlab/email/handler.rb b/lib/gitlab/email/handler.rb
index 56d848cdd7b..b9221f1210c 100644
--- a/lib/gitlab/email/handler.rb
+++ b/lib/gitlab/email/handler.rb
@@ -1,54 +1,15 @@
+require 'gitlab/email/handler/create_note_handler'
+require 'gitlab/email/handler/create_issue_handler'
+
module Gitlab
module Email
- class Handler
- attr_reader :mail, :mail_key
-
- def initialize(mail, mail_key)
- @mail = mail
- @mail_key = mail_key
- end
-
- def message
- @message ||= process_message
- end
-
- def author
- raise NotImplementedError
- end
-
- def project
- raise NotImplementedError
- end
-
- private
- def validate_permission!(permission)
- raise UserNotFoundError unless author
- raise UserBlockedError if author.blocked?
- raise ProjectNotFound unless author.can?(:read_project, project)
- raise UserNotAuthorizedError unless author.can?(permission, project)
- end
-
- def process_message
- add_attachments(ReplyParser.new(mail).execute.strip)
- end
-
- def add_attachments(reply)
- attachments = Email::AttachmentUploader.new(mail).execute(project)
-
- reply + attachments.map do |link|
- "\n\n#{link[:markdown]}"
- end.join
- end
-
- def verify_record(record, exception, error_title)
- return if record.persisted?
-
- msg = error_title + record.errors.full_messages.map do |error|
- "\n\n- #{error}"
- end.join
-
- raise exception, msg
+ module Handler
+ def self.for(mail, mail_key)
+ [CreateNoteHandler, CreateIssueHandler].find do |klass|
+ handler = klass.new(mail, mail_key)
+ break handler if handler.can_handle?
+ end
end
end
end