Commit 330389ab authored by Jarka Košanová's avatar Jarka Košanová Committed by Lin Jen-Shin

Fix unlabeling using quick actions for epics

parent 1454aa9f
...@@ -210,8 +210,6 @@ module QuickActions ...@@ -210,8 +210,6 @@ module QuickActions
end end
params '~label1 ~"label 2"' params '~label1 ~"label 2"'
condition do condition do
parent = project || issuable_group
parent && parent &&
current_user.can?(:"admin_#{issuable.to_ability_name}", parent) && current_user.can?(:"admin_#{issuable.to_ability_name}", parent) &&
find_labels.any? find_labels.any?
...@@ -241,7 +239,7 @@ module QuickActions ...@@ -241,7 +239,7 @@ module QuickActions
issuable.is_a?(Issuable) && issuable.is_a?(Issuable) &&
issuable.persisted? && issuable.persisted? &&
issuable.labels.any? && issuable.labels.any? &&
current_user.can?(:"admin_#{issuable.to_ability_name}", project) current_user.can?(:"admin_#{issuable.to_ability_name}", parent)
end end
command :unlabel do |labels_param = nil| command :unlabel do |labels_param = nil|
if labels_param.present? if labels_param.present?
...@@ -670,6 +668,10 @@ module QuickActions ...@@ -670,6 +668,10 @@ module QuickActions
MilestonesFinder.new(params.merge(project_ids: [project.id], group_ids: [project.group&.id])).execute MilestonesFinder.new(params.merge(project_ids: [project.id], group_ids: [project.group&.id])).execute
end end
def parent
project || issuable_group
end
def issuable_group def issuable_group
strong_memoize(:issuable_group) do strong_memoize(:issuable_group) do
issuable.group if issuable.respond_to?(:group) issuable.group if issuable.respond_to?(:group)
......
...@@ -74,7 +74,7 @@ module EE ...@@ -74,7 +74,7 @@ module EE
if object.is_a?(Group) if object.is_a?(Group)
{ {
members: members_group_autocomplete_sources_path(object, type: noteable_type, type_id: params[:id]), members: members_group_autocomplete_sources_path(object, type: noteable_type, type_id: params[:id]),
labels: labels_group_autocomplete_sources_path(object), labels: labels_group_autocomplete_sources_path(object, type: noteable_type, type_id: params[:id]),
epics: epics_group_autocomplete_sources_path(object), epics: epics_group_autocomplete_sources_path(object),
commands: commands_group_autocomplete_sources_path(object, type: noteable_type, type_id: params[:id]), commands: commands_group_autocomplete_sources_path(object, type: noteable_type, type_id: params[:id]),
milestones: milestones_group_autocomplete_sources_path(object) milestones: milestones_group_autocomplete_sources_path(object)
......
...@@ -197,5 +197,38 @@ describe Notes::QuickActionsService do ...@@ -197,5 +197,38 @@ describe Notes::QuickActionsService do
end end
end end
end end
describe '/label' do
let(:project) { nil }
let!(:bug) { create(:group_label, title: 'bug', group: group)}
let!(:feature) { create(:group_label, title: 'feature', group: group)}
let(:note_text) { "/unlabel ~bug" }
let(:note) { create(:note, noteable: epic, note: note_text) }
before do
group.add_developer(user)
epic.labels = [bug, feature]
end
context 'when epics are not enabled' do
it 'does not remove any label' do
expect { execute(note) }.not_to change { epic.reload.labels }
end
end
context 'when epics are enabled' do
before do
stub_licensed_features(epics: true)
end
it 'removes a requested label from the epic' do
expect { execute(note) }.to change { epic.reload.labels.map(&:title) }.to(['feature'])
end
it 'leaves the note empty' do
expect(execute(note)).to eq('')
end
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