2016-08-08 18:30:01 -04:00
|
|
|
module MergeRequests
|
|
|
|
class AssignIssuesService < BaseService
|
|
|
|
def assignable_issues
|
|
|
|
@assignable_issues ||= begin
|
|
|
|
if current_user == merge_request.author
|
2016-10-07 12:16:42 -04:00
|
|
|
closes_issues.select do |issue|
|
2017-05-04 08:11:15 -04:00
|
|
|
!issue.is_a?(ExternalIssue) && !issue.assignees.present? && can?(current_user, :admin_issue, issue)
|
2016-10-07 12:16:42 -04:00
|
|
|
end
|
2016-08-08 18:30:01 -04:00
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
assignable_issues.each do |issue|
|
2017-05-04 08:11:15 -04:00
|
|
|
Issues::UpdateService.new(issue.project, current_user, assignee_ids: [current_user.id]).execute(issue)
|
2016-08-08 18:30:01 -04:00
|
|
|
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
|