2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
module MergeRequests
|
2021-06-08 01:23:25 +05:30
|
|
|
class AssignIssuesService < BaseProjectService
|
2016-11-03 12:29:30 +05:30
|
|
|
def assignable_issues
|
2023-03-04 22:38:38 +05:30
|
|
|
@assignable_issues ||= if current_user == merge_request.author
|
|
|
|
closes_issues.select do |issue|
|
|
|
|
!issue.is_a?(ExternalIssue) && !issue.assignees.present? && can?(current_user, :admin_issue, issue)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
assignable_issues.each do |issue|
|
2023-04-23 21:23:45 +05:30
|
|
|
Issues::UpdateService.new(container: issue.project, current_user: current_user, params: { assignee_ids: [current_user.id] }).execute(issue)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
count: assignable_issues.count
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def merge_request
|
|
|
|
params[:merge_request]
|
|
|
|
end
|
|
|
|
|
|
|
|
def closes_issues
|
|
|
|
@closes_issues ||= params[:closes_issues] || merge_request.closes_issues(current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|