Skip to content

Commit bb978d0

Browse files
authored
Merge pull request #278 from silinternational/idp-1043
Release 10.0.2 -- assign all values nag controller needs
2 parents 15fe0bf + 30710c2 commit bb978d0

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

modules/profilereview/src/Auth/Process/ProfileReview.php

+30-25
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function process(array &$state): void
222222
$isHeadedToProfileUrl = self::isHeadedToProfileUrl($state, $this->profileUrl);
223223

224224
$mfa = $this->getAttributeAllValues('mfa', $state);
225-
$method = $this->getAttributeAllValues('method', $state);
225+
$method = $this->getMethod($state);
226226
$profileReview = $this->getAttribute('profile_review', $state);
227227

228228
if (!$isHeadedToProfileUrl) {
@@ -240,7 +240,7 @@ public function process(array &$state): void
240240
}
241241

242242
if (self::needToShow($profileReview, self::REVIEW_PAGE)) {
243-
$this->redirectToProfileReview($state, $employeeId, $mfa['options'], $method['options']);
243+
$this->redirectToProfileReview($state, $employeeId);
244244
}
245245
}
246246

@@ -264,48 +264,37 @@ public function process(array &$state): void
264264
*
265265
* @param array $state The state data.
266266
* @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.
269267
*/
270-
protected function redirectToProfileReview(&$state, $employeeId, $mfaOptions, $methodOptions)
268+
protected function redirectToProfileReview(array &$state, string $employeeId): void
271269
{
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'];
279272

280273
if (count($mfaOptions) == 0 && count($methodOptions) == 0) {
281274
return;
282275
}
283276

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');
296278
}
297279

298280
/**
281+
* Redirect user to a template
282+
*
299283
* @param array $state
300284
* @param string $employeeId
301285
* @param string $template
302286
*/
303-
protected function redirectToNag(&$state, $employeeId, $template)
287+
protected function redirectToNag(array &$state, string $employeeId, string $template): void
304288
{
289+
$mfaOptions = $this->getAllMfaOptionsExceptManager($state);
290+
$methodOptions = $this->getMethod($state)['options'];
291+
305292
/* Save state and redirect. */
306293
$state['employeeId'] = $employeeId;
307294
$state['mfaLearnMoreUrl'] = $this->mfaLearnMoreUrl;
308295
$state['profileUrl'] = $this->profileUrl;
296+
$state['mfaOptions'] = $mfaOptions;
297+
$state['methodOptions'] = $methodOptions;
309298
$state['template'] = $template;
310299

311300
$stateId = State::saveState($state, self::STAGE_SENT_TO_NAG);
@@ -315,6 +304,22 @@ protected function redirectToNag(&$state, $employeeId, $template)
315304
$httpUtils->redirectTrustedURL($url, array('StateId' => $stateId));
316305
}
317306

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+
318323
public static function hasSeenSplashPageRecently(string $page)
319324
{
320325
$session = Session::getSessionFromRequest();

0 commit comments

Comments
 (0)