Skip to content

Commit 16c06b1

Browse files
scott-nzScopeyNZ
authored andcommitted
If a user has already registered for MFA, enforce use of it even if they are not in an MFA group
Minor PR changes Update src/Extension/SiteConfigExtension.php Co-authored-by: Guy Marriott <guy.the.person@gmail.com>
1 parent f63a652 commit 16c06b1

3 files changed

Lines changed: 11 additions & 14 deletions

File tree

src/Extension/SiteConfigExtension.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,12 @@ public function updateCMSFields(FieldList $fields)
6969
));
7070
$mfaGraceEnd->addExtraClass('mfa-settings__grace-period');
7171

72-
$mapFn = function ($groups = []) {
73-
$map = [];
74-
foreach ($groups as $group) {
75-
// Listboxfield values are escaped, use ASCII char instead of &raquo;
76-
$map[$group->ID] = $group->getBreadcrumbs(' > ');
77-
}
78-
asort($map);
79-
return $map;
80-
};
81-
$groupsMap = $mapFn(Group::get());
72+
$groupsMap = [];
73+
foreach (Group::get() as $group) {
74+
// Listboxfield values are escaped, use ASCII char instead of &raquo;
75+
$groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
76+
}
77+
asort($groupsMap);
8278

8379
$mfaGroupRestrict = ListboxField::create(
8480
"MFAGroupRestrictions",
@@ -88,7 +84,8 @@ public function updateCMSFields(FieldList $fields)
8884
->setAttribute(
8985
'data-placeholder',
9086
_t(__CLASS__ . '.MFA_GROUP_RESTRICTIONS_PLACEHOLDER', 'Click to select group')
91-
)->setDescription(_t(
87+
)
88+
->setDescription(_t(
9289
__CLASS__ . '.MFA_GROUP_RESTRICTIONS_DESCRIPTION',
9390
'MFA will only be enabled for members of these selected groups. ' .
9491
'If no groups are selected, MFA will be enabled for all users'

src/Service/EnforcementManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function shouldRedirectToMFA(Member $member): bool
108108
return false;
109109
}
110110

111-
if (!$this->isUserInMFAEnabledGroup($member)) {
111+
if (!$this->isUserInMFAEnabledGroup($member) && !$this->hasCompletedRegistration($member)) {
112112
return false;
113113
}
114114

@@ -271,7 +271,7 @@ protected function isEnabled(): bool
271271
return true;
272272
}
273273

274-
protected function isUserInMFAEnabledGroup(Member $member)
274+
protected function isUserInMFAEnabledGroup(Member $member): bool
275275
{
276276
/** @var SiteConfig&SiteConfigExtension $siteConfig */
277277
$siteConfig = SiteConfig::current_site_config();

tests/Behat/features/mfa-enabled.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ Feature: MFA is enabled for the site
1414
Then I should see "Multi-factor authentication (MFA)"
1515
When I select "MFA is required for everyone" from the MFA settings
1616
And I press "Save"
17-
Then I should see "Saved"
17+
Then I should see a "Saved" success toast

0 commit comments

Comments
 (0)