2018-08-23 05:22:23 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-05-21 12:40:08 -04:00
|
|
|
require 'gitlab/email/handler/base_handler'
|
2016-05-18 18:19:25 -04:00
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Email
|
2016-05-21 12:40:08 -04:00
|
|
|
module Handler
|
|
|
|
class CreateIssueHandler < BaseHandler
|
2016-10-12 13:07:36 -04:00
|
|
|
include ReplyProcessing
|
2016-08-19 19:33:46 -04:00
|
|
|
attr_reader :project_path, :incoming_email_token
|
2016-05-23 10:16:40 -04:00
|
|
|
|
|
|
|
def initialize(mail, mail_key)
|
|
|
|
super(mail, mail_key)
|
2016-08-19 19:33:46 -04:00
|
|
|
@project_path, @incoming_email_token =
|
2016-05-23 10:16:40 -04:00
|
|
|
mail_key && mail_key.split('+', 2)
|
|
|
|
end
|
|
|
|
|
2016-05-18 18:19:25 -04:00
|
|
|
def can_handle?
|
2018-04-09 05:39:03 -04:00
|
|
|
!incoming_email_token.nil? && !incoming_email_token.include?("+") && !mail_key.include?(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX)
|
2016-05-18 18:19:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2016-05-23 13:19:20 -04:00
|
|
|
raise ProjectNotFound unless project
|
2016-06-15 04:16:44 -04:00
|
|
|
|
2016-05-18 18:19:25 -04:00
|
|
|
validate_permission!(:create_issue)
|
|
|
|
|
2016-06-20 07:11:42 -04:00
|
|
|
verify_record!(
|
|
|
|
record: create_issue,
|
|
|
|
invalid_exception: InvalidIssueError,
|
|
|
|
record_name: 'issue')
|
2016-05-18 18:19:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def author
|
2016-08-19 19:33:46 -04:00
|
|
|
@author ||= User.find_by(incoming_email_token: incoming_email_token)
|
2016-05-18 18:19:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
2017-02-02 18:43:19 -05:00
|
|
|
@project ||= Project.find_by_full_path(project_path)
|
2016-05-18 18:19:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-06-15 07:41:31 -04:00
|
|
|
|
2016-05-18 18:19:25 -04:00
|
|
|
def create_issue
|
|
|
|
Issues::CreateService.new(
|
|
|
|
project,
|
|
|
|
author,
|
|
|
|
title: mail.subject,
|
2018-05-09 16:19:16 -04:00
|
|
|
description: message_including_reply
|
2016-05-18 18:19:25 -04:00
|
|
|
).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|