Merge pull request #7896 from tchak/cleanup-flipper-use

chore(flipper): always use feature_enabled? helper
This commit is contained in:
Paul Chavard 2022-10-12 14:20:52 +02:00 committed by GitHub
commit cb46cf1429
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 22 additions and 22 deletions

View file

@ -1,7 +1,12 @@
class ApplicationComponent < ViewComponent::Base class ApplicationComponent < ViewComponent::Base
include ViewComponent::Translatable include ViewComponent::Translatable
include FlipperHelper
def class_names(class_names) def class_names(class_names)
class_names.to_a.filter_map { |(class_name, flag)| class_name if flag }.join(' ') class_names.to_a.filter_map { |(class_name, flag)| class_name if flag }.join(' ')
end end
def current_user
controller.current_user
end
end end

View file

@ -6,6 +6,6 @@
%span.updated-at{ class: highlight_if_unseen_class } %span.updated-at{ class: highlight_if_unseen_class }
= "modifié le #{try_format_datetime(@champ.updated_at)}" = "modifié le #{try_format_datetime(@champ.updated_at)}"
- if @champ.rebased_at.present? && @champ.rebased_at > (@seen_at || @champ.updated_at) && controller.current_user.owns_or_invite?(@champ.dossier) - if @champ.rebased_at.present? && @champ.rebased_at > (@seen_at || @champ.updated_at) && current_user.owns_or_invite?(@champ.dossier)
%span.updated-at.highlighted %span.updated-at.highlighted
Le type de ce @champ où sa description a été modifiée par l'administration. Vérifier son contenu. Le type de ce @champ où sa description a été modifiée par l'administration. Vérifier son contenu.

View file

@ -56,7 +56,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent
end end
def types_of_type_de_champ def types_of_type_de_champ
if Flipper.enabled?(:categories_type_de_champ, controller.current_user) if feature_enabled?(:categories_type_de_champ)
cat_scope = "activerecord.attributes.type_de_champ.categorie" cat_scope = "activerecord.attributes.type_de_champ.categorie"
tdc_scope = "activerecord.attributes.type_de_champ.type_champs" tdc_scope = "activerecord.attributes.type_de_champ.type_champs"
@ -105,7 +105,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent
def filter_featured_type_champ(type_champ) def filter_featured_type_champ(type_champ)
feature_name = TypeDeChamp::FEATURE_FLAGS[type_champ] feature_name = TypeDeChamp::FEATURE_FLAGS[type_champ]
feature_name.blank? || Flipper.enabled?(feature_name, helpers.current_user) feature_name.blank? || feature_enabled?(feature_name)
end end
def filter_type_champ(type_champ) def filter_type_champ(type_champ)
@ -133,7 +133,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent
if type_de_champ.private? || coordinate.child? if type_de_champ.private? || coordinate.child?
false false
else else
procedure.feature_enabled?(:procedure_conditional) || Flipper.enabled?(:conditional, controller.current_user) procedure.feature_enabled?(:procedure_conditional)
end end
end end
end end

View file

@ -19,7 +19,7 @@
%span.sr-only Déplacer le champ vers le bas %span.sr-only Déplacer le champ vers le bas
.cell.flex.justify-start.column.flex-grow .cell.flex.justify-start.column.flex-grow
= form.label :type_champ, "Type de champ", for: dom_id(type_de_champ, :type_champ) = form.label :type_champ, "Type de champ", for: dom_id(type_de_champ, :type_champ)
- if Flipper.enabled?(:categories_type_de_champ, controller.current_user) - if feature_enabled?(:categories_type_de_champ)
= form.select :type_champ, grouped_options_for_select(types_of_type_de_champ, type_de_champ.type_champ), {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ) = form.select :type_champ, grouped_options_for_select(types_of_type_de_champ, type_de_champ.type_champ), {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ)
- else - else
= form.select :type_champ, types_of_type_de_champ, {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ) = form.select :type_champ, types_of_type_de_champ, {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ)

View file

@ -53,7 +53,7 @@ class Commentaire < ApplicationRecord
def redacted_email def redacted_email
if sent_by_instructeur? if sent_by_instructeur?
if Flipper.enabled?(:hide_instructeur_email, dossier.procedure) if dossier.procedure.feature_enabled?(:hide_instructeur_email)
"Instructeur n° #{instructeur.id}" "Instructeur n° #{instructeur.id}"
else else
instructeur.email.split('@').first instructeur.email.split('@').first

View file

@ -666,7 +666,7 @@ class Procedure < ApplicationRecord
end end
def missing_zones? def missing_zones?
if Flipper.enabled?(:zonage) if feature_enabled?(:zonage)
zones.empty? zones.empty?
else else
false false

View file

@ -62,7 +62,7 @@
= f.label :lien_dpo, 'Lien ou email pour contacter le Délégué à la Protection des Données (DPO)' = f.label :lien_dpo, 'Lien ou email pour contacter le Délégué à la Protection des Données (DPO)'
= f.text_field :lien_dpo, class: 'form-control' = f.text_field :lien_dpo, class: 'form-control'
- if Flipper.enabled? :opendata, @procedure - if @procedure.feature_enabled?(:opendata)
%h3.header-subsection= t(:opendata_header, scope: [:administrateurs, :informations]) %h3.header-subsection= t(:opendata_header, scope: [:administrateurs, :informations])
%p.notice= t(:opendata_notice_html, scope: [:administrateurs, :informations]) %p.notice= t(:opendata_notice_html, scope: [:administrateurs, :informations])
%p.notice= t(:opendata, scope: [:administrateurs, :informations]) %p.notice= t(:opendata, scope: [:administrateurs, :informations])

