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