diff --git a/admin/settings/users.php b/admin/settings/users.php index 7fc752f38e3..8d93b5a4440 100644 --- a/admin/settings/users.php +++ b/admin/settings/users.php @@ -150,6 +150,7 @@ if ($hassiteconfig $temp->add(new admin_setting_configmultiselect('hiddenuserfields', new lang_string('hiddenuserfields', 'admin'), new lang_string('confighiddenuserfields', 'admin'), array(), array('description' => new lang_string('description'), + 'email' => new lang_string('email'), 'city' => new lang_string('city'), 'country' => new lang_string('country'), 'timezone' => new lang_string('timezone'), diff --git a/lib/myprofilelib.php b/lib/myprofilelib.php index 5ce910486a6..397d5b3e16c 100644 --- a/lib/myprofilelib.php +++ b/lib/myprofilelib.php @@ -127,7 +127,8 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, } else { $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); } - if (has_capability('moodle/site:viewuseridentity', $courseorusercontext)) { + $canviewuseridentity = has_capability('moodle/site:viewuseridentity', $courseorusercontext); + if ($canviewuseridentity) { $identityfields = array_flip(explode(',', $CFG->showuseridentity)); } else { $identityfields = array(); @@ -151,11 +152,14 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $tree->add_node($node); } - if (isset($identityfields['email']) and ($iscurrentuser - or $user->maildisplay == 1 - or has_capability('moodle/course:useremail', $courseorusercontext) - or has_capability('moodle/site:viewuseridentity', $courseorusercontext) - or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER)))) { + if ($iscurrentuser + or (!isset($hiddenfields['email']) and ( + $user->maildisplay == core_user::MAILDISPLAY_EVERYONE + or ($user->maildisplay == core_user::MAILDISPLAY_COURSE_MEMBERS_ONLY and enrol_sharing_course($user, $USER)) + or has_capability('moodle/course:useremail', $courseorusercontext) // TODO: Deprecate/remove for MDL-37479. + )) + or (isset($identityfields['email']) and $canviewuseridentity) + ) { $node = new core_user\output\myprofile\node('contact', 'email', get_string('email'), null, null, obfuscate_mailto($user->email, '')); $tree->add_node($node); diff --git a/user/lib.php b/user/lib.php index 6d1cf602214..5151d79572b 100644 --- a/user/lib.php +++ b/user/lib.php @@ -463,12 +463,15 @@ function user_get_user_details($user, $course = null, array $userfields = array( } } - if (in_array('email', $userfields) && ($isadmin // The admin is allowed the users email. - or $currentuser // Of course the current user is as well. - or $canviewuseremail // This is a capability in course context, it will be false in usercontext. - or in_array('email', $showuseridentityfields) - or $user->maildisplay == 1 - or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER)))) { + if (in_array('email', $userfields) && ( + $currentuser + or (!isset($hiddenfields['email']) and ( + $user->maildisplay == core_user::MAILDISPLAY_EVERYONE + or ($user->maildisplay == core_user::MAILDISPLAY_COURSE_MEMBERS_ONLY and enrol_sharing_course($user, $USER)) + or $canviewuseremail // TODO: Deprecate/remove for MDL-37479. + )) + or in_array('email', $showuseridentityfields) + )) { $userdetails['email'] = $user->email; }