diff --git a/CHANGELOG.md b/CHANGELOG.md index b51ccb21..6a53cd0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [NEXT VERSION] - YYYY-MM-DD + +### Added + +- Parameter for retrieving information about a specific user with `Get-JiraUser` (#328, [@michalporeba]) + - this implementations will be changed with the next major update in favor of #306 + ## [2.9] - 2018-12-12 ### Added @@ -21,7 +28,6 @@ - Fixed missing properties on `Get-JiraUser` (#321, [@lipkau]) - Fixed `-DateStarted` on `Add-JiraIssueWorklog` (#324, [@lipkau]) - ## [2.8] - 2018-06-28 More detailed description about the changes can be found on [Our Website](https://atlassianps.org/article/announcement/JiraPS-v2.8.html). @@ -311,6 +317,7 @@ which is in turn inspired by the [Vagrant](https://github.com/mitchellh/vagrant/ [@LiamLeane]: https://github.com/LiamLeane [@lipkau]: https://github.com/lipkau [@lukhase]: https://github.com/lukhase + [@michalporeba]: https://github.com/michalporeba [@padgers]: https://github.com/padgers [@ThePSAdmin]: https://github.com/ThePSAdmin [@tuxgoose]: https://github.com/tuxgoose diff --git a/JiraPS/Public/Get-JiraUser.ps1 b/JiraPS/Public/Get-JiraUser.ps1 index 640517ce..aa18cc30 100644 --- a/JiraPS/Public/Get-JiraUser.ps1 +++ b/JiraPS/Public/Get-JiraUser.ps1 @@ -11,6 +11,10 @@ function Get-JiraUser { [Parameter( Position = 0, Mandatory, ParameterSetName = 'ByInputObject' )] [Object[]] $InputObject, + [Parameter( ParameterSetName = 'ByInputObject' )] + [Parameter( ParameterSetName = 'ByUserName' )] + [Switch]$Exact, + [Switch] $IncludeInactive, @@ -37,6 +41,7 @@ function Get-JiraUser { $selfResourceUri = "$server/rest/api/latest/myself" $searchResourceUri = "$server/rest/api/latest/user/search?username={0}" + $exactResourceUri = "$server/rest/api/latest/user?username={0}" if ($IncludeInactive) { $searchResourceUri += "&includeInactive=true" @@ -80,7 +85,7 @@ function Get-JiraUser { $PsCmdlet.ParameterSetName = "ByUserName" } "ByUserName" { - $resourceURi = $searchResourceUri + $resourceURi = if ($Exact) { $exactResourceUri } else { $searchResourceUri } foreach ($user in $UserName) { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Processing [$user]" diff --git a/JiraPS/Public/Set-JiraIssue.ps1 b/JiraPS/Public/Set-JiraIssue.ps1 index 2dfb465e..01bce57c 100644 --- a/JiraPS/Public/Set-JiraIssue.ps1 +++ b/JiraPS/Public/Set-JiraIssue.ps1 @@ -96,7 +96,7 @@ function Set-JiraIssue { $validAssignee = $true } else { - if ($assigneeObj = Get-JiraUser -UserName $Assignee -Credential $Credential) { + if ($assigneeObj = Get-JiraUser -UserName $Assignee -Credential $Credential -Exact) { Write-Debug "[$($MyInvocation.MyCommand.Name)] User found (name=[$($assigneeObj.Name)],RestUrl=[$($assigneeObj.RestUrl)])" $assigneeString = $assigneeObj.Name $validAssignee = $true diff --git a/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 b/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 index cd09868c..d8a13a43 100644 --- a/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 +++ b/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 @@ -108,6 +108,12 @@ Describe "Get-JiraUser" -Tag 'Unit' { ConvertFrom-Json -InputObject $restResult } + # Get exact user + Mock Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {$Method -eq 'Get' -and $URI -like "$jiraServer/rest/api/*/user?username=$testUsername"} { + ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri' + ConvertFrom-Json -InputObject $restResult + } + # Viewing a specific user. The main difference here is that this includes groups, and the first does not. Mock Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {$Method -eq 'Get' -and $URI -like "$jiraServer/rest/api/*/user?username=$testUsername&expand=groups"} { ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri' @@ -138,6 +144,16 @@ Describe "Get-JiraUser" -Tag 'Unit' { $getResult | Should Not BeNullOrEmpty + Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter {$URI -like "$jiraServer/rest/api/*/user/search?*username=$testUsername*"} + Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter {$URI -like "$jiraServer/rest/api/*/user?username=$testUsername&expand=groups"} + } + + It "Gets information about a provided Jira exact user" { + $getResult = Get-JiraUser -UserName $testUsername -Exact + + $getResult | Should Not BeNullOrEmpty + + Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like "$jiraServer/rest/api/*/user?username=$testUsername"} Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter {$URI -like "$jiraServer/rest/api/*/user?username=$testUsername&expand=groups"} } diff --git a/docs/en-US/commands/Get-JiraUser.md b/docs/en-US/commands/Get-JiraUser.md index 76d9d06c..fa55f7eb 100644 --- a/docs/en-US/commands/Get-JiraUser.md +++ b/docs/en-US/commands/Get-JiraUser.md @@ -24,13 +24,13 @@ Get-JiraUser [-Credential ] [] ### ByUserName ```powershell -Get-JiraUser [-UserName] [-IncludeInactive] [[-MaxResults] ] [[-Skip] ] [-Credential ] [] +Get-JiraUser [-UserName] [-IncludeInactive] [[-MaxResults] ] [[-Skip] ] [-Credential ] [-Exact] [] ``` ### ByInputObject ```powershell -Get-JiraUser [-InputObject] [-IncludeInactive] [-Credential ] [] +Get-JiraUser [-InputObject] [-IncludeInactive] [-Credential ] [-Exact] [] ``` ## DESCRIPTION @@ -45,7 +45,7 @@ This function returns information regarding a specified user from Jira. Get-JiraUser -UserName user1 ``` -Returns information about the user user1 +Returns information about all users with username like user1 ### EXAMPLE 2 @@ -63,6 +63,14 @@ Get-JiraUser -Credential $cred This example returns the JIRA user that is executing the command. +### EXAMPLE 4 + +```powershell +Get-JiraUser -UserName user1 -Exact +``` + +Returns information about user user1 + ## PARAMETERS ### -UserName @@ -97,6 +105,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Exact + +Limits the search to users where the username is exactly the term searched for. + +```yaml +Type: Switch +Parameter Sets: ByUserName, ByInputObject +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -IncludeInactive Include inactive users in the search