2016-05-18 18:19:25 -04:00
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
raise AutoGeneratedEmailError if mail.header.to_s =~ /auto-(generated|replied)/
|
|
|
|
|
|
|
|
validate_permission!(:create_note)
|
|
|
|
|
|
|
|
raise NoteableNotFoundError unless sent_notification.noteable
|
|
|
|
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
|
|
|
|
|
2016-10-12 13:07:36 -04:00
|
|
|
private
|
|
|
|
|
2016-05-18 18:19:25 -04:00
|
|
|
def author
|
|
|
|
sent_notification.recipient
|
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
|
|
|
sent_notification.project
|
|
|
|
end
|
|
|
|
|
|
|
|
def sent_notification
|
|
|
|
@sent_notification ||= SentNotification.for(mail_key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_note
|
|
|
|
Notes::CreateService.new(
|
|
|
|
project,
|
|
|
|
author,
|
|
|
|
note: message,
|
|
|
|
noteable_type: sent_notification.noteable_type,
|
|
|
|
noteable_id: sent_notification.noteable_id,
|
|
|
|
commit_id: sent_notification.commit_id,
|
2016-10-20 04:16:57 -04:00
|
|
|
line_code: sent_notification.line_code,
|
|
|
|
position: sent_notification.position,
|
|
|
|
type: sent_notification.note_type
|
2016-05-18 18:19:25 -04:00
|
|
|
).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|