Migrate to flipper
This commit is contained in:
parent
28d869e818
commit
65e227c44b
33 changed files with 186 additions and 181 deletions
|
@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base
|
|||
before_action :set_raven_context
|
||||
before_action :redirect_if_untrusted
|
||||
before_action :authorize_request_for_profiler
|
||||
before_action :reject, if: -> { Flipflop.maintenance_mode? }
|
||||
before_action :reject, if: -> { feature_enabled?(:maintenance_mode) }
|
||||
|
||||
before_action :staging_authenticate
|
||||
before_action :set_active_storage_host
|
||||
|
@ -28,7 +28,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def authorize_request_for_profiler
|
||||
if Flipflop.mini_profiler_enabled?
|
||||
if feature_enabled?(:mini_profiler)
|
||||
Rack::MiniProfiler.authorize_request
|
||||
end
|
||||
end
|
||||
|
@ -77,6 +77,10 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
protected
|
||||
|
||||
def feature_enabled?(feature_name)
|
||||
Flipper.enabled?(feature_name, current_user)
|
||||
end
|
||||
|
||||
def authenticate_logged_user!
|
||||
if instructeur_signed_in?
|
||||
authenticate_instructeur!
|
||||
|
@ -190,7 +194,7 @@ class ApplicationController < ActionController::Base
|
|||
def redirect_if_untrusted
|
||||
if instructeur_signed_in? &&
|
||||
sensitive_path &&
|
||||
!Flipflop.bypass_email_login_token? &&
|
||||
!feature_enabled?(:instructeur_bypass_email_login_token) &&
|
||||
!IPService.ip_trusted?(request.headers['X-Forwarded-For']) &&
|
||||
!trusted_device?
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def telecharger_pjs
|
||||
return head(:forbidden) if !Flipflop.download_as_zip_enabled? || !dossier.attachments_downloadable?
|
||||
return head(:forbidden) if !feature_enabled?(:instructeur_download_as_zip) || !dossier.attachments_downloadable?
|
||||
|
||||
files = ActiveStorage::DownloadableFile.create_list_from_dossier(dossier)
|
||||
|
||||
|
|
|
@ -19,20 +19,6 @@ module Manager
|
|||
redirect_to manager_administrateur_path(params[:id])
|
||||
end
|
||||
|
||||
def enable_feature
|
||||
administrateur = Administrateur.find(params[:id])
|
||||
|
||||
params[:features].each do |key, enable|
|
||||
if enable
|
||||
administrateur.enable_feature(key.to_sym)
|
||||
else
|
||||
administrateur.disable_feature(key.to_sym)
|
||||
end
|
||||
end
|
||||
|
||||
head :ok
|
||||
end
|
||||
|
||||
def delete
|
||||
administrateur = Administrateur.find(params[:id])
|
||||
|
||||
|
|
|
@ -6,19 +6,5 @@ module Manager
|
|||
flash[:notice] = "Instructeur réinvité."
|
||||
redirect_to manager_instructeur_path(instructeur)
|
||||
end
|
||||
|
||||
def enable_feature
|
||||
instructeur = Instructeur.find(params[:id])
|
||||
|
||||
params[:features].each do |key, enable|
|
||||
if enable
|
||||
instructeur.enable_feature(key.to_sym)
|
||||
else
|
||||
instructeur.disable_feature(key.to_sym)
|
||||
end
|
||||
end
|
||||
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,5 +6,19 @@ module Manager
|
|||
flash[:notice] = "L'email d'activation de votre compte a été renvoyé."
|
||||
redirect_to manager_user_path(user)
|
||||
end
|
||||
|
||||
def enable_feature
|
||||
user = User.find(params[:id])
|
||||
|
||||
params[:features].each do |key, enable|
|
||||
if enable
|
||||
Flipper.enable_actor(key.to_sym, user)
|
||||
else
|
||||
Flipper.disable_actor(key.to_sym, user)
|
||||
end
|
||||
end
|
||||
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
5
app/helpers/flipper_helper.rb
Normal file
5
app/helpers/flipper_helper.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module FlipperHelper
|
||||
def feature_enabled?(feature_name)
|
||||
Flipper.enabled?(feature_name, current_user)
|
||||
end
|
||||
end
|
|
@ -50,7 +50,7 @@ module ProcedureHelper
|
|||
private
|
||||
|
||||
TOGGLES = {
|
||||
TypeDeChamp.type_champs.fetch(:integer_number) => :champ_integer_number?
|
||||
TypeDeChamp.type_champs.fetch(:integer_number) => :administrateur_champ_integer_number
|
||||
}
|
||||
|
||||
def types_de_champ_types
|
||||
|
@ -58,7 +58,7 @@ module ProcedureHelper
|
|||
|
||||
types_de_champ_types.select! do |tdc|
|
||||
toggle = TOGGLES[tdc.last]
|
||||
toggle.blank? || Flipflop.send(toggle)
|
||||
toggle.blank? || feature_enabled?(toggle)
|
||||
end
|
||||
|
||||
types_de_champ_types
|
||||
|
|
|
@ -44,7 +44,7 @@ class ApiEntreprise::API
|
|||
def self.url(resource_name, siret_or_siren)
|
||||
base_url = [API_ENTREPRISE_URL, resource_name, siret_or_siren].join("/")
|
||||
|
||||
if Flipflop.insee_api_v3?
|
||||
if Flipper.enabled?(:insee_api_v3)
|
||||
base_url += "?with_insee_v3=true"
|
||||
end
|
||||
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
module Flipflop::Strategies
|
||||
class UserPreferenceStrategy < AbstractStrategy
|
||||
def self.default_description
|
||||
"Allows configuration of features per user."
|
||||
end
|
||||
|
||||
def switchable?
|
||||
false
|
||||
end
|
||||
|
||||
def enabled?(feature)
|
||||
find_current_administrateur&.feature_enabled?(feature) ||
|
||||
find_current_instructeur&.feature_enabled?(feature)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_current_administrateur
|
||||
administrateur_id = Current.administrateur&.id
|
||||
if administrateur_id
|
||||
Administrateur.find_by(id: administrateur_id)
|
||||
end
|
||||
end
|
||||
|
||||
def find_current_instructeur
|
||||
instructeur_id = Current.instructeur&.id
|
||||
if instructeur_id
|
||||
Instructeur.find_by(id: instructeur_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -72,23 +72,6 @@ class Administrateur < ApplicationRecord
|
|||
administrateur
|
||||
end
|
||||
|
||||
def feature_enabled?(feature)
|
||||
Flipflop.feature_set.feature(feature)
|
||||
features[feature.to_s]
|
||||
end
|
||||
|
||||
def disable_feature(feature)
|
||||
Flipflop.feature_set.feature(feature)
|
||||
features.delete(feature.to_s)
|
||||
save
|
||||
end
|
||||
|
||||
def enable_feature(feature)
|
||||
Flipflop.feature_set.feature(feature)
|
||||
features[feature.to_s] = true
|
||||
save
|
||||
end
|
||||
|
||||
def owns?(procedure)
|
||||
procedure.administrateurs.include?(self)
|
||||
end
|
||||
|
|
|
@ -66,7 +66,7 @@ class DossierOperationLog < ApplicationRecord
|
|||
def self.serialize_subject(subject)
|
||||
if subject.nil?
|
||||
nil
|
||||
elsif !Flipflop.operation_log_serialize_subject?
|
||||
elsif !Flipper.enabled?(:operation_log_serialize_subject)
|
||||
{ id: subject.id }
|
||||
else
|
||||
case subject
|
||||
|
|
|
@ -180,23 +180,6 @@ class Instructeur < ApplicationRecord
|
|||
Follow.where(instructeur: self, dossier: dossier).update_all(attributes)
|
||||
end
|
||||
|
||||
def feature_enabled?(feature)
|
||||
Flipflop.feature_set.feature(feature)
|
||||
features[feature.to_s]
|
||||
end
|
||||
|
||||
def disable_feature(feature)
|
||||
Flipflop.feature_set.feature(feature)
|
||||
features.delete(feature.to_s)
|
||||
save
|
||||
end
|
||||
|
||||
def enable_feature(feature)
|
||||
Flipflop.feature_set.feature(feature)
|
||||
features[feature.to_s] = true
|
||||
save
|
||||
end
|
||||
|
||||
def young_login_token?
|
||||
trusted_device_token = trusted_device_tokens.order(created_at: :desc).first
|
||||
trusted_device_token&.token_young?
|
||||
|
|
|
@ -87,6 +87,10 @@ class User < ApplicationRecord
|
|||
user
|
||||
end
|
||||
|
||||
def flipper_id
|
||||
"User:#{id}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def link_invites!
|
||||
|
|
|
@ -125,7 +125,7 @@
|
|||
.col-md-6
|
||||
%h4 Options avancées
|
||||
|
||||
- if Flipflop.web_hook?
|
||||
- if feature_enabled?(:administrateur_web_hook)
|
||||
%label{ for: :web_hook_url } Lien de rappel HTTP (webhook)
|
||||
= f.text_field :web_hook_url, class: 'form-control', placeholder: 'https://callback.exemple.fr/'
|
||||
%p.help-block
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
:ruby
|
||||
url = if field.resource.class.name == 'Instructeur'
|
||||
enable_feature_manager_instructeur_path(field.resource.id)
|
||||
else
|
||||
enable_feature_manager_administrateur_path(field.resource.id)
|
||||
end
|
||||
group = field.resource.class.name.downcase
|
||||
user = field.resource.user
|
||||
url = enable_feature_manager_user_path(user)
|
||||
|
||||
%table#features
|
||||
- admin_features = Flipflop.feature_set.features.reject{ |f| f.group.try(:key) == :production }
|
||||
- admin_features.each do |feature|
|
||||
- Flipper.features.select { |feature| feature.key.start_with?("#{group}_") }.each do |feature|
|
||||
%tr
|
||||
%td= feature.title
|
||||
%td= feature
|
||||
%td
|
||||
= check_box_tag "enable-feature", "enable", field.data[feature.name], data: { url: url, key: feature.key }
|
||||
= check_box_tag "enable-feature", "enable", feature.enabled?(user), data: { url: url, key: feature.key }
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
%li
|
||||
= link_to "Uniquement cet onglet", "#", onclick: "window.print()", class: "menu-item menu-link"
|
||||
|
||||
- if Flipflop.download_as_zip_enabled? && !PiecesJustificativesService.liste_pieces_justificatives(dossier).empty?
|
||||
- if feature_enabled?(:instructeur_download_as_zip) && !PiecesJustificativesService.liste_pieces_justificatives(dossier).empty?
|
||||
%span.dropdown.print-menu-opener
|
||||
%button.button.dropdown-button.icon-only
|
||||
%span.icon.attachment
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
- if Flipflop.pre_maintenance_mode?
|
||||
- if feature_enabled?(:pre_maintenance_mode)
|
||||
.maintenance
|
||||
%span
|
||||
Une opération de maintenance est prévue sur demarches-simplifiees.fr à 23 h 00. La plateforme sera inaccessible pendant une vingtaine de minutes.
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
= Gon::Base.render_data(camel_case: true, init: true, nonce: request.content_security_policy_nonce)
|
||||
|
||||
- if Flipflop.xray_enabled?
|
||||
- if feature_enabled?(:xray)
|
||||
= stylesheet_link_tag :xray
|
||||
|
||||
%body{ id: content_for(:page_id), class: browser.platform.ios? ? 'ios' : nil }
|
||||
|
@ -39,7 +39,7 @@
|
|||
- if content_for?(:footer)
|
||||
= content_for(:footer)
|
||||
|
||||
- if Flipflop.xray_enabled?
|
||||
- if feature_enabled?(:xray)
|
||||
= javascript_include_tag :xray
|
||||
|
||||
= yield :charts_js
|
||||
|
|
|
@ -24,5 +24,5 @@ as defined by the routes in the `admin/` namespace
|
|||
<hr />
|
||||
|
||||
<%= link_to "Delayed Jobs", manager_delayed_job_path, class: "navigation__link" %>
|
||||
<%= link_to "Features", manager_flipflop_path, class: "navigation__link" %>
|
||||
<%= link_to "Features", manager_flipper_path, class: "navigation__link" %>
|
||||
</nav>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue