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 ...@@ -3,8 +3,7 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
def allows_multiple_assignees? 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 end
end end
...@@ -113,11 +113,7 @@ module Issuable ...@@ -113,11 +113,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
......
...@@ -209,11 +209,19 @@ class MergeRequest < ActiveRecord::Base ...@@ -209,11 +209,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 ...@@ -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 ...@@ -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
......
...@@ -106,6 +106,22 @@ describe MergeRequest, models: true do ...@@ -106,6 +106,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) }
......
...@@ -410,10 +410,10 @@ describe QuickActions::InterpretService, services: true do ...@@ -410,10 +410,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
...@@ -426,7 +426,7 @@ describe QuickActions::InterpretService, services: true do ...@@ -426,7 +426,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, developer2.id]) expect(updates[:assignee_ids]).to match_array([developer.id, developer2.id])
...@@ -434,10 +434,10 @@ describe QuickActions::InterpretService, services: true do ...@@ -434,10 +434,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
...@@ -484,11 +484,11 @@ describe QuickActions::InterpretService, services: true do ...@@ -484,11 +484,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
......
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