Remplacement de la feature Flipper instructeur_bypass_email_login_token 3/3 (#6681)

This commit is contained in:
Pierre de La Morinerie 2021-12-02 08:56:21 +01:00 committed by GitHub
commit 9ae4361f59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 7 additions and 28 deletions

View file

@ -224,7 +224,7 @@ class ApplicationController < ActionController::Base
def redirect_if_untrusted
if instructeur_signed_in? &&
sensitive_path &&
!feature_enabled?(:instructeur_bypass_email_login_token) &&
!current_instructeur.bypass_email_login_token &&
!IPService.ip_trusted?(request.headers['X-Forwarded-For']) &&
!trusted_device?

View file

@ -1,23 +1,5 @@
module Manager
class InstructeursController < Manager::ApplicationController
# Temporary code: synchronize Flipper's instructeur_bypass_email_login_token
# when Instructeur.bypass_email_login_token is modified.
#
# This will be removed when the migration of this feature flag out of Flipper will be complete.
def update
super
instructeur = requested_resource
saved_successfully = !requested_resource.changed?
if saved_successfully
if instructeur.bypass_email_login_token
Flipper.enable_actor(:instructeur_bypass_email_login_token, instructeur.user)
else
Flipper.disable_actor(:instructeur_bypass_email_login_token, instructeur.user)
end
end
end
def reinvite
instructeur = Instructeur.find(params[:id])
instructeur.user.invite!

View file

@ -63,8 +63,8 @@ module TPS
end
config.middleware.use Rack::Attack
config.middleware.use Flipper::Middleware::Memoizer,
preload: [:instructeur_bypass_email_login_token]
# Ensure we make maximum one call per feature per request.
config.middleware.use Flipper::Middleware::Memoizer
config.ds_env = ENV.fetch('DS_ENV', Rails.env)

View file

@ -30,7 +30,6 @@ features = [
:dossier_pdf_vide,
:expert_not_allowed_to_invite,
:hide_instructeur_email,
:instructeur_bypass_email_login_token,
:procedure_revisions,
:procedure_routage_api,
:procedure_process_expired_dossiers_termine

View file

@ -165,7 +165,7 @@ describe ApplicationController, type: :controller do
let(:sensitive_path) { true }
before do
Flipper.disable(:instructeur_bypass_email_login_token)
current_instructeur.update!(bypass_email_login_token: false)
end
context 'when the instructeur is signed_in' do

View file

@ -2,6 +2,8 @@ FactoryBot.define do
sequence(:instructeur_email) { |n| "inst#{n}@inst.com" }
factory :instructeur do
bypass_email_login_token { true }
user { association :user, email: email, password: password }
transient do

View file

@ -89,10 +89,6 @@ RSpec.configure do |config|
Geocoder.configure(lookup: :test)
end
config.before(:each) do
Flipper.enable(:instructeur_bypass_email_login_token)
end
# By default, forgery protection is disabled in the test environment.
# (See `config.action_controller.allow_forgery_protection` in `config/test.rb`)
#

View file

@ -17,7 +17,7 @@ module SystemHelpers
fill_in :user_password, with: password
if sign_in_by_link
Flipper.disable(:instructeur_bypass_email_login_token)
User.find_by(email: email)&.instructeur&.update!(bypass_email_login_token: false)
end
perform_enqueued_jobs do