2016-05-18 18:19:25 -04:00
|
|
|
|
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-06-15 03:54:04 -04:00
|
|
|
attr_reader :project_path, :authentication_token
|
2016-05-23 10:16:40 -04:00
|
|
|
|
|
|
|
def initialize(mail, mail_key)
|
|
|
|
super(mail, mail_key)
|
2016-06-15 03:54:04 -04:00
|
|
|
@project_path, @authentication_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?
|
2016-06-15 04:15:49 -04:00
|
|
|
!authentication_token.nil?
|
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-05-21 12:46:27 -04:00
|
|
|
verify_record!(
|
2016-05-18 18:19:25 -04:00
|
|
|
create_issue,
|
|
|
|
InvalidIssueError,
|
|
|
|
"The issue could not be created for the following reasons:"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def author
|
2016-05-20 18:38:08 -04:00
|
|
|
@author ||= User.find_by(authentication_token: authentication_token)
|
2016-05-18 18:19:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
2016-06-15 03:54:04 -04:00
|
|
|
@project ||= Project.find_with_namespace(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,
|
|
|
|
description: message
|
|
|
|
).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|