From c460cb6fd3a7b114d0b25707731763526c955ae2 Mon Sep 17 00:00:00 2001 From: Jason Goodman <jgoodman@gitlab.com> Date: Thu, 3 Sep 2020 18:28:55 +0000 Subject: [PATCH] Move operations feature flag models to core Part of moving feature flags to core Move model specs to core --- .rubocop_todo.yml | 8 ++++---- .../models/operations/feature_flag.rb | 0 .../models/operations/feature_flag_scope.rb | 0 .../models/operations/feature_flags/scope.rb | 0 .../operations/feature_flags/strategy.rb | 0 .../feature_flags/strategy_user_list.rb | 0 .../operations/feature_flags/user_list.rb | 0 .../models/operations/feature_flags_client.rb | 0 app/models/project.rb | 4 ++++ .../feature_flag_strategies_validator.rb | 0 .../feature_flag_user_xids_validator.rb | 0 config/routes/project.rb | 8 ++++++++ ee/app/models/ee/project.rb | 4 ---- ee/config/routes/project.rb | 8 -------- ee/lib/ee/gitlab/regex.rb | 20 ------------------- lib/gitlab/regex.rb | 11 ++++++++-- .../operations/feature_flag_scopes.rb | 0 .../factories/operations/feature_flags.rb | 0 .../operations/feature_flags/scope.rb | 0 .../operations/feature_flags/strategy.rb | 0 .../operations/feature_flags/user_list.rb | 0 .../operations/feature_flags_clients.rb | 0 .../operations/feature_flag_scope_spec.rb | 0 .../models/operations/feature_flag_spec.rb | 0 .../operations/feature_flags/strategy_spec.rb | 0 .../feature_flags/user_list_spec.rb | 0 .../operations/feature_flags_client_spec.rb | 0 .../support/helpers/feature_flag_helpers.rb | 0 28 files changed, 25 insertions(+), 38 deletions(-) rename {ee/app => app}/models/operations/feature_flag.rb (100%) rename {ee/app => app}/models/operations/feature_flag_scope.rb (100%) rename {ee/app => app}/models/operations/feature_flags/scope.rb (100%) rename {ee/app => app}/models/operations/feature_flags/strategy.rb (100%) rename {ee/app => app}/models/operations/feature_flags/strategy_user_list.rb (100%) rename {ee/app => app}/models/operations/feature_flags/user_list.rb (100%) rename {ee/app => app}/models/operations/feature_flags_client.rb (100%) rename {ee/app => app}/validators/feature_flag_strategies_validator.rb (100%) rename {ee/app => app}/validators/feature_flag_user_xids_validator.rb (100%) delete mode 100644 ee/lib/ee/gitlab/regex.rb rename {ee/spec => spec}/factories/operations/feature_flag_scopes.rb (100%) rename {ee/spec => spec}/factories/operations/feature_flags.rb (100%) rename {ee/spec => spec}/factories/operations/feature_flags/scope.rb (100%) rename {ee/spec => spec}/factories/operations/feature_flags/strategy.rb (100%) rename {ee/spec => spec}/factories/operations/feature_flags/user_list.rb (100%) rename {ee/spec => spec}/factories/operations/feature_flags_clients.rb (100%) rename {ee/spec => spec}/models/operations/feature_flag_scope_spec.rb (100%) rename {ee/spec => spec}/models/operations/feature_flag_spec.rb (100%) rename {ee/spec => spec}/models/operations/feature_flags/strategy_spec.rb (100%) rename {ee/spec => spec}/models/operations/feature_flags/user_list_spec.rb (100%) rename {ee/spec => spec}/models/operations/feature_flags_client_spec.rb (100%) rename {ee/spec => spec}/support/helpers/feature_flag_helpers.rb (100%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 82e59e0104b4..cb16e0e9d810 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -798,10 +798,6 @@ Rails/SaveBang: - 'ee/spec/models/license_spec.rb' - 'ee/spec/models/merge_request_spec.rb' - 'ee/spec/models/merge_train_spec.rb' - - 'ee/spec/models/operations/feature_flag_scope_spec.rb' - - 'ee/spec/models/operations/feature_flag_spec.rb' - - 'ee/spec/models/operations/feature_flags/strategy_spec.rb' - - 'ee/spec/models/operations/feature_flags/user_list_spec.rb' - 'spec/models/packages/package_spec.rb' - 'ee/spec/models/project_ci_cd_setting_spec.rb' - 'ee/spec/models/project_services/github_service_spec.rb' @@ -1188,6 +1184,10 @@ Rails/SaveBang: - 'spec/models/namespace_spec.rb' - 'spec/models/note_spec.rb' - 'spec/models/notification_setting_spec.rb' + - 'spec/models/operations/feature_flag_scope_spec.rb' + - 'spec/models/operations/feature_flag_spec.rb' + - 'spec/models/operations/feature_flags/strategy_spec.rb' + - 'spec/models/operations/feature_flags/user_list_spec.rb' - 'spec/models/pages_domain_spec.rb' - 'spec/models/project_auto_devops_spec.rb' - 'spec/models/project_feature_spec.rb' diff --git a/ee/app/models/operations/feature_flag.rb b/app/models/operations/feature_flag.rb similarity index 100% rename from ee/app/models/operations/feature_flag.rb rename to app/models/operations/feature_flag.rb diff --git a/ee/app/models/operations/feature_flag_scope.rb b/app/models/operations/feature_flag_scope.rb similarity index 100% rename from ee/app/models/operations/feature_flag_scope.rb rename to app/models/operations/feature_flag_scope.rb diff --git a/ee/app/models/operations/feature_flags/scope.rb b/app/models/operations/feature_flags/scope.rb similarity index 100% rename from ee/app/models/operations/feature_flags/scope.rb rename to app/models/operations/feature_flags/scope.rb diff --git a/ee/app/models/operations/feature_flags/strategy.rb b/app/models/operations/feature_flags/strategy.rb similarity index 100% rename from ee/app/models/operations/feature_flags/strategy.rb rename to app/models/operations/feature_flags/strategy.rb diff --git a/ee/app/models/operations/feature_flags/strategy_user_list.rb b/app/models/operations/feature_flags/strategy_user_list.rb similarity index 100% rename from ee/app/models/operations/feature_flags/strategy_user_list.rb rename to app/models/operations/feature_flags/strategy_user_list.rb diff --git a/ee/app/models/operations/feature_flags/user_list.rb b/app/models/operations/feature_flags/user_list.rb similarity index 100% rename from ee/app/models/operations/feature_flags/user_list.rb rename to app/models/operations/feature_flags/user_list.rb diff --git a/ee/app/models/operations/feature_flags_client.rb b/app/models/operations/feature_flags_client.rb similarity index 100% rename from ee/app/models/operations/feature_flags_client.rb rename to app/models/operations/feature_flags_client.rb diff --git a/app/models/project.rb b/app/models/project.rb index 89dda1837882..a5317d14dd80 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -344,6 +344,10 @@ class Project < ApplicationRecord # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/228637 has_many :product_analytics_events, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent + has_many :operations_feature_flags, class_name: 'Operations::FeatureFlag' + has_one :operations_feature_flags_client, class_name: 'Operations::FeatureFlagsClient' + has_many :operations_feature_flags_user_lists, class_name: 'Operations::FeatureFlags::UserList' + accepts_nested_attributes_for :variables, allow_destroy: true accepts_nested_attributes_for :project_feature, update_only: true accepts_nested_attributes_for :project_setting, update_only: true diff --git a/ee/app/validators/feature_flag_strategies_validator.rb b/app/validators/feature_flag_strategies_validator.rb similarity index 100% rename from ee/app/validators/feature_flag_strategies_validator.rb rename to app/validators/feature_flag_strategies_validator.rb diff --git a/ee/app/validators/feature_flag_user_xids_validator.rb b/app/validators/feature_flag_user_xids_validator.rb similarity index 100% rename from ee/app/validators/feature_flag_user_xids_validator.rb rename to app/validators/feature_flag_user_xids_validator.rb diff --git a/config/routes/project.rb b/config/routes/project.rb index 8c9b1f7f5cd4..4ba1f14222e7 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -367,6 +367,14 @@ post :mark_as_spam end end + + resources :feature_flags, param: :iid do + resources :feature_flag_issues, only: [:index, :create, :destroy], as: 'issues', path: 'issues' + end + resource :feature_flags_client, only: [] do + post :reset_token + end + resources :feature_flags_user_lists, param: :iid, only: [:new, :edit, :show] end # End of the /-/ scope. diff --git a/ee/app/models/ee/project.rb b/ee/app/models/ee/project.rb index c9b58447c968..349e0147ea64 100644 --- a/ee/app/models/ee/project.rb +++ b/ee/app/models/ee/project.rb @@ -81,10 +81,6 @@ def lock_for_confirmation!(id) accepts_nested_attributes_for :software_license_policies, allow_destroy: true has_many :merge_trains, foreign_key: 'target_project_id', inverse_of: :target_project - has_many :operations_feature_flags, class_name: 'Operations::FeatureFlag' - has_one :operations_feature_flags_client, class_name: 'Operations::FeatureFlagsClient' - has_many :operations_feature_flags_user_lists, class_name: 'Operations::FeatureFlags::UserList' - has_many :project_aliases has_many :upstream_project_subscriptions, class_name: 'Ci::Subscriptions::Project', foreign_key: :downstream_project_id, inverse_of: :downstream_project diff --git a/ee/config/routes/project.rb b/ee/config/routes/project.rb index 0346c302d704..374f346ee4ca 100644 --- a/ee/config/routes/project.rb +++ b/ee/config/routes/project.rb @@ -19,14 +19,6 @@ resources :test_cases, only: [:index] end - resources :feature_flags, param: :iid do - resources :feature_flag_issues, only: [:index, :create, :destroy], as: 'issues', path: 'issues' - end - resource :feature_flags_client, only: [] do - post :reset_token - end - resources :feature_flags_user_lists, param: :iid, only: [:new, :edit, :show] - resources :autocomplete_sources, only: [] do collection do get 'epics' diff --git a/ee/lib/ee/gitlab/regex.rb b/ee/lib/ee/gitlab/regex.rb deleted file mode 100644 index 9b350c005b11..000000000000 --- a/ee/lib/ee/gitlab/regex.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module EE - module Gitlab - module Regex - extend ActiveSupport::Concern - - class_methods do - def feature_flag_regex - /\A[a-z]([-_a-z0-9]*[a-z0-9])?\z/ - end - - def feature_flag_regex_message - "can contain only lowercase letters, digits, '_' and '-'. " \ - "Must start with a letter, and cannot end with '-' or '_'" - end - end - end - end -end diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 06e8a9ec6498..8e23ac6aca5e 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -292,7 +292,14 @@ def issue def base64_regex @base64_regex ||= /(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?/.freeze end + + def feature_flag_regex + /\A[a-z]([-_a-z0-9]*[a-z0-9])?\z/ + end + + def feature_flag_regex_message + "can contain only lowercase letters, digits, '_' and '-'. " \ + "Must start with a letter, and cannot end with '-' or '_'" + end end end - -Gitlab::Regex.prepend_if_ee('EE::Gitlab::Regex') diff --git a/ee/spec/factories/operations/feature_flag_scopes.rb b/spec/factories/operations/feature_flag_scopes.rb similarity index 100% rename from ee/spec/factories/operations/feature_flag_scopes.rb rename to spec/factories/operations/feature_flag_scopes.rb diff --git a/ee/spec/factories/operations/feature_flags.rb b/spec/factories/operations/feature_flags.rb similarity index 100% rename from ee/spec/factories/operations/feature_flags.rb rename to spec/factories/operations/feature_flags.rb diff --git a/ee/spec/factories/operations/feature_flags/scope.rb b/spec/factories/operations/feature_flags/scope.rb similarity index 100% rename from ee/spec/factories/operations/feature_flags/scope.rb rename to spec/factories/operations/feature_flags/scope.rb diff --git a/ee/spec/factories/operations/feature_flags/strategy.rb b/spec/factories/operations/feature_flags/strategy.rb similarity index 100% rename from ee/spec/factories/operations/feature_flags/strategy.rb rename to spec/factories/operations/feature_flags/strategy.rb diff --git a/ee/spec/factories/operations/feature_flags/user_list.rb b/spec/factories/operations/feature_flags/user_list.rb similarity index 100% rename from ee/spec/factories/operations/feature_flags/user_list.rb rename to spec/factories/operations/feature_flags/user_list.rb diff --git a/ee/spec/factories/operations/feature_flags_clients.rb b/spec/factories/operations/feature_flags_clients.rb similarity index 100% rename from ee/spec/factories/operations/feature_flags_clients.rb rename to spec/factories/operations/feature_flags_clients.rb diff --git a/ee/spec/models/operations/feature_flag_scope_spec.rb b/spec/models/operations/feature_flag_scope_spec.rb similarity index 100% rename from ee/spec/models/operations/feature_flag_scope_spec.rb rename to spec/models/operations/feature_flag_scope_spec.rb diff --git a/ee/spec/models/operations/feature_flag_spec.rb b/spec/models/operations/feature_flag_spec.rb similarity index 100% rename from ee/spec/models/operations/feature_flag_spec.rb rename to spec/models/operations/feature_flag_spec.rb diff --git a/ee/spec/models/operations/feature_flags/strategy_spec.rb b/spec/models/operations/feature_flags/strategy_spec.rb similarity index 100% rename from ee/spec/models/operations/feature_flags/strategy_spec.rb rename to spec/models/operations/feature_flags/strategy_spec.rb diff --git a/ee/spec/models/operations/feature_flags/user_list_spec.rb b/spec/models/operations/feature_flags/user_list_spec.rb similarity index 100% rename from ee/spec/models/operations/feature_flags/user_list_spec.rb rename to spec/models/operations/feature_flags/user_list_spec.rb diff --git a/ee/spec/models/operations/feature_flags_client_spec.rb b/spec/models/operations/feature_flags_client_spec.rb similarity index 100% rename from ee/spec/models/operations/feature_flags_client_spec.rb rename to spec/models/operations/feature_flags_client_spec.rb diff --git a/ee/spec/support/helpers/feature_flag_helpers.rb b/spec/support/helpers/feature_flag_helpers.rb similarity index 100% rename from ee/spec/support/helpers/feature_flag_helpers.rb rename to spec/support/helpers/feature_flag_helpers.rb -- GitLab