AtlassianPS / JiraPS

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

Error when get username by command Get-JiraUser #411

Open Growlert opened 4 years ago

Growlert commented 4 years ago

Description

When I try to get user information from command like: Get-JiraUser -UserName 'some_user' It thows me the error:

Invoke-JiraMethod : The query parameter 'username' is not supported in GDPR strict mode.
C:\Program Files\WindowsPowerShell\Modules\JiraPS\2.14.0\JiraPS.psm1:2793 знак:34
+                     if ($users = Invoke-JiraMethod @parameter) {
+                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Invoke-JiraMethod], RuntimeException
    + FullyQualifiedErrorId : InvalidResponse.Status400,Invoke-JiraMethod

Get-JiraUser : No results when searching for user some_user
строка:1 знак:1
+ Get-JiraUser -UserName 'some_user'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-JiraUser

Steps To Reproduce

Must use powershell module "JiraPS"

Expected behavior

Should output the username information

Screenshots

Your Environment

Get-Module JiraPS -ListAvailable | Select Name, Version
$PSVersionTable

Possible Solution

friendlyneighbourhoodcoder commented 4 years ago

It looks like Jira have been in the process of depreciating the "username" string on their API to order to comply with European General Data Protection Regulation (GDPR)

It's been replaced by the "query" string.

We resolved this by altering the JiraPS module's Get-JiraUser function from:

$searchResourceUri = "$server/rest/api/2/user/search?username={0}" $exactResourceUri = "$server/rest/api/2/user?username={0}"

to:

$searchResourceUri = "$server/rest/api/2/user/search?query={0}" $exactResourceUri = "$server/rest/api/2/user?query={0}"

lipkau commented 4 years ago

Hello @friendlyneighbourhoodcoder is the query query parameter valid for cloud server and on premise servers?

friendlyneighbourhoodcoder commented 4 years ago

Hi @lipkau

Our organisation uses cloud server, so I can only confirm for cloud.

ebekker commented 4 years ago

The problem with user references when calling against Jira Cloud is that Jira Cloud forces GDPR mode and all API calls that reference a user account have to use an ID, not a name any more.

I propose adding an optional flag to Set-JiraConfigServer such as -GdprMode or something to that effect which will alter the behavior of all other methods so that anywhere that a user is referenced, instead of referring by name, the reference will be changed to ID.

And then of course all those areas across the module need to be updated to support this, which can be eased by centralizing that logic into a method such as Resolve-JiraUserReference. If this approach is palatable to everyone, then I will try to work on and submit a PR to that effect.

friendlyneighbourhoodcoder commented 4 years ago

@ebekker - Sure thing, sounds like a plan!

patrick-ryan1 commented 4 years ago

Is there a way to get the user list with ids?

nguyenanhducs commented 3 years ago

Is there a way to get the user list with ids?

According to the command based help, you can get all Jira users by

Get-JiraUser -UserName ""

The empty string "" matches all users.

or use the REST API

<server>/rest/api/2/user/search?username=
jeffpatton1971 commented 1 year ago

So, this is still an issue with the specific cmdlet Get-JiraUser 2.14.6

Get-Module JiraPS

ModuleType Version    PreRelease Name
---------- -------    ---------- ----
Script     2.14.6                JiraPS

This method does not work

Get-JiraUser -UserName ""
Invoke-JiraMethod: The username or property query parameter must be provided
Invoke-JiraMethod:
Get-JiraUser: No results when searching for user

Specifying my email address also does not work

Get-JiraUser -Username 'jeffrey.patton2@rackspace.com'
Invoke-JiraMethod: The query parameter 'username' is not supported in GDPR strict mode.
Invoke-JiraMethod:
Get-JiraUser: No results when searching for user jeffrey.patton2@###

You will need to update the function Get-JiraUser to accept AccountId, if that's what it's supposed to be, per some 2yr discussion in this STILL OPEN TICKET. Or deprectate this cmdlet and update the documentation to reflect the correct way to grab one or more users from Jira.