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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
918 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
2021-06-08 01:23:25 +05:30
class AssignIssuesService < BaseProjectService
2016-11-03 12:29:30 +05:30
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|
2021-06-08 01:23:25 +05:30
Issues::UpdateService.new(project: 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