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|
|
2016-10-20 10:40:24 -04:00
|
|
|
!issue.is_a?(ExternalIssue) && !issue.assignee_id? && 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|
|
|
|
|
Issues::UpdateService.new(issue.project, current_user, assignee_id: current_user.id).execute(issue)
|
|
|
|
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
|