Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove-JiraGroupMember fails #299

Closed
stevenyoungs opened this issue Jul 6, 2018 · 0 comments · Fixed by #301
Closed

Remove-JiraGroupMember fails #299

stevenyoungs opened this issue Jul 6, 2018 · 0 comments · Fixed by #301

Comments

@stevenyoungs
Copy link

stevenyoungs commented Jul 6, 2018

Description

Calling Remove-JiraGroupMember with valid strings for Group and User, where both group and user do exist, fails with

Get-JiraUser : The variable cannot be validated because the value $null is not a valid value for the UserName variable.

The exact line I'm using is as follows:

Remove-JiraGroupMember -Group "ValidGroupName" -User "ValidUserName" -Force -Credential $Credential

$Credential is a valid PSCredential

Steps To Reproduce

Run the following Powershell script where $Credential is a valid PSCredential for your JIRA server with admin rights.

  1. $Session = New-JiraSession -Credential $Credential
  2. Remove-JiraGroupMember -Group "ValidGroupName" -User "ValidUserName" -Force -Credential $Credential

Expected behavior

No error, and the user is removed from membership of the JIRA group

Your Environment

JiraPS 2.8.0
Windows 10
PSVersion 5.1
JIRA 7.5.0

Get-Module JiraPS -ListAvailable | select version
Version
-------
2.8.0
2.4.4

$PSVersionTable

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

Possible Solution

The problem may be inside Remove-JiraGroupMember where Get-JiraUser is called like so:

$userObj = Get-JiraUser -InputObject $_user -Credential $Credential -ErrorAction Stop

in my case $_user is a string not a JiraPs.User. Inside Get-JiraUser an attempt is made to get the field
$_user.Name with no check on the type of $_user

In v2.4.4, Get-JiraUser checked the supplied user name was of type JiraPS.User

if ((Get-Member -InputObject $i).TypeName -eq 'JiraPS.User')
and if not, assumed calling .ToString() would yield the username

@stevenyoungs stevenyoungs changed the title Remove-JIRAGroupMember fails Remove-JiraGroupMember fails Jul 6, 2018
lipkau added a commit to lipkau/JiraPS that referenced this issue Jul 8, 2018
@ghost ghost assigned lipkau Jul 8, 2018
@ghost ghost added the Status:In Review label Jul 8, 2018
lipkau added a commit that referenced this issue Jul 9, 2018
Fixed the way a string of an user is resolved
@ghost ghost removed the Status:In Review label Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants