Skip to content

Commit

Permalink
MDL-78509 tool_mfa: Fixes based on the report and other issues
Browse files Browse the repository at this point in the history
In this commit, there are couple of fixes based on the report:
1. Removed legacy polyfill from provider.php
2. Fixed phpunit warning detected by CodeChecker
3. Removed unused files
4. Fixed the PHPunit failures by removing "securityquestions"
   from the data_provider due to it has not been included as one of the factors
5. Added PHPunit test to the factors that can be unittested
6. Removed !important rule from tool_mfa/styles.css
7. Added (int) type to sleep method within sleep_timer method due to a php deprecation
in too_mfa/classes/manager.php
8. Changed last param form bool to string in not_enough_factors() when initiating
a new single_button object in tool_mfa/renderer.php
9. Add explanation text to login page
10. Fixed "Access to an undefined property .." from PHPStan
12. Fixed all the "Variable $.. might not be defined" from PHPStan
13. Fixed the issue from catalyst/moodle-tool_mfa#379
  • Loading branch information
stevandoMoodle committed Aug 25, 2023
1 parent 02d9d9e commit b9a5f9c
Show file tree
Hide file tree
Showing 77 changed files with 880 additions and 669 deletions.
15 changes: 0 additions & 15 deletions admin/tool/mfa/.github/workflows/ci.yml

This file was deleted.

12 changes: 0 additions & 12 deletions admin/tool/mfa/README.md

This file was deleted.

3 changes: 1 addition & 2 deletions admin/tool/mfa/classes/local/form/setup_factor_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public function definition_after_data() {
}

/**
* In newer versions of Totara with consistent cleaning enabled we need to ensure to mark static elements
* as "xss safe". Or in Totara's ideal world to use 'html' if form-like display is not required.
* Form elements clean up
*
* @param \HTML_QuickForm $mform
* @return void
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/mfa/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public static function should_require_mfa($url, $preventredirect) {

// Site policy.
if (isset($USER->policyagreed) && !$USER->policyagreed) {
// Privacy classes may not exist in older Moodles/Totara.
// Privacy classes may not exist in older Moodles.
if (class_exists('\core_privacy\local\sitepolicy\manager')) {
$manager = new \core_privacy\local\sitepolicy\manager();
$policyurl = $manager->get_redirect_url(false);
Expand Down Expand Up @@ -596,7 +596,7 @@ public static function sleep_timer() {
$duration = 0.05;
}
set_user_preference('mfa_sleep_duration', $duration, $USER);
sleep($duration);
sleep((int)$duration);
}

/**
Expand Down
136 changes: 0 additions & 136 deletions admin/tool/mfa/db/upgrade.php

This file was deleted.

Empty file removed admin/tool/mfa/example1
Empty file.
Empty file removed admin/tool/mfa/example2
Empty file.
4 changes: 1 addition & 3 deletions admin/tool/mfa/factor/admin/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
namespace factor_admin\privacy;

use core_privacy\local\metadata\null_provider;
use core_privacy\local\legacy_polyfill;

/**
* Privacy provider.
Expand All @@ -28,15 +27,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements null_provider {
use legacy_polyfill;

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function _get_reason() {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
4 changes: 2 additions & 2 deletions admin/tool/mfa/factor/admin/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2019102400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2017051500.00; // Support back to 3.3 - Totara 12. Patches required.
$plugin->version = 2023080300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2023042400.00; // Supports from 4.2.
$plugin->component = 'factor_admin';
$plugin->release = 'v0.1';
$plugin->maturity = MATURITY_STABLE;
Expand Down
4 changes: 1 addition & 3 deletions admin/tool/mfa/factor/auth/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
namespace factor_auth\privacy;

use core_privacy\local\metadata\null_provider;
use core_privacy\local\legacy_polyfill;

/**
* Privacy provider.
Expand All @@ -28,15 +27,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements null_provider {
use legacy_polyfill;

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function _get_reason() {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
4 changes: 2 additions & 2 deletions admin/tool/mfa/factor/auth/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021020500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2017051500.00; // Support back to 3.3 - Totara 12. Patches required.
$plugin->version = 2023080300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2023042400.00; // Supports from 4.2.
$plugin->component = 'factor_auth';
$plugin->release = 2021020500;
$plugin->maturity = MATURITY_STABLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
namespace factor_capability\privacy;

use core_privacy\local\metadata\null_provider;
use core_privacy\local\legacy_polyfill;

/**
* Privacy provider.
Expand All @@ -28,15 +27,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements null_provider {
use legacy_polyfill;

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function _get_reason() {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
6 changes: 3 additions & 3 deletions admin/tool/mfa/factor/capability/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2020071400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2017051500.00; // Support back to 3.3 - Totara 12. Patches required.
$plugin->version = 2023080300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2023042400.00; // Supports from 4.2.
$plugin->component = 'factor_capability';
$plugin->release = 'v0.1';
$plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = ['tool_mfa' => 2019102400];
$plugin->dependencies = ['tool_mfa' => 2023080300];
28 changes: 21 additions & 7 deletions admin/tool/mfa/factor/cohort/classes/factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,29 @@ public function get_summary_condition() {
$selectedcohorts = get_config('factor_cohort', 'cohorts');
if (empty($selectedcohorts)) {
return get_string('summarycondition', 'factor_cohort', get_string('none'));
} else {
$selectedcohorts = explode(',', $selectedcohorts);
}
$names = [];
foreach ($selectedcohorts as $cohort) {

return get_string('summarycondition', 'factor_cohort', $this->get_cohorts($selectedcohorts));
}

/**
* Get string lang for the cohorts.
*
* @param string $selectedcohorts
* @return string
*/
public function get_cohorts(string $selectedcohorts) : string {
global $DB;

$cohorts = [];
foreach (explode(',', $selectedcohorts) as $cohort) {
if ($cohort === 'admin') {
$cohorts[] = get_string('administrator');
} else {
$record = $DB->get_record('cohort', ['id' => $cohort]);
$names[] = $record->name;
$cohorts[] = $record->name;
}
}
$string = implode(', ', $names);
return get_string('summarycondition', 'factor_cohort', $string);
return implode(', ', $cohorts);
}
}
4 changes: 1 addition & 3 deletions admin/tool/mfa/factor/cohort/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
namespace factor_cohort\privacy;

use core_privacy\local\metadata\null_provider;
use core_privacy\local\legacy_polyfill;

/**
* Privacy provider.
Expand All @@ -28,15 +27,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements null_provider {
use legacy_polyfill;

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function _get_reason() {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
Loading

0 comments on commit b9a5f9c

Please sign in to comment.