Skip to content

Commit

Permalink
[#453] Ignore unknown factors when calculating passing score in grace…
Browse files Browse the repository at this point in the history
… mode
  • Loading branch information
matthewhilton committed Feb 15, 2024
1 parent 29963a6 commit 2d036d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,10 @@ public static function possible_factor_setup() {
}

/**
* Gets current user weight, up until first unknown factor.
* Gets current user weight
* @param bool $stoponunknown if true, will stop on the first unknown facotr.
*/
public static function get_cumulative_weight() {
public static function get_cumulative_weight($stoponunknown = true) {
$factors = \tool_mfa\plugininfo\factor::get_active_user_factor_types();
$totalweight = 0;
foreach ($factors as $factor) {
Expand All @@ -824,7 +825,7 @@ public static function get_cumulative_weight() {
if ($totalweight >= 100) {
break;
}
} else if ($factor->get_state() == \tool_mfa\plugininfo\factor::STATE_UNKNOWN) {
} else if ($stoponunknown && $factor->get_state() == \tool_mfa\plugininfo\factor::STATE_UNKNOWN) {
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion factor/grace/classes/factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public function get_state($redirectable = true) {
}

// We should never redirect if we have already passed.
if ($redirectable && \tool_mfa\manager::get_cumulative_weight() >= 100) {
// Do not stop on unknown, to avoid factors e.g. login banner from
// hiding passing factors lower down in the list.
if ($redirectable && \tool_mfa\manager::get_cumulative_weight(false) >= 100) {
$redirectable = false;
}

Expand Down

0 comments on commit 2d036d6

Please sign in to comment.