View email addresses in User Details

View email addresses in User Details

by Pete Edwards -
Number of replies: 3

I'm on Moodle 3.1 and am trying to work out why email addresses are not shown in the User Details section of the profile (seen on user/profile.php). This doc appears to suggest it should be shown: https://docs.moodle.org/31/en/File:course_profile.png

The teachers have their preferences set to show email addresses whereas students do not.  I have added email as a visible identifier:

User policies - showuseridentity = Email address and Department

If  a student looks at the list of participants and changes to the User details view, they will see email addresses (user/index.php). However, if they go straight to the teacher's profile (user/profile.php), the address is not shown.

The other relevant setting I found was to add the following policy for students:

moodle/user:viewdetails = allow

Please can anyone advise me as to why the email is still invisible?

Thanks

Average of ratings: -
In reply to Pete Edwards

Re: View email addresses in User Details

by Richard van Iwaarden -

I'm having the same problem. Email addresses seem no longer visible.

How do we set them visible on the user profile page?

In reply to Pete Edwards

Re: View email addresses in User Details

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If it helps.... I've spend *hours* glaring at the code for this stuff trying to determine why the email address is shown for some combinations of users and not others. I don't understand what it's trying to do and I don't know why it does what it does. 

There's probably a very subtle bug but I can't even reproduce it reliably never mind find it. 

On the other hand, there are settings for what profile settings are shown to whom. Check Site administration > User > Policies (especially, 'Show user identity). I think there's a role capability for seeing another user's details too. So, if you changed any of that stuff you could just have broken it. 

In reply to Howard Miller

Re: View email addresses in User Details

by Christian Thompson -

I'm also trying to figure this one out. Here is what I have found:

Long Story Short:

It appears as though email display is now controlled by the site:viewuseridentity permission. However, giving this permission to students results in the students being able to see EVERYONE'S email addresses, even those who have chosen hide my email address.

Rather than being part of the normal user details that can and cannot be displayed, the email address is in a separate category of siteidentity which is controlled by the permission above.  (Note: you can change which items are considered site identity as mentioned below) however, email is used as the default.)  Regardless, removing email as the site identity does not make it suddenly appear.  

Perhaps we are expected to use the built-in messaging system exclusively?

Anyhoo, if anyone figures a workaround, please do post it.  Hopefully I am just missing something simple. Fingers crossed!

Thanks,

Christian


DETAILS

The relevant code is here:

Moodle: https://github.com/moodle/moodle/blob/6a69cda97dc8b10cffd805d62bfc6d56098c92d0/lib/myprofilelib.php

Specifically (starting at line 124):

    // Contact details.

    if (has_capability('moodle/user:viewhiddendetails', $courseorusercontext)) {

        $hiddenfields = array();

    } else {

        $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));

    }

    if (has_capability('moodle/site:viewuseridentity', $courseorusercontext)) {

        $identityfields = array_flip(explode(',', $CFG->showuseridentity));

    } else {

        $identityfields = array();

    }

The site:viewuseridentity setting refers to the selected user identity found here: SITE_URL/admin/settings.php?section=userpolicies

Based on what I see here, the only way to allow email addresses to be viewed is to grant users the "site:viewuseridentity" setting.  However, it appears that this would ignore the "Hide my email address" setting. 


There is also this code in the same library (from line 154):

    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)))) {

        $node = new core_user\output\myprofile\node('contact', 'email', get_string('email'), null, null,

            obfuscate_mailto($user->email, ''));

        $tree->add_node($node);

    }

As you can see, the code looks for the course:useremail capability - I tried changing this permission on our site for students, but there was no effect. I also found this tracker issue where this capability is supposed to be deprecated:  https://tracker.moodle.org/browse/MDL-37479 . One poster even asked how students would be able to view each other's email addresses (and presumably that of the instructor if this was removed) .

There is a more recent tracker issue posted on this: https://tracker.moodle.org/browse/MDL-58061