Commit 3fbeee08 authored by Felipe Artur's avatar Felipe Artur

Block features by issue type

Block features based on issue type. Allows certain UI elements, quick
actions and other features to be filtered for issue types.
parent 35e12dce
# frozen_string_literal: true
# Verifies features availability based on issue type.
# This can be used, for example, for hiding UI elements or blocking specific
# quick actions for particular issue types;
module IssueAvailableFeatures
extend ActiveSupport::Concern
# EE only features are listed on EE::IssueAvailableFeatures
def available_features_for_issue_types
{}.with_indifferent_access
end
def issue_type_supports?(feature)
unless available_features_for_issue_types.has_key?(feature)
raise ArgumentError, 'invalid feature'
end
available_features_for_issue_types[feature].include?(issue_type)
end
end
IssueAvailableFeatures.prepend_if_ee('EE::IssueAvailableFeatures')
......@@ -20,6 +20,7 @@ class Issue < ApplicationRecord
include StateEventable
include IdInOrdered
include Presentable
include IssueAvailableFeatures
DueDateStruct = Struct.new(:title, :name).freeze
NoDueDate = DueDateStruct.new('No Due Date', '0').freeze
......
......@@ -6,7 +6,7 @@ module EE
extend ::Gitlab::Utils::Override
def supports_epic?
is_a?(Issue) && !incident? && project.group.present?
is_a?(Issue) && issue_type_supports?(:epics) && project.group.present?
end
def supports_health_status?
......
# frozen_string_literal: true
module EE
module IssueAvailableFeatures
include ::Gitlab::Utils::StrongMemoize
extend ::Gitlab::Utils::Override
override :available_features_for_issue_types
def available_features_for_issue_types
strong_memoize(:available_features_for_issue_types) do
super.merge(epics: %w(issue))
end
end
end
end
......@@ -758,4 +758,16 @@ RSpec.describe Issue do
it { is_expected.to eq(supports_iterations) }
end
end
describe '#issue_type_supports?' do
let_it_be(:issue) { create(:issue) }
let_it_be(:test_case) { create(:quality_test_case) }
let_it_be(:incident) { create(:incident) }
it do
expect(issue.issue_type_supports?(:epics)).to be(true)
expect(test_case.issue_type_supports?(:epics)).to be(false)
expect(incident.issue_type_supports?(:epics)).to be(false)
end
end
end
......@@ -121,6 +121,16 @@ RSpec.describe Notes::QuickActionsService do
end
end
context 'on a test case' do
before do
issue.update!(issue_type: :test_case)
end
it 'leaves the note empty' do
expect(execute(note)).to be_empty
end
end
context 'on a merge request' do
let(:note_mr) { create(:note_on_merge_request, project: project, note: note_text) }
......
......@@ -168,12 +168,28 @@ RSpec.describe Epics::IssuePromoteService do
end
end
context 'on an incident' do
it 'raises error' do
issue.update!(issue_type: :incident)
context 'on other issue types' do
shared_examples_for 'raising error' do
before do
issue.update(issue_type: issue_type)
end
expect { subject.execute(issue) }
.to raise_error(Epics::IssuePromoteService::PromoteError, /is not supported/)
it 'raises error' do
expect { subject.execute(issue) }
.to raise_error(Epics::IssuePromoteService::PromoteError, /is not supported/)
end
end
context 'on an incident' do
let(:issue_type) { :incident }
it_behaves_like 'raising error'
end
context 'on a test case' do
let(:issue_type) { :test_case }
it_behaves_like 'raising error'
end
end
end
......
......@@ -1238,4 +1238,12 @@ RSpec.describe Issue do
expect(issue.allows_reviewers?).to be(false)
end
end
describe '#issue_type_supports?' do
let_it_be(:issue) { create(:issue) }
it 'raises error when feature is invalid' do
expect { issue.issue_type_supports?(:unkown_feature) }.to raise_error(ArgumentError)
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