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
|
2020-03-09 13:42:32 +05:30
|
|
|
include SpamCheckMethods
|
2017-08-17 22:00:37 +05:30
|
|
|
include ResolveDiscussions
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def execute
|
2017-08-17 22:00:37 +05:30
|
|
|
@issue = BuildService.new(project, current_user, params).execute
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
filter_spam_check_params
|
|
|
|
filter_resolve_discussion_params
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
create(@issue)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def before_create(issue)
|
|
|
|
spam_check(issue, current_user)
|
|
|
|
issue.move_to_end
|
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)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def after_create(issuable)
|
|
|
|
todo_service.new_issue(issuable, current_user)
|
|
|
|
user_agent_detail_service.create
|
2017-08-17 22:00:37 +05:30
|
|
|
resolve_discussions_with_issue(issuable)
|
2020-04-08 14:13:33 +05:30
|
|
|
delete_milestone_total_issue_counter_cache(issuable.milestone)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
super
|
2016-09-13 17:45:13 +05:30
|
|
|
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,
|
|
|
|
merge_request: merge_request_to_resolve_discussions_of,
|
2017-09-10 17:25:29 +05:30
|
|
|
follow_up_issue: issue)
|
|
|
|
.execute(discussions_to_resolve)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
private
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def user_agent_detail_service
|
|
|
|
UserAgentDetailService.new(@issue, @request)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Issues::CreateService.prepend_if_ee('EE::Issues::CreateService')
|