diff --git a/app/components/application_component.rb b/app/components/application_component.rb index aa9c5eb56..8d88db6c2 100644 --- a/app/components/application_component.rb +++ b/app/components/application_component.rb @@ -1,7 +1,12 @@ class ApplicationComponent < ViewComponent::Base include ViewComponent::Translatable + include FlipperHelper def class_names(class_names) class_names.to_a.filter_map { |(class_name, flag)| class_name if flag }.join(' ') end + + def current_user + controller.current_user + end end diff --git a/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml b/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml index 9ac355378..81c5df6c8 100644 --- a/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml +++ b/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml @@ -6,6 +6,6 @@ %span.updated-at{ class: highlight_if_unseen_class } = "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 Le type de ce @champ où sa description a été modifiée par l'administration. Vérifier son contenu. diff --git a/app/components/types_de_champ_editor/champ_component.rb b/app/components/types_de_champ_editor/champ_component.rb index e3ddab62b..a901d459d 100644 --- a/app/components/types_de_champ_editor/champ_component.rb +++ b/app/components/types_de_champ_editor/champ_component.rb @@ -56,7 +56,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent end 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" tdc_scope = "activerecord.attributes.type_de_champ.type_champs" @@ -105,7 +105,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent def filter_featured_type_champ(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 def filter_type_champ(type_champ) @@ -133,7 +133,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent if type_de_champ.private? || coordinate.child? false else - procedure.feature_enabled?(:procedure_conditional) || Flipper.enabled?(:conditional, controller.current_user) + procedure.feature_enabled?(:procedure_conditional) end end end diff --git a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml index 828434a87..104a92eee 100644 --- a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml +++ b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml @@ -19,7 +19,7 @@ %span.sr-only Déplacer le champ vers le bas .cell.flex.justify-start.column.flex-grow = 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) - 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) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 05103e367..ac6eeb24e 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -53,7 +53,7 @@ class Commentaire < ApplicationRecord def redacted_email if sent_by_instructeur? - if Flipper.enabled?(:hide_instructeur_email, dossier.procedure) + if dossier.procedure.feature_enabled?(:hide_instructeur_email) "Instructeur n° #{instructeur.id}" else instructeur.email.split('@').first diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 98d47d10b..c8beda2e3 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -666,7 +666,7 @@ class Procedure < ApplicationRecord end def missing_zones? - if Flipper.enabled?(:zonage) + if feature_enabled?(:zonage) zones.empty? else false diff --git a/app/views/administrateurs/procedures/_informations.html.haml b/app/views/administrateurs/procedures/_informations.html.haml index dea314f0c..072f3befc 100644 --- a/app/views/administrateurs/procedures/_informations.html.haml +++ b/app/views/administrateurs/procedures/_informations.html.haml @@ -62,7 +62,7 @@ = 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' -- if Flipper.enabled? :opendata, @procedure +- if @procedure.feature_enabled?(:opendata) %h3.header-subsection= t(:opendata_header, scope: [:administrateurs, :informations]) %p.notice= t(:opendata_notice_html, scope: [:administrateurs, :informations]) %p.notice= t(:opendata, scope: [:administrateurs, :informations]) diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index 5df800982..4e443df92 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -58,7 +58,7 @@ %h2.procedure-admin-explanation Indispensable avant publication .procedure-grid = 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::ServiceComponent.new(procedure: @procedure, administrateur: current_administrateur) = render Procedure::Card::AdministrateursComponent.new(procedure: @procedure) diff --git a/app/views/administrateurs/procedures/zones.html.haml b/app/views/administrateurs/procedures/zones.html.haml index 393753149..dbafefc63 100644 --- a/app/views/administrateurs/procedures/zones.html.haml +++ b/app/views/administrateurs/procedures/zones.html.haml @@ -14,7 +14,7 @@ = f.label :zone do = 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| .editable-champ.editable-champ-checkbox = b.check_box diff --git a/spec/components/dossiers/message_component_spec.rb b/spec/components/dossiers/message_component_spec.rb index 9fb4b9d99..b159912c2 100644 --- a/spec/components/dossiers/message_component_spec.rb +++ b/spec/components/dossiers/message_component_spec.rb @@ -35,7 +35,7 @@ RSpec.describe Dossiers::MessageComponent, type: :component do let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) } 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 it { is_expected.to have_text(commentaire.body) } @@ -45,7 +45,7 @@ RSpec.describe Dossiers::MessageComponent, type: :component do end 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 it { is_expected.to have_text(commentaire.body) } diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 8080cec63..0dc5e5a50 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -1254,10 +1254,6 @@ describe Procedure do Flipper.enable :zonage end - after do - Flipper.disable :zonage - end - let(:procedure) { create(:procedure, zones: []) } subject { procedure.missing_zones? } @@ -1278,10 +1274,6 @@ describe Procedure do Flipper.enable :zonage end - after do - Flipper.disable :zonage - end - subject { procedure.missing_steps.include?(step) } context 'without zone' do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 3528d4433..340d3d75d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -120,6 +120,10 @@ RSpec.configure do |config| 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::ActiveModel, type: :model config.include Devise::Test::ControllerHelpers, type: :controller diff --git a/spec/system/users/brouillon_spec.rb b/spec/system/users/brouillon_spec.rb index 44e7cef76..062b39913 100644 --- a/spec/system/users/brouillon_spec.rb +++ b/spec/system/users/brouillon_spec.rb @@ -160,7 +160,6 @@ describe 'The user' do scenario 'extends dossier experation date more than one time, ', js: true do 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, procedure: simple_procedure, created_at: simple_procedure.duree_conservation_dossiers_dans_ds.month.ago, diff --git a/spec/views/experts/avis/instruction.html.haml_spec.rb b/spec/views/experts/avis/instruction.html.haml_spec.rb index 8b7afc3be..5ce2a54ef 100644 --- a/spec/views/experts/avis/instruction.html.haml_spec.rb +++ b/spec/views/experts/avis/instruction.html.haml_spec.rb @@ -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 let(:confidentiel) { false } before do - Flipper.enable_actor(:expert_not_allowed_to_invite, avis.procedure) + Flipper.enable(:expert_not_allowed_to_invite, avis.procedure) end it { is_expected.to have_no_text("Inviter des personnes à donner leur avis") } end