MDL-62065 core_access: First deprecation of get roles on exact context

This commit is contained in:
cescobedo
2018-07-29 22:43:06 +02:00
parent 6e8235c7d3
commit df536ab17d
4 changed files with 43 additions and 36 deletions
@@ -147,8 +147,8 @@ class data_registry {
if ($contextcourse = $context->get_course_context(false)) {
// Below course level we look at module or block level roles + course-assigned roles.
$courseroles = get_roles_with_assignment_on_context($contextcourse);
$roles = $courseroles + get_roles_with_assignment_on_context($context);
$courseroles = get_roles_used_in_context($contextcourse, false);
$roles = $courseroles + get_roles_used_in_context($context, false);
} else {
// We list category + system for others (we don't work with user instances so no need to work about them).
$roles = get_roles_used_in_context($context);
+7 -34
View File
@@ -2548,12 +2548,17 @@ function get_profile_roles(context $context) {
* Gets the list of roles assigned to this context and up (parents)
*
* @param context $context
* @param boolean $includeparents, false means without parents.
* @return array
*/
function get_roles_used_in_context(context $context) {
function get_roles_used_in_context(context $context, $includeparents = true) {
global $DB;
list($contextlist, $params) = $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'cl');
if ($includeparents === true) {
list($contextlist, $params) = $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'cl');
} else {
list($contextlist, $params) = $DB->get_in_or_equal($context->id, SQL_PARAMS_NAMED, 'cl');
}
if ($coursecontext = $context->get_course_context(false)) {
$params['coursecontext'] = $coursecontext->id;
@@ -3988,22 +3993,6 @@ function get_user_capability_course($capability, $userid = null, $doanything = t
return empty($courses) ? false : $courses;
}
/**
* This function finds the roles assigned directly to this context only
* i.e. no roles in parent contexts
*
* @param context $context
* @return array
*/
function get_roles_on_exact_context(context $context) {
global $DB;
return $DB->get_records_sql("SELECT r.*
FROM {role_assignments} ra, {role} r
WHERE ra.roleid = r.id AND ra.contextid = ?",
array($context->id));
}
/**
* Switches the current user to another role for the current session and only
* in the given context.
@@ -4091,22 +4080,6 @@ function get_capabilities_from_role_on_context($role, context $context) {
array($context->id, $role->id));
}
/**
* Find out which roles has assignment on this context
*
* @param context $context
* @return array
*
*/
function get_roles_with_assignment_on_context(context $context) {
global $DB;
return $DB->get_records_sql("SELECT r.*
FROM {role_assignments} ra, {role} r
WHERE ra.roleid = r.id AND ra.contextid = ?",
array($context->id));
}
/**
* Find all user assignment of users for this role, on this context
*
+31
View File
@@ -6613,3 +6613,34 @@ function groups_get_all_groups_for_courses($courses) {
return $groups;
}
/**
* This function finds the roles assigned directly to this context only
* i.e. no roles in parent contexts
*
* @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
* @todo final deprecation. To be removed in Moodle 4.0
* @param context $context
* @return array
*/
function get_roles_on_exact_context(context $context) {
debugging('get_roles_on_exact_context() is deprecated, please use get_roles_used_in_context() instead.',
DEBUG_DEVELOPER);
return get_roles_used_in_context($context, false);
}
/**
* Find out which roles has assignment on this context
*
* @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
* @todo final deprecation. To be removed in Moodle 4.0
* @param context $context
* @return array
*/
function get_roles_with_assignment_on_context(context $context) {
debugging('get_roles_with_assignment_on_context() is deprecated, please use get_roles_used_in_context() instead.',
DEBUG_DEVELOPER);
return get_roles_used_in_context($context, false);
}
+3
View File
@@ -22,6 +22,9 @@ information provided here is intended especially for developers.
- I set the field "<field_string>" to multiline
- I follow "<link_string>"" in the open menu
* Removed the lib/password_compat/lib/password.php file.
* Following functions have been deprecated, please use get_roles_used_in_context.
- get_roles_on_exact_context()
- get_roles_with_assignment_on_context()
=== 3.5 ===