@@ -222,7 +222,7 @@ public function process(array &$state): void
222
222
$ isHeadedToProfileUrl = self ::isHeadedToProfileUrl ($ state , $ this ->profileUrl );
223
223
224
224
$ mfa = $ this ->getAttributeAllValues ('mfa ' , $ state );
225
- $ method = $ this ->getAttributeAllValues ( ' method ' , $ state );
225
+ $ method = $ this ->getMethod ( $ state );
226
226
$ profileReview = $ this ->getAttribute ('profile_review ' , $ state );
227
227
228
228
if (!$ isHeadedToProfileUrl ) {
@@ -240,7 +240,7 @@ public function process(array &$state): void
240
240
}
241
241
242
242
if (self ::needToShow ($ profileReview , self ::REVIEW_PAGE )) {
243
- $ this ->redirectToProfileReview ($ state , $ employeeId, $ mfa [ ' options ' ], $ method [ ' options ' ] );
243
+ $ this ->redirectToProfileReview ($ state , $ employeeId );
244
244
}
245
245
}
246
246
@@ -264,48 +264,37 @@ public function process(array &$state): void
264
264
*
265
265
* @param array $state The state data.
266
266
* @param string $employeeId The Employee ID of the user account.
267
- * @param array $mfaOptions A list of the mfa options.
268
- * @param array $methodOptions A list of the method options.
269
267
*/
270
- protected function redirectToProfileReview (&$ state , $ employeeId , $ mfaOptions , $ methodOptions )
268
+ protected function redirectToProfileReview (array &$ state , string $ employeeId ): void
271
269
{
272
- assert ('is_array($state) ' );
273
-
274
- foreach ($ mfaOptions as $ key => $ mfaOption ) {
275
- if ($ mfaOption ['type ' ] === 'manager ' ) {
276
- unset ($ mfaOptions [$ key ]);
277
- }
278
- }
270
+ $ mfaOptions = $ this ->getAllMfaOptionsExceptManager ($ state );
271
+ $ methodOptions = $ this ->getMethod ($ state )['options ' ];
279
272
280
273
if (count ($ mfaOptions ) == 0 && count ($ methodOptions ) == 0 ) {
281
274
return ;
282
275
}
283
276
284
- /* Save state and redirect. */
285
- $ state ['employeeId ' ] = $ employeeId ;
286
- $ state ['profileUrl ' ] = $ this ->profileUrl ;
287
- $ state ['mfaOptions ' ] = $ mfaOptions ;
288
- $ state ['methodOptions ' ] = $ methodOptions ;
289
- $ state ['template ' ] = 'review ' ;
290
-
291
- $ stateId = State::saveState ($ state , self ::STAGE_SENT_TO_NAG );
292
- $ url = Module::getModuleURL ('profilereview/nag.php ' );
293
-
294
- $ httpUtils = new HTTP ();
295
- $ httpUtils ->redirectTrustedURL ($ url , array ('StateId ' => $ stateId ));
277
+ $ this ->redirectToNag ($ state , $ employeeId , 'review ' );
296
278
}
297
279
298
280
/**
281
+ * Redirect user to a template
282
+ *
299
283
* @param array $state
300
284
* @param string $employeeId
301
285
* @param string $template
302
286
*/
303
- protected function redirectToNag (&$ state , $ employeeId , $ template )
287
+ protected function redirectToNag (array &$ state , string $ employeeId , string $ template ): void
304
288
{
289
+ $ mfaOptions = $ this ->getAllMfaOptionsExceptManager ($ state );
290
+ $ methodOptions = $ this ->getMethod ($ state )['options ' ];
291
+
305
292
/* Save state and redirect. */
306
293
$ state ['employeeId ' ] = $ employeeId ;
307
294
$ state ['mfaLearnMoreUrl ' ] = $ this ->mfaLearnMoreUrl ;
308
295
$ state ['profileUrl ' ] = $ this ->profileUrl ;
296
+ $ state ['mfaOptions ' ] = $ mfaOptions ;
297
+ $ state ['methodOptions ' ] = $ methodOptions ;
309
298
$ state ['template ' ] = $ template ;
310
299
311
300
$ stateId = State::saveState ($ state , self ::STAGE_SENT_TO_NAG );
@@ -315,6 +304,22 @@ protected function redirectToNag(&$state, $employeeId, $template)
315
304
$ httpUtils ->redirectTrustedURL ($ url , array ('StateId ' => $ stateId ));
316
305
}
317
306
307
+ public function getMethod (array $ state ): ?array
308
+ {
309
+ return $ this ->getAttributeAllValues ('method ' , $ state );
310
+ }
311
+
312
+ protected function getAllMfaOptionsExceptManager (array $ state ): array
313
+ {
314
+ $ mfaOptions = $ this ->getAttributeAllValues ('mfa ' , $ state )['options ' ];
315
+ foreach ($ mfaOptions as $ key => $ mfaOption ) {
316
+ if ($ mfaOption ['type ' ] === 'manager ' ) {
317
+ unset ($ mfaOptions [$ key ]);
318
+ }
319
+ }
320
+ return $ mfaOptions ;
321
+ }
322
+
318
323
public static function hasSeenSplashPageRecently (string $ page )
319
324
{
320
325
$ session = Session::getSessionFromRequest ();
0 commit comments