From 6e8ed1a8fbbbf669826ee28932748f0497780fff Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 7 Jan 2020 16:18:56 +0000 Subject: [PATCH] MDL-67245 group: observe viewfullnames capability. --- group/autogroup.php | 4 ++-- group/classes/output/user_groups_editable.php | 6 ++++-- group/externallib.php | 3 ++- group/index.php | 8 ++++++-- group/overview.php | 3 ++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/group/autogroup.php b/group/autogroup.php index dd7d582c1b0..cc2aeebdf3b 100644 --- a/group/autogroup.php +++ b/group/autogroup.php @@ -172,7 +172,7 @@ if ($editform->is_cancelled()) { $table->width = '90%'; } $table->data = array(); - + $viewfullnames = has_capability('moodle/site:viewfullnames', $context); foreach ($groups as $group) { $line = array(); if (groups_get_group_by_name($courseid, $group['name'])) { @@ -184,7 +184,7 @@ if ($editform->is_cancelled()) { if ($data->allocateby != 'no') { $unames = array(); foreach ($group['members'] as $user) { - $fullname = fullname($user, true); + $fullname = fullname($user, $viewfullnames); if ($extrafields) { $extrafieldsdisplay = []; foreach ($extrafields as $field) { diff --git a/group/classes/output/user_groups_editable.php b/group/classes/output/user_groups_editable.php index 9595a033568..a4a61c50111 100644 --- a/group/classes/output/user_groups_editable.php +++ b/group/classes/output/user_groups_editable.php @@ -77,8 +77,10 @@ class user_groups_editable extends \core\output\inplace_editable { foreach ($coursegroups as $group) { $options[$group->id] = format_string($group->name, true, ['context' => $this->context]); } - $this->edithint = get_string('editusersgroupsa', 'group', fullname($user)); - $this->editlabel = get_string('editusersgroupsa', 'group', fullname($user)); + + $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->context)); + $this->edithint = get_string('editusersgroupsa', 'group', $fullname); + $this->editlabel = get_string('editusersgroupsa', 'group', $fullname); $attributes = ['multiple' => true]; $this->set_type_autocomplete($options, $attributes); diff --git a/group/externallib.php b/group/externallib.php index bebede4fd4b..341e72750a8 100644 --- a/group/externallib.php +++ b/group/externallib.php @@ -556,7 +556,8 @@ class core_group_external extends external_api { require_capability('moodle/course:managegroups', $context); if (!groups_remove_member_allowed($group, $user)) { - throw new moodle_exception('errorremovenotpermitted', 'group', '', fullname($user)); + $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); + throw new moodle_exception('errorremovenotpermitted', 'group', '', $fullname); } groups_remove_member($group, $user); } diff --git a/group/index.php b/group/index.php index f589f279b05..e2aa22b35e7 100644 --- a/group/index.php +++ b/group/index.php @@ -85,6 +85,8 @@ switch ($action) { if ($groupmemberroles = groups_get_members_by_role($groupids[0], $courseid, 'u.id, ' . user_picture::fields('u', $extrafields))) { + $viewfullnames = has_capability('moodle/site:viewfullnames', $context); + foreach($groupmemberroles as $roleid=>$roledata) { $shortroledata = new stdClass(); $shortroledata->name = $roledata->name; @@ -92,7 +94,7 @@ switch ($action) { foreach($roledata->users as $member) { $shortmember = new stdClass(); $shortmember->id = $member->id; - $shortmember->name = fullname($member, true); + $shortmember->name = fullname($member, $viewfullnames); if ($extrafields) { $extrafieldsdisplay = []; foreach ($extrafields as $field) { @@ -204,12 +206,14 @@ if ($singlegroup) { if ($groupmemberroles = groups_get_members_by_role(reset($groupids), $courseid, 'u.id, ' . user_picture::fields('u', $extrafields))) { + $viewfullnames = has_capability('moodle/site:viewfullnames', $context); + foreach ($groupmemberroles as $roleid => $roledata) { $users = array(); foreach ($roledata->users as $member) { $shortmember = new stdClass(); $shortmember->value = $member->id; - $shortmember->text = fullname($member, true); + $shortmember->text = fullname($member, $viewfullnames); if ($extrafields) { $extrafieldsdisplay = []; foreach ($extrafields as $field) { diff --git a/group/overview.php b/group/overview.php index e4202cc8236..5c23992cc19 100644 --- a/group/overview.php +++ b/group/overview.php @@ -251,9 +251,10 @@ foreach ($members as $gpgid=>$groupdata) { $line[] = html_writer::tag('span', $name, array('class' => 'group_hoverdescription', 'data-groupid' => $gpid)); $hoverevents[$gpid] = get_string('descriptiona', null, $jsdescription); } + $viewfullnames = has_capability('moodle/site:viewfullnames', $context); $fullnames = array(); foreach ($users as $user) { - $displayname = fullname($user, true); + $displayname = fullname($user, $viewfullnames); if ($extrafields) { $extrafieldsdisplay = []; foreach ($extrafields as $field) {