From e8c7d8cd41ee24f449f6b188adee6c980670cb0f Mon Sep 17 00:00:00 2001 From: Christian Abila Date: Wed, 3 Dec 2025 07:48:05 +0100 Subject: [PATCH] MDL-87075 core: Filter roles to include visibility permissions --- lib/accesslib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index 646fe1dfa04..74208c09e69 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2881,12 +2881,12 @@ function get_roles_used_in_context(context $context, $includeparents = true) { * It is using the CFG->profileroles to limit the list to only interesting roles. * (The permission tab has full details of user role assignments.) * - * @param int $userid + * @param int $userid ID of the user whose course roles are filtered by visibility * @param int $courseid * @return string */ function get_user_roles_in_course($userid, $courseid) { - global $CFG, $DB; + global $CFG, $DB, $USER; if ($courseid == SITEID) { $context = context_system::instance(); } else { @@ -2926,7 +2926,7 @@ function get_user_roles_in_course($userid, $courseid) { $rolestring = ''; if ($roles = $DB->get_records_sql($sql, $params)) { - $viewableroles = get_viewable_roles($context, $userid); + $viewableroles = get_viewable_roles($context, $USER->id); $rolenames = array(); foreach ($roles as $roleid => $unused) { @@ -3384,7 +3384,7 @@ function get_switchable_roles(context $context, $rolenamedisplay = ROLENAME_ALIA * Gets a list of roles that this user can view in a context * * @param context $context a context. - * @param int $userid id of user. + * @param int $userid id of user whose viewable roles we are fetching * @param int $rolenamedisplay the type of role name to display. One of the * ROLENAME_X constants. Default ROLENAME_ALIAS. * @return array an array $roleid => $rolename.