2019-07-04 12:36:17 +02:00
|
|
|
Flipper.configure do |config|
|
|
|
|
config.default do
|
|
|
|
Flipper.new(Flipper::Adapters::ActiveRecord.new)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Flipper.register('Administrateurs') do |user|
|
|
|
|
user.administrateur_id.present?
|
|
|
|
end
|
|
|
|
Flipper.register('Instructeurs') do |user|
|
|
|
|
user.instructeur_id.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
# This setup is primarily for first deployment, because consequently
|
|
|
|
# we can add new features from the Web UI. However when the new DB is created
|
|
|
|
# this will immediately migrate the default features to be controlled.
|
|
|
|
def setup_features(features)
|
|
|
|
features.each do |feature|
|
2019-09-11 12:21:21 +02:00
|
|
|
if !Flipper.exist?(feature)
|
|
|
|
# Disable feature by default
|
|
|
|
Flipper.disable(feature)
|
2019-07-04 12:36:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# A list of features to be deployed on first push
|
|
|
|
features = [
|
|
|
|
:administrateur_web_hook,
|
|
|
|
:insee_api_v3,
|
|
|
|
:instructeur_bypass_email_login_token,
|
2019-11-19 17:55:30 +01:00
|
|
|
:autosave_dossier_draft,
|
2019-07-04 12:36:17 +02:00
|
|
|
:maintenance_mode,
|
|
|
|
:mini_profiler,
|
2020-07-30 17:10:26 +02:00
|
|
|
:xray,
|
2020-08-27 11:37:03 +02:00
|
|
|
:carte_ign,
|
|
|
|
:localization
|
2019-07-04 12:36:17 +02:00
|
|
|
]
|
|
|
|
|
2019-09-11 12:21:21 +02:00
|
|
|
def database_exists?
|
|
|
|
ActiveRecord::Base.connection
|
|
|
|
true
|
2019-11-14 09:17:39 +01:00
|
|
|
rescue ActiveRecord::NoDatabaseError, PG::ConnectionBad
|
2019-09-11 12:21:21 +02:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2019-07-04 12:36:17 +02:00
|
|
|
ActiveSupport.on_load(:active_record) do
|
2019-09-11 12:21:21 +02:00
|
|
|
if database_exists? && ActiveRecord::Base.connection.data_source_exists?('flipper_features')
|
2019-07-04 12:36:17 +02:00
|
|
|
setup_features(features)
|
|
|
|
end
|
|
|
|
end
|