Skip to content

Commit

Permalink
Merge branch 'MDL-60548-master-v4' of https://github.com/Dave-B/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Apr 10, 2018
2 parents bd0391d + d2bba97 commit 2f27dca
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 16 deletions.
3 changes: 2 additions & 1 deletion admin/settings/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$choices['1'] = new lang_string('emaildisplayyes');
$choices['2'] = new lang_string('emaildisplaycourse');
$temp->add(new admin_setting_configselect('defaultpreference_maildisplay', new lang_string('emaildisplay'),
'', 2, $choices));
new lang_string('emaildisplay_help'), 2, $choices));

$choices = array();
$choices['0'] = new lang_string('textformat');
Expand Down Expand Up @@ -150,6 +150,7 @@
$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'),
Expand Down
1 change: 1 addition & 0 deletions admin/tool/uploaduser/user_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ function definition () {
$choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse'));
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
$mform->setDefault('maildisplay', core_user::get_property_default('maildisplay'));
$mform->addHelpButton('maildisplay', 'emaildisplay');

$choices = array(0 => get_string('textformat'), 1 => get_string('htmlformat'));
$mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
Expand Down
1 change: 1 addition & 0 deletions enrol/lti/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ public function edit_instance_form($instance, MoodleQuickForm $mform, $context)
);
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
$mform->setDefault('maildisplay', $emaildisplay);
$mform->addHelpButton('maildisplay', 'emaildisplay');

$city = get_config('enrol_lti', 'city');
$mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
Expand Down
4 changes: 2 additions & 2 deletions enrol/lti/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
1 => get_string('emaildisplayyes'),
2 => get_string('emaildisplaycourse'));
$maildisplay = isset($CFG->defaultpreference_maildisplay) ? $CFG->defaultpreference_maildisplay : 2;
$settings->add(new admin_setting_configselect('enrol_lti/emaildisplay', get_string('emaildisplay'), '',
$maildisplay, $choices));
$settings->add(new admin_setting_configselect('enrol_lti/emaildisplay', get_string('emaildisplay'),
get_string('emaildisplay_help'), $maildisplay, $choices));

$city = '';
if (!empty($CFG->defaultcity)) {
Expand Down
3 changes: 2 additions & 1 deletion lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,10 @@
$string['emaildisable'] = 'This email address is disabled';
$string['emaildisableclick'] = 'Click here to disable all email from being sent to this address';
$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['emaildisplayhidden'] = 'Email hidden';
$string['emaildisplayno'] = 'Hide my email address from everyone';
$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';
$string['emailenableclick'] = 'Click here to re-enable all email being sent to this address';
Expand Down
16 changes: 10 additions & 6 deletions lib/myprofilelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions user/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
$choices['2'] = get_string('emaildisplaycourse');
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
$mform->setDefault('maildisplay', core_user::get_property_default('maildisplay'));
$mform->addHelpButton('maildisplay', 'emaildisplay');

$mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
$mform->setType('city', PARAM_TEXT);
Expand Down
15 changes: 9 additions & 6 deletions user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
78 changes: 78 additions & 0 deletions user/tests/behat/set_email_display.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
@core @core_user
Feature: Set email display preference
In order to control who can see my email address on my profile page
As a student
I need my email to be shown to only the user groups chosen

Background:
Given the following "users" exist:
| username | firstname | lastname | email | maildisplay |
| teacher1 | Teacher | 1 | teacher1@example.com | 2 |
| studentP | Student | PEER | studentP@example.com | 2 |
| studentN | Student | NONE | studentN@example.com | 0 |
| studentE | Student | EVERYONE | studentE@example.com | 1 |
| studentM | Student | MEMBERS | studentM@example.com | 2 |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "course enrolments" exist:
| user | course | role | status | timeend |
| teacher1 | C1 | teacher | 0 | 0 |
| studentP | C1 | student | 0 | 0 |
| studentN | C1 | student | 0 | 0 |
| studentE | C1 | student | 0 | 0 |
| studentM | C1 | student | 0 | 0 |

@javascript
Scenario: Student viewing own profile
Given I log in as "studentP"
When I follow "Profile" in the user menu
Then I should see "[email protected]"

@javascript
Scenario: Student peer on the same course viewing profiles
Given I log in as "studentP"
And I am on "Course 1" course homepage
And I navigate to course participants
When I follow "Student NONE"
Then I should not see "[email protected]"
And I navigate to course participants
When I follow "Student EVERYONE"
Then I should see "[email protected]"
And I navigate to course participants
When I follow "Student MEMBERS"
Then I should see "[email protected]"

@javascript
Scenario: Student viewing teacher email (whose maildisplay = MEMBERS)
Given I log in as "studentP"
And I am on "Course 1" course homepage
And I navigate to course participants
When I follow "Teacher 1"
Then I should see "[email protected]"

@javascript
Scenario: Teacher viewing student email, whilst site:showuseridentity = “email”
Given the following config values are set as admin:
| showuseridentity | email |
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to course participants
When I follow "Student NONE"
Then I should see "[email protected]"
And I navigate to course participants
When I follow "Student MEMBERS"
Then I should see "[email protected]"

@javascript
Scenario: Teacher viewing student email, whilst site:showuseridentity = “”
Given I log in as "teacher1"
And the following config values are set as admin:
| showuseridentity | |
And I am on "Course 1" course homepage
And I navigate to course participants
When I follow "Student NONE"
Then I should not see "[email protected]"
And I navigate to course participants
When I follow "Student MEMBERS"
Then I should see "[email protected]"

0 comments on commit 2f27dca

Please sign in to comment.