debian-mirror-gitlab/app/models/concerns/issue_available_features.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# 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
2021-01-29 00:20:46 +05:30
class_methods do
# EE only features are listed on EE::IssueAvailableFeatures
def available_features_for_issue_types
2021-03-08 18:12:59 +05:30
{
assignee: %w(issue incident),
2021-09-04 01:27:46 +05:30
confidentiality: %w(issue incident),
time_tracking: %w(issue incident)
2021-03-08 18:12:59 +05:30
}.with_indifferent_access
2021-01-29 00:20:46 +05:30
end
end
included do
scope :with_feature, ->(feature) { where(issue_type: available_features_for_issue_types[feature]) }
2021-01-03 14:25:43 +05:30
end
def issue_type_supports?(feature)
2021-01-29 00:20:46 +05:30
unless self.class.available_features_for_issue_types.has_key?(feature)
2021-01-03 14:25:43 +05:30
raise ArgumentError, 'invalid feature'
end
2021-01-29 00:20:46 +05:30
self.class.available_features_for_issue_types[feature].include?(issue_type)
2021-01-03 14:25:43 +05:30
end
end
2021-06-08 01:23:25 +05:30
IssueAvailableFeatures.prepend_mod_with('IssueAvailableFeatures')
IssueAvailableFeatures::ClassMethods.prepend_mod_with('IssueAvailableFeatures::ClassMethods')