AtlassianPS / JiraPS

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

Remove-JiraGroupMember fails #299

Closed stevenyoungs closed 6 years ago

stevenyoungs commented 6 years ago

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
<!-- Not obligatory, but suggest a fix/reason for the bug -->
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