diff --git a/lib/classes/check/access/riskbackup.php b/lib/classes/check/access/riskbackup.php index 630efc37c7a..4339bd6fa2e 100644 --- a/lib/classes/check/access/riskbackup.php +++ b/lib/classes/check/access/riskbackup.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Abstract class for common properties of scheduled_task and adhoc_task. + * Lists all roles that have the ability to backup user data, as well as users * * @package core * @category check diff --git a/lib/classes/check/access/riskbackup_result.php b/lib/classes/check/access/riskbackup_result.php index 04105c70947..f4e9f4fd504 100644 --- a/lib/classes/check/access/riskbackup_result.php +++ b/lib/classes/check/access/riskbackup_result.php @@ -15,10 +15,7 @@ // along with Moodle. If not, see . /** - * Lists all users with XSS risk - * - * It would be great to combine this with risk trusts in user table, - * unfortunately nobody implemented user trust UI yet :-( + * Lists all roles that have the ability to backup user data, as well as users * * @package core * @category check @@ -29,15 +26,12 @@ namespace core\check\access; -defined('MOODLE_INTERNAL') || die(); - +use context; +use stdClass; use core\check\result; /** - * Lists all users with XSS risk - * - * It would be great to combine this with risk trusts in user table, - * unfortunately nobody implemented user trust UI yet :-( + * Lists all roles that have the ability to backup user data, as well as users * * @copyright 2020 Brendan Heywood * @copyright 2008 petr Skoda @@ -45,6 +39,15 @@ use core\check\result; */ class riskbackup_result extends \core\check\result { + /** @var stdClass[] $systemroles */ + private $systemroles; + + /** @var stdClass[] $overriddenroles */ + private $overriddenroles; + + /** @var string $sqluserinfo */ + private $sqluserinfo; + /** * Constructor */ @@ -62,8 +65,11 @@ class riskbackup_result extends \core\check\result { AND rc.permission = :permission"; $this->systemroles = $DB->get_records_sql($sql, $params); + // Ensure first field is unique (role.id + role_capabilities.contextid). + $roleidcontextfield = $DB->sql_concat_join("','", ['r.id', 'rc.contextid']); $params = array('capability' => 'moodle/backup:userinfo', 'permission' => CAP_ALLOW, 'contextid' => $syscontext->id); - $sql = "SELECT DISTINCT r.id, r.name, r.shortname, r.sortorder, r.archetype, rc.contextid + $sql = "SELECT DISTINCT {$roleidcontextfield} AS rolecontext, r.id, r.name, r.shortname, r.sortorder, r.archetype, + rc.contextid FROM {role} r JOIN {role_capabilities} rc ON rc.roleid = r.id WHERE rc.capability = :capability @@ -139,11 +145,9 @@ class riskbackup_result extends \core\check\result { } // Make a list of overrides to roles. - $rolelinks2 = array(); if ($this->overriddenroles) { $links = array(); foreach ($this->overriddenroles as $role) { - $role->name = $role->localname; $context = context::instance_by_id($role->contextid); $role->name = role_get_name($role, $context, ROLENAME_BOTH); $role->contextname = $context->get_context_name();