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`.
This commit is contained in:
parent
fcd46c1af4
commit
451e25532f
5 changed files with 47 additions and 32 deletions
|
@ -108,11 +108,7 @@ module Issuable
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_multiple_assignees?
|
def has_multiple_assignees?
|
||||||
supports_multiple_assignees? && assignees.count > 1
|
assignees.count > 1
|
||||||
end
|
|
||||||
|
|
||||||
def supports_multiple_assignees?
|
|
||||||
respond_to?(:assignee_ids)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -197,11 +197,19 @@ class MergeRequest < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
end
|
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
|
def assignees
|
||||||
Array(assignee)
|
Array(assignee)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assignee_ids
|
||||||
|
Array(assignee_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def assignee_ids=(ids)
|
||||||
|
write_attribute(:assignee_id, ids.last)
|
||||||
|
end
|
||||||
|
|
||||||
def assignee_or_author?(user)
|
def assignee_or_author?(user)
|
||||||
author_id == user.id || assignee_id == user.id
|
author_id == user.id || assignee_id == user.id
|
||||||
end
|
end
|
||||||
|
|
|
@ -107,13 +107,12 @@ module QuickActions
|
||||||
command :assign do |users|
|
command :assign do |users|
|
||||||
next if users.empty?
|
next if users.empty?
|
||||||
|
|
||||||
if issuable.allows_multiple_assignees?
|
@updates[:assignee_ids] =
|
||||||
@updates[:assignee_ids] = issuable.assignees.pluck(:id) + users.map(&:id)
|
if issuable.allows_multiple_assignees?
|
||||||
elsif issuable.supports_multiple_assignees?
|
issuable.assignees.pluck(:id) + users.map(&:id)
|
||||||
@updates[:assignee_ids] = [users.last.id]
|
else
|
||||||
else
|
[users.last.id]
|
||||||
@updates[:assignee_id] = users.last.id
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc do
|
desc do
|
||||||
|
@ -138,16 +137,12 @@ module QuickActions
|
||||||
# When multiple users are assigned, all will be unassigned if multiple assignees are no longer allowed
|
# 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?
|
users = extract_users(unassign_param) if issuable.allows_multiple_assignees?
|
||||||
|
|
||||||
if issuable.supports_multiple_assignees?
|
@updates[:assignee_ids] =
|
||||||
@updates[:assignee_ids] =
|
if users&.any?
|
||||||
if users&.any?
|
issuable.assignees.pluck(:id) - users.map(&:id)
|
||||||
issuable.assignees.pluck(:id) - users.map(&:id)
|
else
|
||||||
else
|
[]
|
||||||
[]
|
end
|
||||||
end
|
|
||||||
else
|
|
||||||
@updates[:assignee_id] = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc do
|
desc do
|
||||||
|
|
|
@ -105,6 +105,22 @@ describe MergeRequest, models: true do
|
||||||
end
|
end
|
||||||
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
|
describe '#assignee_or_author?' do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
|
|
@ -359,7 +359,7 @@ describe QuickActions::InterpretService, services: true do
|
||||||
let(:content) { "/assign @#{developer.username}" }
|
let(:content) { "/assign @#{developer.username}" }
|
||||||
|
|
||||||
context 'Issue' do
|
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)
|
_, updates = service.execute(content, issue)
|
||||||
|
|
||||||
expect(updates[:assignee_ids]).to match_array([developer.id])
|
expect(updates[:assignee_ids]).to match_array([developer.id])
|
||||||
|
@ -367,10 +367,10 @@ describe QuickActions::InterpretService, services: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Merge Request' do
|
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)
|
_, 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
|
end
|
||||||
end
|
end
|
||||||
|
@ -383,7 +383,7 @@ describe QuickActions::InterpretService, services: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Issue' do
|
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)
|
_, updates = service.execute(content, issue)
|
||||||
|
|
||||||
expect(updates[:assignee_ids]).to match_array([developer.id])
|
expect(updates[:assignee_ids]).to match_array([developer.id])
|
||||||
|
@ -391,10 +391,10 @@ describe QuickActions::InterpretService, services: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Merge Request' do
|
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)
|
_, 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
|
end
|
||||||
end
|
end
|
||||||
|
@ -422,11 +422,11 @@ describe QuickActions::InterpretService, services: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Merge Request' do
|
context 'Merge Request' do
|
||||||
it 'populates assignee_id: nil if content contains /unassign' do
|
it 'populates assignee_ids: [] if content contains /unassign' do
|
||||||
merge_request.update(assignee_id: developer.id)
|
merge_request.update(assignee_ids: [developer.id])
|
||||||
_, updates = service.execute(content, merge_request)
|
_, updates = service.execute(content, merge_request)
|
||||||
|
|
||||||
expect(updates).to eq(assignee_id: nil)
|
expect(updates).to eq(assignee_ids: [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue