diff --git a/ee/lib/ee/gitlab/quick_actions/work_item_actions.rb b/ee/lib/ee/gitlab/quick_actions/work_item_actions.rb index 020f52ebabe265ca16c7a38e6e74a982fcc9773f..d1b762e3d28adc19088afee2d276411b6faa97b9 100644 --- a/ee/lib/ee/gitlab/quick_actions/work_item_actions.rb +++ b/ee/lib/ee/gitlab/quick_actions/work_item_actions.rb @@ -143,7 +143,7 @@ def show_epic_alias? override :supports_parent? def supports_parent? target_item = quick_action_target - return false if target_item.work_item_type.issue? && !target_item.licensed_feature_available?(:epics) + return false if target_item.work_item_type.epic? && !target_item.licensed_feature_available?(:subepics) super diff --git a/lib/gitlab/quick_actions/work_item_actions.rb b/lib/gitlab/quick_actions/work_item_actions.rb index 63ad84a43f6f3d04aaa249a9d4131697acf548b3..af5db69fc2fa929ff32f6704b47d30720b58dff2 100644 --- a/lib/gitlab/quick_actions/work_item_actions.rb +++ b/lib/gitlab/quick_actions/work_item_actions.rb @@ -183,7 +183,12 @@ def work_item_parent end def supports_parent? - ::WorkItems::HierarchyRestriction.find_by_child_type_id(quick_action_target.work_item_type_id).present? + target_item = quick_action_target + + return false if target_item.work_item_type&.issue? && + !(target_item.project || target_item.namespace)&.licensed_feature_available?(:epics) + + ::WorkItems::HierarchyRestriction.find_by_child_type_id(target_item.work_item_type_id).present? end def supports_children? diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 69332e2bc081771b04be13dda5356f68516a662d..eaf4e679aa4309745e95f78ec448463313611f8a 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -3312,21 +3312,52 @@ context '/set_parent command' do let_it_be(:parent) { create(:work_item, :issue, project: project) } - let_it_be(:work_item) { create(:work_item, :task, project: project) } + let_it_be(:task_work_item) { create(:work_item, :task, project: project) } + let_it_be(:issue_work_item) { create(:work_item, :issue, project: project) } let_it_be(:parent_ref) { parent.to_reference(project) } - let(:content) { "/set_parent #{parent_ref}" } + context 'on a work item' do + let(:content) { "/set_parent #{parent_ref}" } + + it 'returns success message' do + _, _, message = service.execute(content, task_work_item) + + expect(message).to eq(_('Parent set successfully')) + end + + it 'sets correct update params' do + _, updates, _ = service.execute(content, task_work_item) + + expect(updates).to eq(set_parent: parent) + end - it 'returns success message' do - _, _, message = service.execute(content, work_item) + context 'when epics are disabled' do + before do + stub_licensed_features(epics: false) + end - expect(message).to eq(_('Parent set successfully')) + it 'does not contain command for issue work item types' do + expect(service.available_commands(issue_work_item)).not_to include(a_hash_including(name: :set_parent)) + end + + it 'contains command for task work item types' do + expect(service.available_commands(task_work_item)).to include(a_hash_including(name: :set_parent)) + end + end end - it 'sets correct update params' do - _, updates, _ = service.execute(content, work_item) + context 'on an issue' do + context 'when epics are disabled' do + before do + stub_licensed_features(epics: false) + end + + let_it_be(:issue) { create(:issue, project: project) } - expect(updates).to eq(set_parent: parent) + it 'does not contain command' do + expect(service.available_commands(issue)).not_to include(a_hash_including(name: :set_parent)) + end + end end end