diff --git a/lang/en/moodle.php b/lang/en/moodle.php index d58d87d4ad9..d5b8c6a9484 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -648,6 +648,9 @@ $string['emaildisableclick'] = 'Click here to disable all email from being sent $string['emaildisplay'] = 'Email display'; $string['emaildisplay_help'] = 'Privileged users (such as teachers and managers) will always be able to see your email address.'; $string['emaildisplaycourse'] = 'Allow only other course members to see my email address'; +$string['emaildisplaycoursemembersonly'] = '(Visible to other course participants)'; +$string['emaildisplayeveryone'] = '(Visible to everyone)'; +$string['emaildisplayhide'] = '(Hidden from all non-privileged users)'; $string['emaildisplayno'] = 'Hide my email address from non-privileged users'; $string['emaildisplayyes'] = 'Allow everyone to see my email address'; $string['emailenable'] = 'This email address is enabled'; diff --git a/lib/myprofilelib.php b/lib/myprofilelib.php index 044d5595dcd..d077e381605 100644 --- a/lib/myprofilelib.php +++ b/lib/myprofilelib.php @@ -158,8 +158,18 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, )) or (isset($identityfields['email']) and $canviewuseridentity) ) { - $node = new core_user\output\myprofile\node('contact', 'email', get_string('email'), null, null, - obfuscate_mailto($user->email, '')); + $maildisplay = obfuscate_mailto($user->email, ''); + if ($iscurrentuser) { + if ($user->maildisplay == core_user::MAILDISPLAY_EVERYONE) { + $maildisplay .= ' ' . get_string('emaildisplayeveryone'); + } else if ($user->maildisplay == core_user::MAILDISPLAY_COURSE_MEMBERS_ONLY) { + $maildisplay .= ' ' . get_string('emaildisplaycoursemembersonly'); + } else { + $maildisplay .= ' ' . get_string('emaildisplayhide'); + } + } + $node = new core_user\output\myprofile\node('contact', 'email', get_string('email'), + null, null, $maildisplay); $tree->add_node($node); } diff --git a/user/tests/behat/set_email_display.feature b/user/tests/behat/set_email_display.feature index ef6de88502e..25efabf577c 100644 --- a/user/tests/behat/set_email_display.feature +++ b/user/tests/behat/set_email_display.feature @@ -28,6 +28,7 @@ Feature: Set email display preference Given I log in as "studentp" When I follow "Profile" in the user menu Then I should see "studentP@example.com" + And I should see "(Visible to other course participants)" @javascript Scenario: Student peer on the same course viewing profiles @@ -76,3 +77,20 @@ Feature: Set email display preference And I navigate to course participants When I follow "Student MEMBERS" Then I should see "studentM@example.com" + + @javascript + Scenario: User can see user's email address settings on own profile + Given I log in as "studentp" + And I follow "Profile" in the user menu + Then I should see "studentP@example.com" + And I should see "(Visible to other course participants)" + When I click on "Edit profile" "link" in the "region-main" "region" + And I set the following fields to these values: + | maildisplay | 0 | + And I click on "Update profile" "button" + Then I should see "(Hidden from all non-privileged users)" + When I click on "Edit profile" "link" in the "region-main" "region" + And I set the following fields to these values: + | maildisplay | 1 | + And I click on "Update profile" "button" + Then I should see "(Visible to everyone)"