Commit d36a4504 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix code structure

parent 542763ff
...@@ -8,16 +8,16 @@ class Projects::FeatureFlagsController < Projects::ApplicationController ...@@ -8,16 +8,16 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
before_action :feature_flag, only: [:edit, :update, :destroy] before_action :feature_flag, only: [:edit, :update, :destroy]
def index def index
@feature_flags = project.project_feature_flags @feature_flags = project.operations_feature_flags
@unleash_instanceid = project.project_feature_flags_access_tokens.first&.token || project.project_feature_flags_access_tokens.create!.token @unleash_instanceid = project.feature_flag_access_token
end end
def new def new
@feature_flag = project.project_feature_flags.new @feature_flag = project.operations_feature_flags.new
end end
def create def create
@feature_flag = project.project_feature_flags.create(create_params) @feature_flag = project.operations_feature_flags.create(create_params)
if @feature_flag.persisted? if @feature_flag.persisted?
flash[:notice] = 'Feature flag was successfully created.' flash[:notice] = 'Feature flag was successfully created.'
...@@ -50,16 +50,16 @@ class Projects::FeatureFlagsController < Projects::ApplicationController ...@@ -50,16 +50,16 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
protected protected
def feature_flag def feature_flag
@feature_flag ||= project.project_feature_flags.find(params[:id]) @feature_flag ||= project.operations_feature_flags.find(params[:id])
end end
def create_params def create_params
params.require(:project_feature_flag) params.require(:operations_feature_flag)
.permit(:name, :description, :active) .permit(:name, :description, :active)
end end
def update_params def update_params
params.require(:project_feature_flag) params.require(:operations_feature_flag)
.permit(:description, :active) .permit(:description, :active)
end end
end end
class ProjectFeatureFlag < ActiveRecord::Base module Operations
belongs_to :project class FeatureFlag < ActiveRecord::Base
self.table_name = 'operations_feature_flags'
validates :project, presence: true belongs_to :project
validates :name,
presence: true, validates :project, presence: true
length: 2..63, validates :name,
format: { presence: true,
with: Gitlab::Regex.feature_flag_regex, length: 2..63,
message: Gitlab::Regex.feature_flag_regex_message format: {
} with: Gitlab::Regex.feature_flag_regex,
message: Gitlab::Regex.feature_flag_regex_message
}
end
end end
class ProjectFeatureFlagsAccessToken < ActiveRecord::Base
include TokenAuthenticatable
belongs_to :project
validates :project, presence: true
validates :token, presence: true
add_authentication_token_field :token
before_validation :ensure_token!
end
module Operations
class FeatureFlagsAccessToken < ActiveRecord::Base
include TokenAuthenticatable
self.table_name = 'operations_feature_flags_access_tokens'
belongs_to :project
validates :project, presence: true
validates :token, presence: true
add_authentication_token_field :token
before_validation :ensure_token!
end
end
...@@ -266,8 +266,8 @@ class Project < ActiveRecord::Base ...@@ -266,8 +266,8 @@ class Project < ActiveRecord::Base
has_many :project_deploy_tokens has_many :project_deploy_tokens
has_many :deploy_tokens, through: :project_deploy_tokens has_many :deploy_tokens, through: :project_deploy_tokens
has_many :project_feature_flags has_many :operations_feature_flags, class_name: 'Operations::FeatureFlag'
has_many :project_feature_flags_access_tokens has_one :operations_feature_flags_access_token, class_name: 'Operations::FeatureFlagsAccessToken'
has_one :auto_devops, class_name: 'ProjectAutoDevops' has_one :auto_devops, class_name: 'ProjectAutoDevops'
has_many :custom_attributes, class_name: 'ProjectCustomAttribute' has_many :custom_attributes, class_name: 'ProjectCustomAttribute'
...@@ -2105,6 +2105,10 @@ class Project < ActiveRecord::Base ...@@ -2105,6 +2105,10 @@ class Project < ActiveRecord::Base
auto_cancel_pending_pipelines == 'enabled' auto_cancel_pending_pipelines == 'enabled'
end end
def feature_flag_access_token
(operations_feature_flags_access_token || create_operations_feature_flags_access_token!).token
end
private private
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
......
...@@ -1525,7 +1525,7 @@ module API ...@@ -1525,7 +1525,7 @@ module API
class UnleashFeatures < Grape::Entity class UnleashFeatures < Grape::Entity
expose :version expose :version
expose :project_feature_flags, as: :features, with: UnleashFeature expose :operations_feature_flags, as: :features, with: UnleashFeature
private private
......
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