diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /app/models/operations | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'app/models/operations')
-rw-r--r-- | app/models/operations/feature_flag.rb | 37 | ||||
-rw-r--r-- | app/models/operations/feature_flag_scope.rb | 66 |
2 files changed, 1 insertions, 102 deletions
diff --git a/app/models/operations/feature_flag.rb b/app/models/operations/feature_flag.rb index 46810749b18..7db396bcad5 100644 --- a/app/models/operations/feature_flag.rb +++ b/app/models/operations/feature_flag.rb @@ -19,13 +19,10 @@ module Operations default_value_for :active, true default_value_for :version, :new_version_flag - # scopes exists only for the first version - has_many :scopes, class_name: 'Operations::FeatureFlagScope' # strategies exists only for the second version has_many :strategies, class_name: 'Operations::FeatureFlags::Strategy' has_many :feature_flag_issues has_many :issues, through: :feature_flag_issues - has_one :default_scope, -> { where(environment_scope: '*') }, class_name: 'Operations::FeatureFlagScope' validates :project, presence: true validates :name, @@ -37,10 +34,7 @@ module Operations } validates :name, uniqueness: { scope: :project_id } validates :description, allow_blank: true, length: 0..255 - validate :first_default_scope, on: :create, if: :has_scopes? - validate :version_associations - accepts_nested_attributes_for :scopes, allow_destroy: true accepts_nested_attributes_for :strategies, allow_destroy: true scope :ordered, -> { order(:name) } @@ -56,7 +50,7 @@ module Operations class << self def preload_relations - preload(:scopes, strategies: :scopes) + preload(strategies: :scopes) end def for_unleash_client(project, environment) @@ -104,13 +98,6 @@ module Operations Ability.issues_readable_by_user(issues, current_user) end - def execute_hooks(current_user) - run_after_commit do - feature_flag_data = Gitlab::DataBuilder::FeatureFlag.build(self, current_user) - project.execute_hooks(feature_flag_data, :feature_flag_hooks) - end - end - def hook_attrs { id: id, @@ -119,27 +106,5 @@ module Operations active: active } end - - private - - def version_associations - if new_version_flag? && scopes.any? - errors.add(:version_associations, 'version 2 feature flags may not have scopes') - end - end - - def first_default_scope - unless scopes.first.environment_scope == '*' - errors.add(:default_scope, 'has to be the first element') - end - end - - def build_default_scope - scopes.build(environment_scope: '*', active: self.active) - end - - def has_scopes? - scopes.any? - end end end diff --git a/app/models/operations/feature_flag_scope.rb b/app/models/operations/feature_flag_scope.rb deleted file mode 100644 index 9068ca0f588..00000000000 --- a/app/models/operations/feature_flag_scope.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -# All of the legacy flags have been removed in 14.1, including all of the -# `operations_feature_flag_scopes` rows. Therefore, this model and the database -# table are unused and should be removed. - -module Operations - class FeatureFlagScope < ApplicationRecord - prepend HasEnvironmentScope - include Gitlab::Utils::StrongMemoize - - self.table_name = 'operations_feature_flag_scopes' - - belongs_to :feature_flag - - validates :environment_scope, uniqueness: { - scope: :feature_flag, - message: "(%{value}) has already been taken" - } - - validates :environment_scope, - if: :default_scope?, on: :update, - inclusion: { in: %w(*), message: 'cannot be changed from default scope' } - - validates :strategies, feature_flag_strategies: true - - before_destroy :prevent_destroy_default_scope, if: :default_scope? - - scope :ordered, -> { order(:id) } - scope :enabled, -> { where(active: true) } - scope :disabled, -> { where(active: false) } - - def self.with_name_and_description - joins(:feature_flag) - .select(FeatureFlag.arel_table[:name], FeatureFlag.arel_table[:description]) - end - - def self.for_unleash_client(project, environment) - select_columns = [ - 'DISTINCT ON (operations_feature_flag_scopes.feature_flag_id) operations_feature_flag_scopes.id', - '(operations_feature_flags.active AND operations_feature_flag_scopes.active) AS active', - 'operations_feature_flag_scopes.strategies', - 'operations_feature_flag_scopes.environment_scope', - 'operations_feature_flag_scopes.created_at', - 'operations_feature_flag_scopes.updated_at' - ] - - select(select_columns) - .with_name_and_description - .where(feature_flag_id: project.operations_feature_flags.select(:id)) - .order(:feature_flag_id) - .on_environment(environment) - .reverse_order - end - - private - - def default_scope? - environment_scope_was == '*' - end - - def prevent_destroy_default_scope - raise ActiveRecord::ReadOnlyRecord, "default scope cannot be destroyed" - end - end -end |