View file

@ -58,7 +58,7 @@
%h2.procedure-admin-explanation Indispensable avant publication %h2.procedure-admin-explanation Indispensable avant publication
.procedure-grid .procedure-grid
= render Procedure::Card::PresentationComponent.new(procedure: @procedure) = render Procedure::Card::PresentationComponent.new(procedure: @procedure)
= render Procedure::Card::ZonesComponent.new(procedure: @procedure) if Flipper.enabled? :zonage = render Procedure::Card::ZonesComponent.new(procedure: @procedure) if @procedure.feature_enabled?(:zonage)
= render Procedure::Card::ChampsComponent.new(procedure: @procedure) = render Procedure::Card::ChampsComponent.new(procedure: @procedure)
= render Procedure::Card::ServiceComponent.new(procedure: @procedure, administrateur: current_administrateur) = render Procedure::Card::ServiceComponent.new(procedure: @procedure, administrateur: current_administrateur)
= render Procedure::Card::AdministrateursComponent.new(procedure: @procedure) = render Procedure::Card::AdministrateursComponent.new(procedure: @procedure)

View file

@ -14,7 +14,7 @@
= f.label :zone do = f.label :zone do
= t('zone', scope: 'activerecord.attributes.procedure') = t('zone', scope: 'activerecord.attributes.procedure')
- if Flipper.enabled? :zonage - if @procedure.feature_enabled?(:zonage)
= f.collection_check_boxes :zone_ids, Zone.available_at(@procedure.published_or_created_at), :id, :label do |b| = f.collection_check_boxes :zone_ids, Zone.available_at(@procedure.published_or_created_at), :id, :label do |b|
.editable-champ.editable-champ-checkbox .editable-champ.editable-champ-checkbox
= b.check_box = b.check_box

View file

@ -35,7 +35,7 @@ RSpec.describe Dossiers::MessageComponent, type: :component do
let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) } let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) }
context 'on a procedure with anonymous instructeurs' do context 'on a procedure with anonymous instructeurs' do
before { Flipper.enable_actor(:hide_instructeur_email, procedure) } before { Flipper.enable(:hide_instructeur_email, procedure) }
context 'redacts the instructeur email' do context 'redacts the instructeur email' do
it { is_expected.to have_text(commentaire.body) } it { is_expected.to have_text(commentaire.body) }
@ -45,7 +45,7 @@ RSpec.describe Dossiers::MessageComponent, type: :component do
end end
context 'on a procedure where instructeurs names are not redacted' do context 'on a procedure where instructeurs names are not redacted' do
before { Flipper.disable_actor(:hide_instructeur_email, procedure) } before { Flipper.disable(:hide_instructeur_email, procedure) }
context 'redacts the instructeur email but keeps the name' do context 'redacts the instructeur email but keeps the name' do
it { is_expected.to have_text(commentaire.body) } it { is_expected.to have_text(commentaire.body) }

View file

@ -1254,10 +1254,6 @@ describe Procedure do
Flipper.enable :zonage Flipper.enable :zonage
end end
after do
Flipper.disable :zonage
end
let(:procedure) { create(:procedure, zones: []) } let(:procedure) { create(:procedure, zones: []) }
subject { procedure.missing_zones? } subject { procedure.missing_zones? }
@ -1278,10 +1274,6 @@ describe Procedure do
Flipper.enable :zonage Flipper.enable :zonage
end end
after do
Flipper.disable :zonage
end
subject { procedure.missing_steps.include?(step) } subject { procedure.missing_steps.include?(step) }
context 'without zone' do context 'without zone' do

View file

@ -120,6 +120,10 @@ RSpec.configure do |config|
end end
end end
config.before(:each, type: Proc.new { |type| type != :system }) do
Flipper.instance = Flipper.new(Flipper::Adapters::Memory.new)
end
config.include Shoulda::Matchers::ActiveRecord, type: :model config.include Shoulda::Matchers::ActiveRecord, type: :model
config.include Shoulda::Matchers::ActiveModel, type: :model config.include Shoulda::Matchers::ActiveModel, type: :model
config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :controller

View file

@ -160,7 +160,6 @@ describe 'The user' do
scenario 'extends dossier experation date more than one time, ', js: true do scenario 'extends dossier experation date more than one time, ', js: true do
simple_procedure.update(procedure_expires_when_termine_enabled: true) simple_procedure.update(procedure_expires_when_termine_enabled: true)
allow(simple_procedure).to receive(:feature_enabled?).with(:procedure_process_expired_dossiers_termine).and_return(true)
user_old_dossier = create(:dossier, user_old_dossier = create(:dossier,
procedure: simple_procedure, procedure: simple_procedure,
created_at: simple_procedure.duree_conservation_dossiers_dans_ds.month.ago, created_at: simple_procedure.duree_conservation_dossiers_dans_ds.month.ago,

View file

@ -27,7 +27,7 @@ describe 'experts/avis/instruction.html.haml', type: :view do
context 'when an expert is not allowed to invite another expert' do context 'when an expert is not allowed to invite another expert' do
let(:confidentiel) { false } let(:confidentiel) { false }
before do before do
Flipper.enable_actor(:expert_not_allowed_to_invite, avis.procedure) Flipper.enable(:expert_not_allowed_to_invite, avis.procedure)
end end
it { is_expected.to have_no_text("Inviter des personnes à donner leur avis") } it { is_expected.to have_no_text("Inviter des personnes à donner leur avis") }
end end