2016-05-21 12:40:08 -04:00
|
|
|
require 'gitlab/email/handler/base_handler'
|
2016-10-12 13:07:36 -04:00
|
|
|
require 'gitlab/email/handler/reply_processing'
|
2016-05-18 18:19:25 -04:00
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Email
|
2016-05-21 12:40:08 -04:00
|
|
|
module Handler
|
|
|
|
class CreateNoteHandler < BaseHandler
|
2016-10-12 13:07:36 -04:00
|
|
|
include ReplyProcessing
|
|
|
|
|
2017-04-20 06:33:51 -04:00
|
|
|
delegate :project, to: :sent_notification, allow_nil: true
|
2018-05-03 17:32:20 -04:00
|
|
|
delegate :noteable, to: :sent_notification
|
2017-04-20 06:33:51 -04:00
|
|
|
|
2016-05-18 18:19:25 -04:00
|
|
|
def can_handle?
|
2016-06-20 07:15:54 -04:00
|
|
|
mail_key =~ /\A\w+\z/
|
2016-05-18 18:19:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
raise SentNotificationNotFoundError unless sent_notification
|
|
|
|
|
|
|
|
validate_permission!(:create_note)
|
|
|
|
|
2018-05-03 17:32:20 -04:00
|
|
|
raise NoteableNotFoundError unless noteable
|
2016-05-18 18:19:25 -04:00
|
|
|
raise EmptyEmailError if message.blank?
|
|
|
|
|
2016-06-20 07:11:42 -04:00
|
|
|
verify_record!(
|
|
|
|
record: create_note,
|
|
|
|
invalid_exception: InvalidNoteError,
|
|
|
|
record_name: 'comment')
|
2016-05-18 18:19:25 -04:00
|
|
|
end
|
|
|
|
|
2017-04-21 11:11:21 -04:00
|
|
|
def metrics_params
|
2017-05-05 05:33:41 -04:00
|
|
|
super.merge(project: project&.full_path)
|
2017-04-21 11:11:21 -04:00
|
|
|
end
|
|
|
|
|
2016-10-12 13:07:36 -04:00
|
|
|
private
|
|
|
|
|
2016-05-18 18:19:25 -04:00
|
|
|
def author
|
|
|
|
sent_notification.recipient
|
|
|
|
end
|
|
|
|
|
|
|
|
def sent_notification
|
|
|
|
@sent_notification ||= SentNotification.for(mail_key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_note
|
2017-03-17 15:25:52 -04:00
|
|
|
sent_notification.create_reply(message)
|
2016-05-18 18:19:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|