AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
322 stars 131 forks source link

Get-JiraUser returns blank EmailAddress for all users #394

Closed JohnLBevan closed 4 years ago

JohnLBevan commented 4 years ago

Description

Running Get-JiraUser -Username '' (or variants) returns users successfully, but their EmailAddress property is blank.

This seems to be down to a change in the API; but reporting here as the field is returned, so people would expect it to be populated. I'm logging this more for the benefit of others encountering this issue than for a bugfix in this module, as I don't think it's fixable within this module, but is rather a restriction of the API.

The reason we see the EmailAddress property is because it's assigned here: https://github.com/AtlassianPS/JiraPS/blob/0c081ad647f1d2102699229990d54c914b3579df/JiraPS/Private/ConvertTo-JiraUser.ps1#L18 The reason this is blank is because the API no longer populated an EmailAddress field (e.g. going to https://mytenant.atlassian.net/rest/api/latest/user?maxResults=1&username=ExactExampleUsername does not include a mail address).

Atlassian have documented removing this field here: https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-user-privacy-api-migration-guide/

Steps To Reproduce

  1. Run Get-JiraUser -Username '' | Select -First 1 *
  2. Unless the first user found is your account, the email address property will be blank.

Expected behavior

The user's email address should be populated.

Your Environment

>Get-Module JiraPS -ListAvailable | Select Name, Version

Name   Version
----   -------
JiraPS 2.12.5 

> $PSVersionTable

Name                           Value                                                                                                                                                                        
----                           -----                                                                                                                                                                        
PSVersion                      5.1.14409.1018                                                                                                                                                               
PSEdition                      Desktop                                                                                                                                                                      
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                      
BuildVersion                   10.0.14409.1018                                                                                                                                                              
CLRVersion                     4.0.30319.42000                                                                                                                                                              
WSManStackVersion              3.0                                                                                                                                                                          
PSRemotingProtocolVersion      2.3                                                                                                                                                                          
SerializationVersion           1.1.0.1                                                                                                                                                                      

Possible Solution

Navigate to: https://myTenant.atlassian.net/secure/admin/ViewApplicationProperties.jspa If you see: User email visibility set to Show to logged in users only, that is the cause.

In theory, to resolve, click Edit Settings (top right) then change User Email Visibility to Public. Sadly initial tests have shown that info still doesn't come through the API / it seems this issue was discovered and reported ~2 years ago: https://community.atlassian.com/t5/Jira-questions/Get-emailAddress-of-user-with-REST-API/qaq-p/718538

Note: I'm not sure whether JiraPS could show a warning explaining why this information is not shown when it's not retrieved?

Alternatively happy for this to be closed as it's not a JiraPS bug; just wanted to ensure the ticket's here to help others hitting this issue in future.

lipkau commented 4 years ago

when writing the documentation for the fix of #404 , I noticed that the email address might not be returned by the server depending on the privacy settings. You are absolutely right with your findings. Thank you for reporting this. but unfortunately, I can't think of a way how the module could work around this.