From df3980595220386644d8b1d504dddc0b2d77ca70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Wed, 9 Jan 2019 08:30:54 +0000 Subject: [PATCH 1/9] fixes 320 - assignment when similar users exist --- JiraPS/Public/Get-JiraUser.ps1 | 7 +++++-- JiraPS/Public/Set-JiraIssue.ps1 | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/JiraPS/Public/Get-JiraUser.ps1 b/JiraPS/Public/Get-JiraUser.ps1 index 640517ce..66ed850d 100644 --- a/JiraPS/Public/Get-JiraUser.ps1 +++ b/JiraPS/Public/Get-JiraUser.ps1 @@ -27,7 +27,9 @@ function Get-JiraUser { [Parameter()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] - $Credential = [System.Management.Automation.PSCredential]::Empty + $Credential = [System.Management.Automation.PSCredential]::Empty, + + [Switch]$Exact ) begin { @@ -37,6 +39,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 +83,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 From 6e38104bf2f1ac8e257e053fd74b4ed7b8c9a0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Wed, 9 Jan 2019 09:04:55 +0000 Subject: [PATCH 2/9] -Exact for Get-JiraUser --- JiraPS/Public/Get-JiraUser.ps1 | 1 + Tests/Functions/Get-JiraUser.Unit.Tests.ps1 | 16 ++++++++++++++++ docs/en-US/commands/Get-JiraUser.md | 12 ++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/JiraPS/Public/Get-JiraUser.ps1 b/JiraPS/Public/Get-JiraUser.ps1 index 66ed850d..5a8be9d3 100644 --- a/JiraPS/Public/Get-JiraUser.ps1 +++ b/JiraPS/Public/Get-JiraUser.ps1 @@ -29,6 +29,7 @@ function Get-JiraUser { [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty, + [Parameter()] [Switch]$Exact ) diff --git a/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 b/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 index cd09868c..25df25d6 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 + + $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..9167e5a5 100644 --- a/docs/en-US/commands/Get-JiraUser.md +++ b/docs/en-US/commands/Get-JiraUser.md @@ -24,7 +24,7 @@ Get-JiraUser [-Credential ] [] ### ByUserName ```powershell -Get-JiraUser [-UserName] [-IncludeInactive] [[-MaxResults] ] [[-Skip] ] [-Credential ] [] +Get-JiraUser [-UserName] [-IncludeInactive] [[-MaxResults] ] [[-Skip] ] [-Credential ] [-Exact] [] ``` ### ByInputObject @@ -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 From fd6f3a1e0b964b8b2df5c7262205517d5c54f272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Wed, 9 Jan 2019 10:28:51 +0000 Subject: [PATCH 3/9] missing } --- Tests/Functions/Get-JiraUser.Unit.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 b/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 index 25df25d6..e8b975df 100644 --- a/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 +++ b/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 @@ -144,7 +144,7 @@ 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/search?*username=$testUsername*"} Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter {$URI -like "$jiraServer/rest/api/*/user?username=$testUsername&expand=groups"} } From eb8c09a6410c8cc30b32478e5dd94f0088c3bcd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Thu, 10 Jan 2019 07:40:08 +0000 Subject: [PATCH 4/9] adding documentation to Get-JiraUser -Exact --- docs/en-US/commands/Get-JiraUser.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en-US/commands/Get-JiraUser.md b/docs/en-US/commands/Get-JiraUser.md index 9167e5a5..179f81f1 100644 --- a/docs/en-US/commands/Get-JiraUser.md +++ b/docs/en-US/commands/Get-JiraUser.md @@ -30,7 +30,7 @@ Get-JiraUser [-UserName] [-IncludeInactive] [[-MaxResults] ] ### ByInputObject ```powershell -Get-JiraUser [-InputObject] [-IncludeInactive] [-Credential ] [] +Get-JiraUser [-InputObject] [-IncludeInactive] [-Credential ] [-Exact] [] ``` ## DESCRIPTION From adf6e40b7cee913aa015bba3ade609957dae5fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Thu, 10 Jan 2019 07:40:59 +0000 Subject: [PATCH 5/9] fixing Get-JiraUser -Exact unit test --- Tests/Functions/Get-JiraUser.Unit.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 b/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 index e8b975df..d8a13a43 100644 --- a/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 +++ b/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 @@ -149,7 +149,7 @@ Describe "Get-JiraUser" -Tag 'Unit' { } It "Gets information about a provided Jira exact user" { - $getResult = Get-JiraUser -UserName $testUsername + $getResult = Get-JiraUser -UserName $testUsername -Exact $getResult | Should Not BeNullOrEmpty From acff336ae3bcd16d70f16579066c8f84a723d215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Thu, 10 Jan 2019 07:42:20 +0000 Subject: [PATCH 6/9] Exact in Get-JiraUser is not applicable for -Self set --- JiraPS/Public/Get-JiraUser.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/JiraPS/Public/Get-JiraUser.ps1 b/JiraPS/Public/Get-JiraUser.ps1 index 5a8be9d3..8c6b8a0b 100644 --- a/JiraPS/Public/Get-JiraUser.ps1 +++ b/JiraPS/Public/Get-JiraUser.ps1 @@ -29,7 +29,8 @@ function Get-JiraUser { [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty, - [Parameter()] + [Parameter( ParameterSetName = 'ByInputObject' )] + [Parameter( ParameterSetName = 'ByUserName' )] [Switch]$Exact ) From 74a3f6156a2e13ef74470220180d4ab62fbf33f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Thu, 10 Jan 2019 08:01:15 +0000 Subject: [PATCH 7/9] trying to figure out the documentation requirements --- docs/en-US/commands/Get-JiraUser.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/en-US/commands/Get-JiraUser.md b/docs/en-US/commands/Get-JiraUser.md index 179f81f1..b07c710c 100644 --- a/docs/en-US/commands/Get-JiraUser.md +++ b/docs/en-US/commands/Get-JiraUser.md @@ -174,6 +174,20 @@ Accept pipeline input: False Accept wildcard characters: False ``` +```yaml +Type: SwitchParameter +Parameter Sets: ByUserName,ByInputObject +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + + + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. From 95d547497d09be34ede0a4ca776111fd99c007be Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Thu, 10 Jan 2019 17:08:48 +0100 Subject: [PATCH 8/9] Fixed documentation of new parameter --- JiraPS/Public/Get-JiraUser.ps1 | 10 ++++----- docs/en-US/commands/Get-JiraUser.md | 32 +++++++++++++++-------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/JiraPS/Public/Get-JiraUser.ps1 b/JiraPS/Public/Get-JiraUser.ps1 index 8c6b8a0b..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, @@ -27,11 +31,7 @@ function Get-JiraUser { [Parameter()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] - $Credential = [System.Management.Automation.PSCredential]::Empty, - - [Parameter( ParameterSetName = 'ByInputObject' )] - [Parameter( ParameterSetName = 'ByUserName' )] - [Switch]$Exact + $Credential = [System.Management.Automation.PSCredential]::Empty ) begin { diff --git a/docs/en-US/commands/Get-JiraUser.md b/docs/en-US/commands/Get-JiraUser.md index b07c710c..fa55f7eb 100644 --- a/docs/en-US/commands/Get-JiraUser.md +++ b/docs/en-US/commands/Get-JiraUser.md @@ -66,7 +66,7 @@ This example returns the JIRA user that is executing the command. ### EXAMPLE 4 ```powershell -Get-JiraUser -UserName user1 -Exact +Get-JiraUser -UserName user1 -Exact ``` Returns information about user user1 @@ -105,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 @@ -174,20 +190,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -```yaml -Type: SwitchParameter -Parameter Sets: ByUserName,ByInputObject -Aliases: - -Required: False -Position: Named -Default value: False -Accept pipeline input: False -Accept wildcard characters: False -``` - - - ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. From d21c011da56423e358d1f4bc4bbdfbbdfa1548d5 Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Thu, 10 Jan 2019 17:24:02 +0100 Subject: [PATCH 9/9] Added description of implementation to CHANGELOG --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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