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

Add support for licensingSource and msdnLicenseType for User Entitlements #244

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .docs/Add-VSTeamUserEntitlement.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@ Required: True
Default value: ProjectContributor
```

### -LicensingSource

Licensing Source (e.g. Account. MSDN etc.). The acceptable values for this parameter are:

- account
- auto
- msdn
- none
- profile
- trial

```yaml
Type: String
Default value: account
```

### -MSDNLicenseType

Type of MSDN License (e.g. Visual Studio Professional, Visual Studio Enterprise etc.). The acceptable values for this parameter are:

- eligible
- enterprise
- none
- platforms
- premium
- professional
- testProfessional
- ultimate

```yaml
Type: String
Default value: none
```

## INPUTS

## OUTPUTS
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 6.4.5

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/244) from [Michel Zehnder](https://github.com/MichelZ) which included the following:

Add support for licensingSource and msdnLicenseType to Add-VSTeamUserEntitlement / Update-VSTeamUserEntitlement

## 6.4.4

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/231) from [Dave Neeley](https://github.com/daveneeley) which included the following:
Expand Down
8 changes: 7 additions & 1 deletion Source/Public/Add-VSTeamUserEntitlement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ function Add-VSTeamUserEntitlement {
[ValidateSet('Advanced', 'EarlyAdopter', 'Express', 'None', 'Professional', 'StakeHolder')]
[string]$License = 'EarlyAdopter',
[ValidateSet('Custom', 'ProjectAdministrator', 'ProjectContributor', 'ProjectReader', 'ProjectStakeholder')]
[string]$Group = 'ProjectContributor'
[string]$Group = 'ProjectContributor',
[ValidateSet('account', 'auto', 'msdn', 'none', 'profile', 'trial')]
[string]$LicensingSource = "account",
[ValidateSet('eligible', 'enterprise', 'none', 'platforms', 'premium', 'professional', 'testProfessional', 'ultimate')]
[string]$MSDNLicenseType = "none"
)

DynamicParam {
Expand All @@ -24,6 +28,8 @@ function Add-VSTeamUserEntitlement {
$obj = @{
accessLevel = @{
accountLicenseType = $License
licensingSource = $LicensingSource
msdnLicenseType = $MSDNLicenseType
}
user = @{
principalName = $email
Expand Down
40 changes: 32 additions & 8 deletions Source/Public/Update-VSTeamUserEntitlement.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
function Update-VSTeamUserEntitlement
{
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "High", DefaultParameterSetName = 'ByEmail')]
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "High", DefaultParameterSetName = 'ByEmailLicenseOnly')]
param (
[Parameter(ParameterSetName = 'ById', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = 'ByIdLicenseOnly', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = 'ByIdWithSource', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Alias('UserId')]
[string]$Id,

[Parameter(ParameterSetName = 'ByEmail', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = 'ByEmailLicenseOnly', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = 'ByEmailWithSource', Mandatory = $True, ValueFromPipelineByPropertyName = $true)]
[Alias('UserEmail')]
[string]$Email,

[Parameter(Mandatory = $true)]
[Parameter(ParameterSetName = 'ByIdLicenseOnly', Mandatory = $true)]
[Parameter(ParameterSetName = 'ByIdWithSource')]
[Parameter(ParameterSetName = 'ByEmailLicenseOnly', Mandatory = $true)]
[Parameter(ParameterSetName = 'ByEmailWithSource')]
[ValidateSet('Advanced', 'EarlyAdopter', 'Express', 'None', 'Professional', 'StakeHolder')]
[string]$License,

[ValidateSet('account', 'auto', 'msdn', 'none', 'profile', 'trial')]
[Parameter(ParameterSetName = 'ByIdWithSource')]
[Parameter(ParameterSetName = 'ByEmailWithSource')]
[string]$LicensingSource,

[ValidateSet('eligible', 'enterprise', 'none', 'platforms', 'premium', 'professional', 'testProfessional', 'ultimate')]
[Parameter(ParameterSetName = 'ByIdWithSource')]
[Parameter(ParameterSetName = 'ByEmailWithSource')]
[string]$MSDNLicenseType,

[switch]$Force
)

Expand All @@ -38,15 +53,22 @@ function Update-VSTeamUserEntitlement
$user = Get-VSTeamUserEntitlement -Id $id
}

$licenseOld = $user.accessLevel.accountLicenseType
$licenseTypeOriginal = $user.accessLevel.accountLicenseType
$licenseSourceOriginal = $user.accessLevel.licensingSource
$msdnLicenseTypeOriginal = $user.accessLevel.msdnLicenseType

$newLicenseType = if ($License) { $License } else { $licenseTypeOriginal }
$newLicenseSource = if ($LicensingSource) { $LicensingSource } else { $licenseSourceOriginal }
$newMSDNLicenseType = if ($MSDNLicenseType) { $MSDNLicenseType } else { $msdnLicenseTypeOriginal }

$obj = @{
from = ""
op = "replace"
path = "/accessLevel"
value = @{
accountLicenseType = $License
licensingSource = "account"
accountLicenseType = $newLicenseType
licensingSource = $newLicenseSource
msdnLicenseType = $newMSDNLicenseType
}
}

Expand All @@ -57,7 +79,9 @@ function Update-VSTeamUserEntitlement
# Call the REST API
_callAPI -Method Patch -Body $body -SubDomain 'vsaex' -Resource 'userentitlements' -Id $id -Version $([VSTeamVersions]::MemberEntitlementManagement) -ContentType 'application/json-patch+json' | Out-Null

Write-Output "Updated user license for $( $user.userName ) ($( $user.email )) from ($licenseOld) to ($License)"
Write-Output "Updated user license for $( $user.userName ) ($( $user.email )) from LicenseType: ($licenseTypeOriginal) to ($newLicenseType)"
Write-Output "Updated user license for $( $user.userName ) ($( $user.email )) from LicenseSource: ($licenseSourceOriginal) to ($newLicenseSource)"
Write-Output "Updated user license for $( $user.userName ) ($( $user.email )) from MSDNLicenseType: ($msdnLicenseTypeOriginal) to ($newMSDNLicenseType)"
}
}
}
2 changes: 1 addition & 1 deletion Source/VSTeam.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'VSTeam.psm1'

# Version number of this module.
ModuleVersion = '6.4.4'
ModuleVersion = '6.4.5'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
14 changes: 12 additions & 2 deletions integration/test/010_projects.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,25 @@ InModuleScope VSTeam {
{ Remove-VSTeamUserEntitlement -Email [email protected] -Force } | Should Throw
}

It 'Remove-VSTeamUserEntitlement should delete the team' {
It 'Remove-VSTeamUserEntitlement should delete the user' {
Remove-VSTeamUserEntitlement -Email $email -Force
Get-VSTeamUserEntitlement | Where-Object Email -eq $email | Should Be $null
}

It 'Add-VSTeamUserEntitlement should add a team' {
It 'Add-VSTeamUserEntitlement should add a user' {
Add-VSTeamUserEntitlement -Email $email -License StakeHolder | Should Not Be $null
(Get-VSTeamUserEntitlement).Count | Should Be 3
}

It 'Remove-VSTeamUserEntitlement should delete the user' {
Remove-VSTeamUserEntitlement -Email $email -Force
Get-VSTeamUserEntitlement | Where-Object Email -eq $email | Should Be $null
}

It 'Add-VSTeamUserEntitlement should add a user with MSDN license' {
Add-VSTeamUserEntitlement -Email $email -License none -LicensingSource msdn -MSDNLicenseType professional | Should not be $null
(Get-VSTeamUserEntitlement).Count | Should Be 4
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions unit/test/usersentitlement.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ InModuleScope VSTeam {
$obj = @{
accessLevel = @{
accountLicenseType = 'earlyAdopter'
licensingSource = 'msdn'
msdnLicenseType = 'enterprise'
}
user = @{
principalName = '[email protected]'
Expand All @@ -226,7 +228,7 @@ InModuleScope VSTeam {
$Body -eq $expected
}

Add-VSTeamUserEntitlement -License earlyAdopter -Email '[email protected]'
Add-VSTeamUserEntitlement -License earlyAdopter -LicensingSource msdn -MSDNLicenseType enterprise -Email '[email protected]'

It 'Should add a user' {
Assert-VerifiableMock
Expand All @@ -239,14 +241,16 @@ InModuleScope VSTeam {
members = [PSCustomObject]@{
accessLevel = [PSCustomObject]@{
accountLicenseType = "Stakeholder"
licensingSource = "msdn"
msdnLicenseType = "enterprise"
}
email = '[email protected]'
id = '00000000-0000-0000-0000-000000000000'
}
}
}

Update-VSTeamUserEntitlement -License 'Stakeholder' -Email '[email protected]' -Force
Update-VSTeamUserEntitlement -License 'Stakeholder' -LicensingSource msdn -MSDNLicenseType enterprise -Email '[email protected]' -Force

It 'Should update a user' {
Assert-MockCalled _callAPI -Exactly 1 -ParameterFilter {
Expand Down