debian-mirror-gitlab/app/services/merge_requests/assign_issues_service.rb

38 lines
876 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-11-03 12:29:30 +05:30
module MergeRequests
class AssignIssuesService < BaseService
def assignable_issues
@assignable_issues ||= begin
if current_user == merge_request.author
closes_issues.select do |issue|
2017-08-17 22:00:37 +05:30
!issue.is_a?(ExternalIssue) && !issue.assignees.present? && can?(current_user, :admin_issue, issue)
2016-11-03 12:29:30 +05:30
end
else
[]
end
end
end
def execute
assignable_issues.each do |issue|
2017-08-17 22:00:37 +05:30
Issues::UpdateService.new(issue.project, current_user, 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