MDL-67245 group: observe viewfullnames capability.
authorPaul Holden <paulh@moodle.com>
Tue, 7 Jan 2020 16:18:56 +0000 (16:18 +0000)
committerPaul Holden <paulh@moodle.com>
Fri, 17 Jan 2020 12:42:17 +0000 (12:42 +0000)
group/autogroup.php
group/classes/output/user_groups_editable.php
group/externallib.php
group/index.php
group/overview.php

index dd7d582..cc2aeeb 100644 (file)
@@ -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) {
index 9595a03..a4a61c5 100644 (file)
@@ -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);
index bebede4..341e727 100644 (file)
@@ -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);
         }
index f589f27..e2aa22b 100644 (file)
@@ -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) {
index e4202cc..5c23992 100644 (file)
@@ -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) {