2018-07-16 16:31:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-02 10:38:35 +00:00
|
|
|
module Issues
|
2014-04-02 16:55:23 +00:00
|
|
|
class CreateService < Issues::BaseService
|
2017-02-27 17:12:52 +00:00
|
|
|
include ResolveDiscussions
|
2021-10-13 03:12:30 +00:00
|
|
|
prepend RateLimitedService
|
|
|
|
|
|
|
|
rate_limit key: :issues_create,
|
2021-11-05 00:13:17 +00:00
|
|
|
opts: { scope: [:project, :current_user, :external_author] }
|
2017-02-14 19:07:11 +00:00
|
|
|
|
2021-06-21 12:07:45 +00:00
|
|
|
# NOTE: For Issues::CreateService, we require the spam_params and do not default it to nil, because
|
|
|
|
# spam_checking is likely to be necessary. However, if there is not a request available in scope
|
|
|
|
# in the caller (for example, an issue created via email) and the required arguments to the
|
|
|
|
# SpamParams constructor are not otherwise available, spam_params: must be explicitly passed as nil.
|
2021-12-24 18:13:33 +00:00
|
|
|
def initialize(project:, current_user: nil, params: {}, spam_params:, build_service: nil)
|
2021-06-21 12:07:45 +00:00
|
|
|
super(project: project, current_user: current_user, params: params)
|
|
|
|
@spam_params = spam_params
|
2021-12-24 18:13:33 +00:00
|
|
|
@build_service = build_service || BuildService.new(project: project, current_user: current_user, params: params)
|
2021-06-21 12:07:45 +00:00
|
|
|
end
|
2021-01-27 09:09:01 +00:00
|
|
|
|
2021-06-21 12:07:45 +00:00
|
|
|
def execute(skip_system_notes: false)
|
2021-12-24 18:13:33 +00:00
|
|
|
@issue = @build_service.execute
|
2017-03-08 00:20:05 +00:00
|
|
|
|
2022-02-09 18:16:19 +00:00
|
|
|
handle_move_between_ids(@issue)
|
|
|
|
|
2017-02-27 17:12:52 +00:00
|
|
|
filter_resolve_discussion_params
|
2014-04-02 10:38:35 +00:00
|
|
|
|
2020-09-08 21:08:53 +00:00
|
|
|
create(@issue, skip_system_notes: skip_system_notes)
|
2016-06-30 15:34:19 +00:00
|
|
|
end
|
2014-04-02 10:38:35 +00:00
|
|
|
|
2021-11-05 00:13:17 +00:00
|
|
|
def external_author
|
|
|
|
params[:external_author] # present when creating an issue using service desk (email: from)
|
|
|
|
end
|
|
|
|
|
2017-02-14 19:07:11 +00:00
|
|
|
def before_create(issue)
|
2021-01-27 09:09:01 +00:00
|
|
|
Spam::SpamActionService.new(
|
|
|
|
spammable: issue,
|
2021-06-21 12:07:45 +00:00
|
|
|
spam_params: spam_params,
|
2021-01-27 09:09:01 +00:00
|
|
|
user: current_user,
|
|
|
|
action: :create
|
2021-06-21 12:07:45 +00:00
|
|
|
).execute
|
2017-08-01 12:38:45 +00:00
|
|
|
|
2017-08-08 07:41:27 +00:00
|
|
|
# current_user (defined in BaseService) is not available within run_after_commit block
|
2017-08-01 12:38:45 +00:00
|
|
|
user = current_user
|
|
|
|
issue.run_after_commit do
|
|
|
|
NewIssueWorker.perform_async(issue.id, user.id)
|
2021-12-02 21:10:16 +00:00
|
|
|
Issues::PlacementWorker.perform_async(nil, issue.project_id)
|
2021-02-25 18:11:05 +00:00
|
|
|
Namespaces::OnboardingIssueCreatedWorker.perform_async(issue.namespace.id)
|
2017-08-01 12:38:45 +00:00
|
|
|
end
|
2016-08-17 00:59:55 +00:00
|
|
|
end
|
|
|
|
|
2021-04-08 18:09:32 +00:00
|
|
|
# Add new items to Issues::AfterCreateService if they can be performed in Sidekiq
|
2020-09-14 15:09:28 +00:00
|
|
|
def after_create(issue)
|
2016-08-16 22:49:53 +00:00
|
|
|
user_agent_detail_service.create
|
2020-09-14 15:09:28 +00:00
|
|
|
resolve_discussions_with_issue(issue)
|
2021-12-17 12:16:21 +00:00
|
|
|
create_escalation_status(issue)
|
2021-04-08 18:09:32 +00:00
|
|
|
|
2017-08-17 15:21:25 +00:00
|
|
|
super
|
2016-10-26 21:21:50 +00:00
|
|
|
end
|
|
|
|
|
2021-05-25 09:10:54 +00:00
|
|
|
def handle_changes(issue, options)
|
|
|
|
super
|
|
|
|
old_associations = options.fetch(:old_associations, {})
|
|
|
|
old_assignees = old_associations.fetch(:assignees, [])
|
|
|
|
|
|
|
|
handle_assignee_changes(issue, old_assignees)
|
|
|
|
end
|
|
|
|
|
|
|
|
def handle_assignee_changes(issue, old_assignees)
|
|
|
|
return if issue.assignees == old_assignees
|
|
|
|
|
|
|
|
create_assignee_note(issue, old_assignees)
|
|
|
|
end
|
|
|
|
|
2017-03-08 00:30:43 +00:00
|
|
|
def resolve_discussions_with_issue(issue)
|
|
|
|
return if discussions_to_resolve.empty?
|
|
|
|
|
|
|
|
Discussions::ResolveService.new(project, current_user,
|
2020-05-27 06:08:13 +00:00
|
|
|
one_or_more_discussions: discussions_to_resolve,
|
|
|
|
follow_up_issue: issue).execute
|
2017-03-08 00:30:43 +00:00
|
|
|
end
|
|
|
|
|
2016-07-21 23:11:53 +00:00
|
|
|
private
|
|
|
|
|
2021-06-21 12:07:45 +00:00
|
|
|
attr_reader :spam_params
|
2021-01-27 09:09:01 +00:00
|
|
|
|
2021-12-17 12:16:21 +00:00
|
|
|
def create_escalation_status(issue)
|
|
|
|
::IncidentManagement::IssuableEscalationStatuses::CreateService.new(issue).execute if issue.supports_escalation?
|
|
|
|
end
|
|
|
|
|
2016-07-30 04:18:32 +00:00
|
|
|
def user_agent_detail_service
|
2021-06-21 12:07:45 +00:00
|
|
|
UserAgentDetailService.new(spammable: @issue, spam_params: spam_params)
|
2016-07-21 23:11:53 +00:00
|
|
|
end
|
2014-04-02 10:38:35 +00:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
Issues::CreateService.prepend_mod
|