Commit f17fce50 authored by Toon Claes's avatar Toon Claes

Make MergeRequest respond to assignee_ids & assignee_ids=

To make it simpler to assign users to an Issuable, make MergeRequest
support the attribute `assignee_ids`.
parent cae24e0a
......@@ -3,8 +3,7 @@ module EE
extend ActiveSupport::Concern
def allows_multiple_assignees?
supports_multiple_assignees? &&
is_a?(Issue) && project.feature_available?(:multiple_issue_assignees)
is_a?(Issue) && project.feature_available?(:multiple_issue_assignees)
end
end
end
......@@ -113,11 +113,7 @@ module Issuable
end
def has_multiple_assignees?
supports_multiple_assignees? && assignees.count > 1
end
def supports_multiple_assignees?
respond_to?(:assignee_ids)
assignees.count > 1
end
end
......
......@@ -209,11 +209,19 @@ class MergeRequest < ActiveRecord::Base
}
end
# This method is needed for compatibility with issues to not mess view and other code
# These method are needed for compatibility with issues to not mess view and other code
def assignees
Array(assignee)
end
def assignee_ids
Array(assignee_id)
end
def assignee_ids=(ids)
write_attribute(:assignee_id, ids.last)
end
def assignee_or_author?(user)
author_id == user.id || assignee_id == user.id
end
......
......@@ -107,13 +107,12 @@ module QuickActions
command :assign do |users|
next if users.empty?
if issuable.allows_multiple_assignees?
@updates[:assignee_ids] = issuable.assignees.pluck(:id) + users.map(&:id)
elsif issuable.supports_multiple_assignees?
@updates[:assignee_ids] = [users.last.id]
else
@updates[:assignee_id] = users.last.id
end
@updates[:assignee_ids] =
if issuable.allows_multiple_assignees?
issuable.assignees.pluck(:id) + users.map(&:id)
else
[users.last.id]
end
end
desc do
......@@ -138,16 +137,12 @@ module QuickActions
# When multiple users are assigned, all will be unassigned if multiple assignees are no longer allowed
users = extract_users(unassign_param) if issuable.allows_multiple_assignees?
if issuable.supports_multiple_assignees?
@updates[:assignee_ids] =
if users&.any?
issuable.assignees.pluck(:id) - users.map(&:id)
else
[]
end
else
@updates[:assignee_id] = nil
end
@updates[:assignee_ids] =
if users&.any?
issuable.assignees.pluck(:id) - users.map(&:id)
else
[]
end
end
desc do
......
......@@ -106,6 +106,22 @@ describe MergeRequest, models: true do
end
end
describe '#assignee_ids' do
it 'returns an array of the assigned user id' do
subject.assignee_id = 123
expect(subject.assignee_ids).to eq([123])
end
end
describe '#assignee_ids=' do
it 'sets assignee_id to the last id in the array' do
subject.assignee_ids = [123, 456]
expect(subject.assignee_id).to eq(456)
end
end
describe '#assignee_or_author?' do
let(:user) { create(:user) }
......
......@@ -410,10 +410,10 @@ describe QuickActions::InterpretService, services: true do
end
context 'Merge Request' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
it 'fetches assignee and populates assignee_ids if content contains /assign' do
_, updates = service.execute(content, merge_request)
expect(updates).to eq(assignee_id: developer.id)
expect(updates).to eq(assignee_ids: [developer.id])
end
end
end
......@@ -426,7 +426,7 @@ describe QuickActions::InterpretService, services: true do
end
context 'Issue' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
it 'fetches assignee and populates assignee_ids if content contains /assign' do
_, updates = service.execute(content, issue)
expect(updates[:assignee_ids]).to match_array([developer.id, developer2.id])
......@@ -434,10 +434,10 @@ describe QuickActions::InterpretService, services: true do
end
context 'Merge Request' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
it 'fetches assignee and populates assignee_ids if content contains /assign' do
_, updates = service.execute(content, merge_request)
expect(updates).to eq(assignee_id: developer.id)
expect(updates).to eq(assignee_ids: [developer.id])
end
end
end
......@@ -484,11 +484,11 @@ describe QuickActions::InterpretService, services: true do
end
context 'Merge Request' do
it 'populates assignee_id: nil if content contains /unassign' do
merge_request.update(assignee_id: developer.id)
it 'populates assignee_ids: [] if content contains /unassign' do
merge_request.update(assignee_ids: [developer.id])
_, updates = service.execute(content, merge_request)
expect(updates).to eq(assignee_id: nil)
expect(updates).to eq(assignee_ids: [])
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment