mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-13 18:46:49 +00:00
Add all feature toggles with descriptions at boot
So you can easily inspect and activate new features without trying to use them first. It brings more visibility and will enable us to easily remove retired features as well.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
require "flipper"
|
||||
require "flipper/adapters/active_record"
|
||||
require "open_food_network/feature_toggle"
|
||||
|
||||
if Rails.env.production?
|
||||
Flipper::UI.configure do |config|
|
||||
@@ -9,3 +10,17 @@ if Rails.env.production?
|
||||
end
|
||||
|
||||
Flipper.register(:admins) { |actor| actor.respond_to?(:admin?) && actor.admin? }
|
||||
|
||||
Flipper::UI.configure do |config|
|
||||
config.descriptions_source = ->(_keys) do
|
||||
# return has to be hash of {String key => String description}
|
||||
OpenFoodNetwork::FeatureToggle::CURRENT_FEATURES
|
||||
end
|
||||
|
||||
# Defaults to false. Set to true to show feature descriptions on the list
|
||||
# page as well as the view page.
|
||||
# config.show_feature_description_in_list = true
|
||||
end
|
||||
|
||||
# Add known feature toggles. This may fail if the database isn't setup yet.
|
||||
OpenFoodNetwork::FeatureToggle.setup! rescue ActiveRecord::StatementInvalid
|
||||
|
||||
@@ -7,6 +7,58 @@ module OpenFoodNetwork
|
||||
# - http://localhost:3000/admin/feature-toggle/features
|
||||
#
|
||||
module FeatureToggle
|
||||
# Please add your new feature here to appear in the Flipper UI.
|
||||
# We way move this to a YAML file when it becomes too awkward.
|
||||
CURRENT_FEATURES = {
|
||||
"admin_style_v2" => <<~DESC,
|
||||
Change some colour and layout in the backend to a newer version.
|
||||
DESC
|
||||
"api_reports" => <<~DESC,
|
||||
An API endpoint for reports at
|
||||
<code>/api/v0/reports/:report_type(/:report_subtype)</code>
|
||||
DESC
|
||||
"api_v1" => <<~DESC,
|
||||
Enable the new API at <code>/api/v1</code>
|
||||
DESC
|
||||
"background_reports" => <<~DESC,
|
||||
Generate reports in a background process to limit memory consumption.
|
||||
DESC
|
||||
"dfc_provider" => <<~DESC,
|
||||
Enable the DFC compatible endpoint at <code>/api/dfc-*</code>.
|
||||
DESC
|
||||
"match_shipping_categories" => <<~DESC,
|
||||
During checkout, show only shipping methods that support <em>all</em>
|
||||
shipping categories. Activating this feature for an enterprise owner
|
||||
will activate it for all shops of this enterprise.
|
||||
DESC
|
||||
"new_products_page" => <<~DESC,
|
||||
Show the new (experimental) version of the admin products page.
|
||||
DESC
|
||||
"split_checkout" => <<~DESC,
|
||||
Replace the one-page checkout with a multi-step checkout.
|
||||
DESC
|
||||
}.freeze
|
||||
|
||||
# Move your feature entry from CURRENT_FEATURES to RETIRED_FEATURES when
|
||||
# you remove it from the code. It will then be deleted from the database.
|
||||
#
|
||||
# We may delete this field one day and regard all features not listed in
|
||||
# CURRENT_FEATURES as unsupported and remove them. But until this approach
|
||||
# is accepted we delete only the features listed here.
|
||||
RETIRED_FEATURES = {}.freeze
|
||||
|
||||
def self.setup!
|
||||
CURRENT_FEATURES.each_key do |name|
|
||||
feature = Flipper.feature(name)
|
||||
feature.add unless feature.exist?
|
||||
end
|
||||
|
||||
RETIRED_FEATURES.each_key do |name|
|
||||
feature = Flipper.feature(name)
|
||||
feature.remove if feature.exist?
|
||||
end
|
||||
end
|
||||
|
||||
def self.enabled?(feature_name, user = nil)
|
||||
feature = Flipper.feature(feature_name)
|
||||
feature.add unless feature.exist?
|
||||
|
||||
Reference in New Issue
Block a user