From f3c46482f95551f33bcfd5844af27cec8b2460d1 Mon Sep 17 00:00:00 2001
From: Eugie Limpin <elimpin@gitlab.com>
Date: Wed, 14 Feb 2024 16:38:38 +0800
Subject: [PATCH] Add actor to auto_request_phone_number_verification_exemption
 FF

---
 .../telesign_callbacks_controller.rb                   | 10 +++++++---
 .../users/identity_verification_controller.rb          |  2 +-
 .../telesign_callbacks_controller_spec.rb              |  5 +++--
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/ee/app/controllers/phone_verification/telesign_callbacks_controller.rb b/ee/app/controllers/phone_verification/telesign_callbacks_controller.rb
index 5a55a32c1f619..7d371a06b3041 100644
--- a/ee/app/controllers/phone_verification/telesign_callbacks_controller.rb
+++ b/ee/app/controllers/phone_verification/telesign_callbacks_controller.rb
@@ -28,11 +28,15 @@ def callback
     end
 
     def exempt_user_from_phone_number_verification
-      return unless ::Feature.enabled?(:auto_request_phone_number_verification_exemption, type: :gitlab_com_derisk)
-
       user = callback.user
 
-      return unless user&.offer_phone_number_exemption?
+      return unless user
+
+      return unless ::Feature.enabled?(
+        :auto_request_phone_number_verification_exemption, user, type: :gitlab_com_derisk
+      )
+
+      return unless user.offer_phone_number_exemption?
 
       user.create_phone_number_exemption!
       Gitlab::EtagCaching::Store.new.touch(verification_state_identity_verification_path)
diff --git a/ee/app/controllers/users/identity_verification_controller.rb b/ee/app/controllers/users/identity_verification_controller.rb
index 26e1640cebafb..6ebe7f1e4aebf 100644
--- a/ee/app/controllers/users/identity_verification_controller.rb
+++ b/ee/app/controllers/users/identity_verification_controller.rb
@@ -31,7 +31,7 @@ class IdentityVerificationController < ApplicationController
     layout 'minimal'
 
     def show
-      push_frontend_feature_flag(:auto_request_phone_number_verification_exemption, type: :gitlab_com_derisk)
+      push_frontend_feature_flag(:auto_request_phone_number_verification_exemption, @user, type: :gitlab_com_derisk)
 
       # We to perform cookie migration for tracking from logged out to log in
       # calling this before tracking gives us access to request where the
diff --git a/ee/spec/requests/phone_verification/telesign_callbacks_controller_spec.rb b/ee/spec/requests/phone_verification/telesign_callbacks_controller_spec.rb
index fd22db8b84ef2..6fb5bd007eec3 100644
--- a/ee/spec/requests/phone_verification/telesign_callbacks_controller_spec.rb
+++ b/ee/spec/requests/phone_verification/telesign_callbacks_controller_spec.rb
@@ -81,6 +81,7 @@
 
         before do
           allow(user).to receive(:offer_phone_number_exemption?).and_return(true)
+          stub_feature_flags(auto_request_phone_number_verification_exemption: user)
         end
 
         it 'exempts the user' do
@@ -104,9 +105,9 @@
           it_behaves_like 'does not invalidate verification_state_identity_verification_path cache'
         end
 
-        context 'when auto_request_phone_number_verification_exemption feature flag is disabled' do
+        context 'when auto_request_phone_number_verification_exemption feature flag is disabled for user' do
           before do
-            stub_feature_flags(auto_request_phone_number_verification_exemption: false)
+            stub_feature_flags(auto_request_phone_number_verification_exemption: create(:user))
           end
 
           it_behaves_like 'does not exempt the user'
-- 
GitLab