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

87 lines
2.9 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-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.
def initialize(project:, current_user: nil, params: {}, spam_params:)
# Temporary check to ensure we are no longer passing request in params now that we have
# introduced spam_params. Raise an exception if it is present.
# Remove after https://gitlab.com/gitlab-org/gitlab/-/merge_requests/58603 is complete.
raise if params[:request]
super(project: project, current_user: current_user, params: params)
@spam_params = spam_params
end
2021-03-11 19:13:27 +05:30
2021-09-30 23:02:18 +05:30
def execute(skip_system_notes: false)
2021-06-08 01:23:25 +05:30
@issue = BuildService.new(project: project, current_user: current_user, params: params).execute
2014-09-02 18:07:02 +05:30
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
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)
2020-11-24 15:15:51 +05:30
IssuePlacementWorker.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
2020-11-24 15:15:51 +05:30
resolve_discussions_with_issue(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
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
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Issues::CreateService.prepend_mod