2021-04-17 20:07:23 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# This follows the rules specified in the specs.
|
|
|
|
# See spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb
|
|
|
|
|
|
|
|
module Issuable
|
|
|
|
class ProcessAssignees
|
|
|
|
def initialize(assignee_ids:, add_assignee_ids:, remove_assignee_ids:, existing_assignee_ids: nil, extra_assignee_ids: nil)
|
2022-11-25 23:54:43 +05:30
|
|
|
@assignee_ids = assignee_ids&.map(&:to_i)
|
|
|
|
@add_assignee_ids = add_assignee_ids&.map(&:to_i)
|
|
|
|
@remove_assignee_ids = remove_assignee_ids&.map(&:to_i)
|
|
|
|
@existing_assignee_ids = existing_assignee_ids&.map(&:to_i) || []
|
|
|
|
@extra_assignee_ids = extra_assignee_ids&.map(&:to_i) || []
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2021-04-29 21:17:54 +05:30
|
|
|
updated_new_assignees = new_assignee_ids
|
|
|
|
|
|
|
|
if add_assignee_ids.blank? && remove_assignee_ids.blank?
|
|
|
|
updated_new_assignees = assignee_ids if assignee_ids
|
|
|
|
else
|
2021-04-17 20:07:23 +05:30
|
|
|
updated_new_assignees |= add_assignee_ids if add_assignee_ids
|
|
|
|
updated_new_assignees -= remove_assignee_ids if remove_assignee_ids
|
|
|
|
end
|
|
|
|
|
|
|
|
updated_new_assignees.uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_accessor :assignee_ids, :add_assignee_ids, :remove_assignee_ids, :existing_assignee_ids, :extra_assignee_ids
|
|
|
|
|
|
|
|
def new_assignee_ids
|
|
|
|
existing_assignee_ids | extra_assignee_ids
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|