Merge branch 'MDL-63387-2' of https://github.com/paulholden/moodle into master

This commit is contained in:
Sara Arjona 2020-09-01 16:58:00 +02:00
commit c9bd1a6652
12 changed files with 47 additions and 23 deletions

View File

@ -49,7 +49,7 @@ class award_criteria_manual extends award_criteria {
$rec = $DB->get_record('role', array('id' => $rid));
if ($rec) {
return role_get_name($rec, $PAGE->context, ROLENAME_ALIAS);
return role_get_name($rec, $PAGE->context, ROLENAME_BOTH);
} else {
return null;
}

View File

@ -88,7 +88,7 @@ if ($switchrole > 0 && has_capability('moodle/role:switchroles', $context)) {
$roles[0] = get_string('switchrolereturn');
$assumedrole = $USER->access['rsw'][$context->path];
}
$availableroles = get_switchable_roles($context);
$availableroles = get_switchable_roles($context, ROLENAME_BOTH);
if (is_array($availableroles)) {
foreach ($availableroles as $key => $role) {
if ($assumedrole == (int)$key) {

View File

@ -32,9 +32,15 @@ Feature: Rename roles within a course
And I navigate to course participants
And I set the field "type" in the "Filter 1" "fieldset" to "Roles"
And I click on ".form-autocomplete-downarrow" "css_element" in the "Filter 1" "fieldset"
And I should see "Tutor" in the ".form-autocomplete-suggestions" "css_element"
And I should see "Learner" in the ".form-autocomplete-suggestions" "css_element"
And I should not see "Student" in the ".form-autocomplete-suggestions" "css_element"
And I should see "Tutor (Non-editing teacher)" in the ".form-autocomplete-suggestions" "css_element"
And I should see "Learner (Student)" in the ".form-autocomplete-suggestions" "css_element"
And I click on "Student 1's role assignments" "link"
And I click on ".form-autocomplete-downarrow" "css_element" in the "Student 1" "table_row"
And "Tutor (Non-editing teacher)" "autocomplete_suggestions" should exist
And I click on "Cancel" "link"
And I press "Enrol users"
And the "Assign role" select box should contain "Learner (Student)"
And I click on "Cancel" "button" in the "Enrol users" "dialogue"
And I am on "Course 1" course homepage
And I navigate to "Edit settings" in current page administration
And I set the following fields to these values:

View File

@ -26,9 +26,17 @@ Feature: Rename roles in a course
| Your word for 'Teacher' | Lecturer |
| Your word for 'Student' | Learner |
And I press "Save and display"
And I navigate to "Users > Enrolled users" in current page administration
Then I should see "Lecturer" in the "Teacher 1" "table_row"
And I navigate to course participants
Then I should see "Lecturer (Teacher)" in the "Teacher 1" "table_row"
And I should see "Learner (Student)" in the "Student 1" "table_row"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I navigate to course participants
And I should see "Lecturer" in the "Teacher 1" "table_row"
And I should see "Learner" in the "Student 1" "table_row"
And I should not see "Lecturer (Teacher)" in the "Teacher 1" "table_row"
And I should not see "Learner (Student)" in the "Student 1" "table_row"
Scenario: Ability to rename roles can be prevented
Given I log in as "admin"

View File

@ -68,7 +68,7 @@ class enrol_cohort_plugin extends enrol_plugin {
}
$cohortname = format_string($cohort->name, true, array('context'=>context::instance_by_id($cohort->contextid)));
if ($role = $DB->get_record('role', array('id'=>$instance->roleid))) {
$role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING));
$role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING), ROLENAME_BOTH);
return get_string('pluginname', 'enrol_'.$enrol) . ' (' . $cohortname . ' - ' . $role .')';
} else {
return get_string('pluginname', 'enrol_'.$enrol) . ' (' . $cohortname . ')';
@ -364,13 +364,14 @@ class enrol_cohort_plugin extends enrol_plugin {
protected function get_role_options($instance, $coursecontext) {
global $DB;
$roles = get_assignable_roles($coursecontext);
$roles = get_assignable_roles($coursecontext, ROLENAME_BOTH);
$roles[0] = get_string('none');
$roles = array_reverse($roles, true); // Descending default sortorder.
// If the instance is already configured, but the configured role is no longer assignable in the course then add it back.
if ($instance->id and !isset($roles[$instance->roleid])) {
if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
$roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true);
$roles[$instance->roleid] = role_get_name($role, $coursecontext);
$roles[$instance->roleid] = role_get_name($role, $coursecontext, ROLENAME_BOTH);
} else {
$roles[$instance->roleid] = get_string('error');
}

View File

@ -116,7 +116,7 @@ class enrol_manual_enrol_users_form extends moodleform {
}
}
$roles = get_assignable_roles($context);
$roles = get_assignable_roles($context, ROLENAME_BOTH);
$mform->addElement('select', 'roletoassign', get_string('assignrole', 'enrol_manual'), $roles);
$mform->setDefault('roletoassign', $instance->roleid);

View File

@ -60,7 +60,7 @@ $preview = '';
$error = '';
/// Get applicable roles - used in menus etc later on
$rolenames = role_fix_names(get_profile_roles($context), $context, ROLENAME_ALIAS, true);
$rolenames = role_fix_names(get_profile_roles($context), $context, ROLENAME_BOTH, true);
/// Create the form
$editform = new autogroup_form(null, array('roles' => $rolenames));

View File

@ -3163,9 +3163,11 @@ function get_assignable_roles(context $context, $rolenamedisplay = ROLENAME_ALIA
* test the moodle/role:switchroles to see if the user is allowed to switch in the first place.
*
* @param context $context a context.
* @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.
*/
function get_switchable_roles(context $context) {
function get_switchable_roles(context $context, $rolenamedisplay = ROLENAME_ALIAS) {
global $USER, $DB;
// You can't switch roles without this capability.
@ -3208,7 +3210,7 @@ function get_switchable_roles(context $context) {
ORDER BY r.sortorder";
$roles = $DB->get_records_sql($query, $params);
return role_fix_names($roles, $context, ROLENAME_ALIAS, true);
return role_fix_names($roles, $context, $rolenamedisplay, true);
}
/**
@ -3216,9 +3218,11 @@ function get_switchable_roles(context $context) {
*
* @param context $context a context.
* @param int $userid id of user.
* @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.
*/
function get_viewable_roles(context $context, $userid = null) {
function get_viewable_roles(context $context, $userid = null, $rolenamedisplay = ROLENAME_ALIAS) {
global $USER, $DB;
if ($userid == null) {
@ -3260,7 +3264,7 @@ function get_viewable_roles(context $context, $userid = null) {
ORDER BY r.sortorder";
$roles = $DB->get_records_sql($query, $params);
return role_fix_names($roles, $context, ROLENAME_ALIAS, true);
return role_fix_names($roles, $context, $rolenamedisplay, true);
}
/**

View File

@ -31,6 +31,8 @@ information provided here is intended especially for developers.
* The form element 'htmleditor', which was deprecated in 3.6, has been removed.
* The `core_output_load_fontawesome_icon_map` web service has been deprecated and replaced by
`core_output_load_fontawesome_icon_system_map` which takes the name of the theme to generate the icon system map for.
* A new parameter `$rolenamedisplay` has been added to `get_viewable_roles()` and `get_switchable_roles` to define how role names
should be returned.
* The class coursecat_sortable_records has been removed.
* Admin setting admin_setting_configselect now supports lazy-loading the options list by supplying
a callback function instead of an array of options.

View File

@ -129,10 +129,10 @@ class participants_filter implements renderable, templatable {
protected function get_roles_filter(): ?stdClass {
$roles = [];
$roles += [-1 => get_string('noroles', 'role')];
$roles += get_viewable_roles($this->context);
$roles += get_viewable_roles($this->context, null, ROLENAME_BOTH);
if (has_capability('moodle/role:assign', $this->context)) {
$roles += get_assignable_roles($this->context, ROLENAME_ALIAS);
$roles += get_assignable_roles($this->context, ROLENAME_BOTH);
}
return $this->get_filter_object(

View File

@ -173,8 +173,8 @@ class user_roles_editable extends \core\output\inplace_editable {
}
// Check that all the groups belong to the course.
$allroles = role_fix_names(get_all_roles($context), $context);
$assignableroles = get_assignable_roles($context, ROLENAME_ALIAS, false);
$allroles = role_fix_names(get_all_roles($context), $context, ROLENAME_BOTH);
$assignableroles = get_assignable_roles($context, ROLENAME_BOTH, false);
$viewableroles = get_viewable_roles($context);
$userrolesbyid = get_user_roles($context, $userid, true, 'c.contextlevel DESC, r.sortorder ASC');
$profileroles = get_profile_roles($context);

View File

@ -202,8 +202,11 @@ class participants extends \table_sql implements dynamic_table {
if ($canseegroups) {
$this->groups = groups_get_all_groups($this->courseid, 0, 0, 'g.*', true);
}
$this->allroles = role_fix_names(get_all_roles($this->context), $this->context);
$this->assignableroles = get_assignable_roles($this->context, ROLENAME_ALIAS, false);
// If user has capability to review enrol, show them both role names.
$allrolesnamedisplay = ($canreviewenrol ? ROLENAME_BOTH : ROLENAME_ALIAS);
$this->allroles = role_fix_names(get_all_roles($this->context), $this->context, $allrolesnamedisplay);
$this->assignableroles = get_assignable_roles($this->context, ROLENAME_BOTH, false);
$this->profileroles = get_profile_roles($this->context);
$this->viewableroles = get_viewable_roles($this->context);