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

43 lines
1.5 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),
2021-11-18 22:05:49 +05:30
time_tracking: %w(issue incident),
move_and_clone: %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
2023-06-20 00:43:36 +05:30
type_for_issue = if Feature.enabled?(:issue_type_uses_work_item_types_table)
# The default will only be used in places where an issue is only build and not saved
work_item_type_with_default.base_type
else
issue_type
end
self.class.available_features_for_issue_types[feature].include?(type_for_issue)
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')