Commit bd65eabe authored by Valery Sizov's avatar Valery Sizov

[Multiple issue assignees] Fix slash commands[ci skip]

parent 7934e400
...@@ -22,7 +22,7 @@ module Issues ...@@ -22,7 +22,7 @@ module Issues
end end
def filter_assignee(issuable) def filter_assignee(issuable)
return if params[:assignee_ids].to_a.empty? return if params[:assignee_ids].empty?
assignee_ids = params[:assignee_ids].select{ |assignee_id| assignee_can_read?(issuable, assignee_id)} assignee_ids = params[:assignee_ids].select{ |assignee_id| assignee_can_read?(issuable, assignee_id)}
......
...@@ -89,17 +89,27 @@ module SlashCommands ...@@ -89,17 +89,27 @@ module SlashCommands
user = extract_references(assignee_param, :user).first user = extract_references(assignee_param, :user).first
user ||= User.find_by(username: assignee_param) user ||= User.find_by(username: assignee_param)
@updates[:assignee_id] = user.id if user next unless user
if issuable.is_a?(Issue)
@updates[:assignee_ids] = [user.id]
else
@updates[:assignee_id] = user.id
end
end end
desc 'Remove assignee' desc 'Remove assignee'
condition do condition do
issuable.persisted? && issuable.persisted? &&
issuable.assignee_id? && issuable.assignees.any? &&
current_user.can?(:"admin_#{issuable.to_ability_name}", project) current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end end
command :unassign do command :unassign do
@updates[:assignee_id] = nil if issuable.is_a?(Issue)
@updates[:assignee_ids] = []
else
@updates[:assignee_id] = nil
end
end end
desc 'Set milestone' desc 'Set milestone'
......
...@@ -66,7 +66,7 @@ describe Notes::SlashCommandsService, services: true do ...@@ -66,7 +66,7 @@ describe Notes::SlashCommandsService, services: true do
expect(content).to eq '' expect(content).to eq ''
expect(note.noteable).to be_closed expect(note.noteable).to be_closed
expect(note.noteable.labels).to match_array(labels) expect(note.noteable.labels).to match_array(labels)
expect(note.noteable.assignee).to eq(assignee) expect(note.noteable.assignees).to eq([assignee])
expect(note.noteable.milestone).to eq(milestone) expect(note.noteable.milestone).to eq(milestone)
end end
end end
...@@ -113,7 +113,7 @@ describe Notes::SlashCommandsService, services: true do ...@@ -113,7 +113,7 @@ describe Notes::SlashCommandsService, services: true do
expect(content).to eq "HELLO\nWORLD" expect(content).to eq "HELLO\nWORLD"
expect(note.noteable).to be_closed expect(note.noteable).to be_closed
expect(note.noteable.labels).to match_array(labels) expect(note.noteable.labels).to match_array(labels)
expect(note.noteable.assignee).to eq(assignee) expect(note.noteable.assignees).to eq([assignee])
expect(note.noteable.milestone).to eq(milestone) expect(note.noteable.milestone).to eq(milestone)
end end
end end
......
...@@ -42,23 +42,6 @@ describe SlashCommands::InterpretService, services: true do ...@@ -42,23 +42,6 @@ describe SlashCommands::InterpretService, services: true do
end end
end end
shared_examples 'assign command' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
_, updates = service.execute(content, issuable)
expect(updates).to eq(assignee_id: developer.id)
end
end
shared_examples 'unassign command' do
it 'populates assignee_id: nil if content contains /unassign' do
issuable.update(assignee_id: developer.id)
_, updates = service.execute(content, issuable)
expect(updates).to eq(assignee_id: nil)
end
end
shared_examples 'milestone command' do shared_examples 'milestone command' do
it 'fetches milestone and populates milestone_id if content contains /milestone' do it 'fetches milestone and populates milestone_id if content contains /milestone' do
milestone # populate the milestone milestone # populate the milestone
...@@ -385,14 +368,24 @@ describe SlashCommands::InterpretService, services: true do ...@@ -385,14 +368,24 @@ describe SlashCommands::InterpretService, services: true do
let(:issuable) { issue } let(:issuable) { issue }
end end
it_behaves_like 'assign command' do context 'assign command' do
let(:content) { "/assign @#{developer.username}" } let(:content) { "/assign @#{developer.username}" }
let(:issuable) { issue }
end
it_behaves_like 'assign command' do context 'Issue' do
let(:content) { "/assign @#{developer.username}" } it 'fetches assignee and populates assignee_id if content contains /assign' do
let(:issuable) { merge_request } _, updates = service.execute(content, issue)
expect(updates).to eq(assignee_ids: [developer.id])
end
end
context 'Merge Request' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
_, updates = service.execute(content, merge_request)
expect(updates).to eq(assignee_id: developer.id)
end
end
end end
it_behaves_like 'empty command' do it_behaves_like 'empty command' do
...@@ -405,14 +398,26 @@ describe SlashCommands::InterpretService, services: true do ...@@ -405,14 +398,26 @@ describe SlashCommands::InterpretService, services: true do
let(:issuable) { issue } let(:issuable) { issue }
end end
it_behaves_like 'unassign command' do context 'unassign command' do
let(:content) { '/unassign' } let(:content) { '/unassign' }
let(:issuable) { issue }
end
it_behaves_like 'unassign command' do context 'Issue' do
let(:content) { '/unassign' } it 'populates assignee_ids: [] if content contains /unassign' do
let(:issuable) { merge_request } issue.update(assignee_ids: [developer.id])
_, updates = service.execute(content, issue)
expect(updates).to eq(assignee_ids: [])
end
end
context 'Merge Request' do
it 'populates assignee_id: nil if content contains /unassign' do
merge_request.update(assignee_id: developer.id)
_, updates = service.execute(content, merge_request)
expect(updates).to eq(assignee_id: nil)
end
end
end end
it_behaves_like 'milestone command' do it_behaves_like 'milestone command' do
......
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