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