2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-02 06:38:35 -04:00
|
|
|
module Issues
|
2014-04-02 12:55:23 -04:00
|
|
|
class CreateService < Issues::BaseService
|
2017-02-27 12:12:52 -05:00
|
|
|
include ResolveDiscussions
|
2017-02-14 14:07:11 -05:00
|
|
|
|
2020-09-08 17:08:53 -04:00
|
|
|
def execute(skip_system_notes: false)
|
2021-01-27 04:09:01 -05:00
|
|
|
@request = params.delete(:request)
|
|
|
|
@spam_params = Spam::SpamActionService.filter_spam_params!(params)
|
|
|
|
|
2017-03-07 19:20:05 -05:00
|
|
|
@issue = BuildService.new(project, current_user, params).execute
|
|
|
|
|
2017-02-27 12:12:52 -05:00
|
|
|
filter_resolve_discussion_params
|
2014-04-02 06:38:35 -04:00
|
|
|
|
2020-09-08 17:08:53 -04:00
|
|
|
create(@issue, skip_system_notes: skip_system_notes)
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
|
2017-02-14 14:07:11 -05:00
|
|
|
def before_create(issue)
|
2021-01-27 04:09:01 -05:00
|
|
|
Spam::SpamActionService.new(
|
|
|
|
spammable: issue,
|
|
|
|
request: request,
|
|
|
|
user: current_user,
|
|
|
|
action: :create
|
|
|
|
).execute(spam_params: spam_params)
|
2017-08-01 08:38:45 -04:00
|
|
|
|
2017-08-08 03:41:27 -04:00
|
|
|
# current_user (defined in BaseService) is not available within run_after_commit block
|
2017-08-01 08:38:45 -04:00
|
|
|
user = current_user
|
|
|
|
issue.run_after_commit do
|
|
|
|
NewIssueWorker.perform_async(issue.id, user.id)
|
2020-09-16 08:10:15 -04:00
|
|
|
IssuePlacementWorker.perform_async(nil, issue.project_id)
|
2017-08-01 08:38:45 -04:00
|
|
|
end
|
2016-08-16 20:59:55 -04:00
|
|
|
end
|
|
|
|
|
2020-09-14 11:09:28 -04:00
|
|
|
def after_create(issue)
|
|
|
|
add_incident_label(issue)
|
|
|
|
todo_service.new_issue(issue, current_user)
|
2016-08-16 18:49:53 -04:00
|
|
|
user_agent_detail_service.create
|
2020-09-14 11:09:28 -04:00
|
|
|
resolve_discussions_with_issue(issue)
|
|
|
|
delete_milestone_total_issue_counter_cache(issue.milestone)
|
|
|
|
track_incident_action(current_user, issue, :incident_created)
|
2017-08-17 11:21:25 -04:00
|
|
|
|
|
|
|
super
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2017-03-07 19:30:43 -05:00
|
|
|
def resolve_discussions_with_issue(issue)
|
|
|
|
return if discussions_to_resolve.empty?
|
|
|
|
|
|
|
|
Discussions::ResolveService.new(project, current_user,
|
2020-05-27 02:08:13 -04:00
|
|
|
one_or_more_discussions: discussions_to_resolve,
|
|
|
|
follow_up_issue: issue).execute
|
2017-03-07 19:30:43 -05:00
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:53 -04:00
|
|
|
private
|
|
|
|
|
2021-01-27 04:09:01 -05:00
|
|
|
attr_reader :request, :spam_params
|
|
|
|
|
2016-07-30 00:18:32 -04:00
|
|
|
def user_agent_detail_service
|
2021-01-27 04:09:01 -05:00
|
|
|
UserAgentDetailService.new(@issue, request)
|
2016-07-21 19:11:53 -04:00
|
|
|
end
|
2020-12-08 04:09:41 -05:00
|
|
|
|
|
|
|
# Applies label "incident" (creates it if missing) to incident issues.
|
|
|
|
# For use in "after" hooks only to ensure we are not appyling
|
|
|
|
# labels prematurely.
|
|
|
|
def add_incident_label(issue)
|
|
|
|
return unless issue.incident?
|
|
|
|
|
|
|
|
label = ::IncidentManagement::CreateIncidentLabelService
|
|
|
|
.new(project, current_user)
|
|
|
|
.execute
|
|
|
|
.payload[:label]
|
|
|
|
|
|
|
|
return if issue.label_ids.include?(label.id)
|
|
|
|
|
|
|
|
issue.labels << label
|
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Issues::CreateService.prepend_if_ee('EE::Issues::CreateService')
|