debian-mirror-gitlab/app/services/issues/create_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
3.5 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module Issues
class CreateService < Issues::BaseService
2017-08-17 22:00:37 +05:30
include ResolveDiscussions
2021-11-18 22:05:49 +05:30
prepend RateLimitedService
rate_limit key: :issues_create,
2021-12-11 22:18:48 +05:30
opts: { scope: [:project, :current_user, :external_author] }
2017-08-17 22:00:37 +05:30
2021-09-30 23:02:18 +05:30
# 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.
2022-03-02 08:16:31 +05:30
def initialize(project:, current_user: nil, params: {}, spam_params:, build_service: nil)
2021-09-30 23:02:18 +05:30
super(project: project, current_user: current_user, params: params)
@spam_params = spam_params
2022-03-02 08:16:31 +05:30
@build_service = build_service || BuildService.new(project: project, current_user: current_user, params: params)
2021-09-30 23:02:18 +05:30
end
2021-03-11 19:13:27 +05:30
2021-09-30 23:02:18 +05:30
def execute(skip_system_notes: false)
2022-03-02 08:16:31 +05:30
@issue = @build_service.execute
2014-09-02 18:07:02 +05:30
2022-04-04 11:22:00 +05:30
handle_move_between_ids(@issue)
2022-05-07 20:08:51 +05:30
@add_related_issue ||= params.delete(:add_related_issue)
2017-08-17 22:00:37 +05:30
filter_resolve_discussion_params
2014-09-02 18:07:02 +05:30
2020-11-24 15:15:51 +05:30
create(@issue, skip_system_notes: skip_system_notes)
2016-09-13 17:45:13 +05:30
end
2021-12-11 22:18:48 +05:30
def external_author
params[:external_author] # present when creating an issue using service desk (email: from)
end
2017-08-17 22:00:37 +05:30
def before_create(issue)
2021-03-11 19:13:27 +05:30
Spam::SpamActionService.new(
spammable: issue,
2021-09-30 23:02:18 +05:30
spam_params: spam_params,
2021-03-11 19:13:27 +05:30
user: current_user,
action: :create
2021-09-30 23:02:18 +05:30
).execute
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
# current_user (defined in BaseService) is not available within run_after_commit block
2017-09-10 17:25:29 +05:30
user = current_user
issue.run_after_commit do
NewIssueWorker.perform_async(issue.id, user.id)
2022-01-26 12:08:38 +05:30
Issues::PlacementWorker.perform_async(nil, issue.project_id)
2021-04-17 20:07:23 +05:30
Namespaces::OnboardingIssueCreatedWorker.perform_async(issue.namespace.id)
2017-09-10 17:25:29 +05:30
end
2016-09-13 17:45:13 +05:30
end
2021-04-29 21:17:54 +05:30
# Add new items to Issues::AfterCreateService if they can be performed in Sidekiq
2020-11-24 15:15:51 +05:30
def after_create(issue)
2016-09-13 17:45:13 +05:30
user_agent_detail_service.create
2022-05-07 20:08:51 +05:30
handle_add_related_issue(issue)
2020-11-24 15:15:51 +05:30
resolve_discussions_with_issue(issue)
2022-01-26 12:08:38 +05:30
create_escalation_status(issue)
2018-03-17 18:26:18 +05:30
super
2016-09-13 17:45:13 +05:30
end
2021-09-04 01:27:46 +05:30
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-08-17 22:00:37 +05:30
def resolve_discussions_with_issue(issue)
return if discussions_to_resolve.empty?
2016-09-13 17:45:13 +05:30
2017-08-17 22:00:37 +05:30
Discussions::ResolveService.new(project, current_user,
2020-06-23 00:09:42 +05:30
one_or_more_discussions: discussions_to_resolve,
follow_up_issue: issue).execute
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
private
2021-09-30 23:02:18 +05:30
attr_reader :spam_params
2021-03-11 19:13:27 +05:30
2022-01-26 12:08:38 +05:30
def create_escalation_status(issue)
::IncidentManagement::IssuableEscalationStatuses::CreateService.new(issue).execute if issue.supports_escalation?
end
2016-09-13 17:45:13 +05:30
def user_agent_detail_service
2021-09-30 23:02:18 +05:30
UserAgentDetailService.new(spammable: @issue, spam_params: spam_params)
2014-09-02 18:07:02 +05:30
end
2022-05-07 20:08:51 +05:30
def handle_add_related_issue(issue)
return unless @add_related_issue
IssueLinks::CreateService.new(issue, issue.author, { target_issuable: @add_related_issue }).execute
end
2014-09-02 18:07:02 +05:30
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Issues::CreateService.prepend_mod