From 55942776c954e58cccadce99abfbbba89bebd78b Mon Sep 17 00:00:00 2001 From: Seekatar Date: Thu, 1 Aug 2019 06:40:27 -0400 Subject: [PATCH] add membership to PSDrive --- CHANGELOG.md | 11 +++++++ Source/Classes/VSTeamAccount.ps1 | 3 +- Source/Classes/VSTeamGroups.ps1 | 29 +++++++++++++++++++ Source/Classes/VSTeamPermissions.ps1 | 24 +++++++++++++++ Source/Classes/VSTeamUsers.ps1 | 29 +++++++++++++++++++ Source/Classes/_classes.json | 3 ++ Source/en-US/about_vsteam_provider.help.txt | 17 +++++++++-- Source/formats/Team.Build.TableView.ps1xml | 2 +- .../Team.PSDrive.Default.TableView.ps1xml | 2 +- unit/test/teamspsdrive.Tests.ps1 | 29 +++++++++++++++++-- 10 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 Source/Classes/VSTeamGroups.ps1 create mode 100644 Source/Classes/VSTeamPermissions.ps1 create mode 100644 Source/Classes/VSTeamUsers.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 35ce33928..02d290d85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 6.3.2 + +Add PSDrive support for memberships + +- Memberships + - Groups + - Group1 + - Users + - User1 + + ## 6.3.1 Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/178) from [Jim W](https://github.com/Seekatar) which included the following: diff --git a/Source/Classes/VSTeamAccount.ps1 b/Source/Classes/VSTeamAccount.ps1 index 0bfb6aebc..0a3316de5 100644 --- a/Source/Classes/VSTeamAccount.ps1 +++ b/Source/Classes/VSTeamAccount.ps1 @@ -18,7 +18,8 @@ class VSTeamAccount : SHiPSDirectory { $poolsAndProjects = @( [VSTeamPools]::new('Agent Pools'), [VSTeamExtensions]::new('Extensions') - [VSTeamFeeds]::new('Feeds') + [VSTeamFeeds]::new('Feeds'), + [VSTeamPermissions]::new('Permissions') ) $items = Get-VSTeamProject | Sort-Object Name diff --git a/Source/Classes/VSTeamGroups.ps1 b/Source/Classes/VSTeamGroups.ps1 new file mode 100644 index 000000000..548e35f91 --- /dev/null +++ b/Source/Classes/VSTeamGroups.ps1 @@ -0,0 +1,29 @@ +using namespace Microsoft.PowerShell.SHiPS + +[SHiPSProvider(UseCache = $true)] +[SHiPSProvider(BuiltinProgress = $false)] +class VSTeamGroups : VSTeamDirectory { + + # Default constructor + VSTeamGroups( + [string]$Name + ) : base($Name, $null) { + $this.AddTypeName('Team.Groups') + + $this.DisplayMode = 'd-r-s-' + } + + [object[]] GetChildItem() { + $Groups = Get-VSTeamGroup -ErrorAction SilentlyContinue | Sort-Object name + + $objs = @() + + foreach ($Group in $Groups) { + $Group.AddTypeName('Team.Provider.Group') + + $objs += $Group + } + + return $objs + } +} \ No newline at end of file diff --git a/Source/Classes/VSTeamPermissions.ps1 b/Source/Classes/VSTeamPermissions.ps1 new file mode 100644 index 000000000..66226effe --- /dev/null +++ b/Source/Classes/VSTeamPermissions.ps1 @@ -0,0 +1,24 @@ +using namespace Microsoft.PowerShell.SHiPS + +[SHiPSProvider(UseCache = $true)] +[SHiPSProvider(BuiltinProgress = $false)] +class VSTeamPermissions : VSTeamDirectory { + + # Default constructor + VSTeamPermissions( + [string]$Name + ) : base($Name, $null) { + $this.AddTypeName('Team.Permissions') + + $this.DisplayMode = 'd-r-s-' + } + + [object[]] GetChildItem() { + $groupsAndUsers = @( + [VSTeamGroups]::new('Groups'), + [VSTeamUsers]::new('Users') + ) + + return $groupsAndUsers + } +} \ No newline at end of file diff --git a/Source/Classes/VSTeamUsers.ps1 b/Source/Classes/VSTeamUsers.ps1 new file mode 100644 index 000000000..4517c76a0 --- /dev/null +++ b/Source/Classes/VSTeamUsers.ps1 @@ -0,0 +1,29 @@ +using namespace Microsoft.PowerShell.SHiPS + +[SHiPSProvider(UseCache = $true)] +[SHiPSProvider(BuiltinProgress = $false)] +class VSTeamUsers : VSTeamDirectory { + + # Default constructor + VSTeamUsers( + [string]$Name + ) : base($Name, $null) { + $this.AddTypeName('Team.Users') + + $this.DisplayMode = 'd-r-s-' + } + + [object[]] GetChildItem() { + $Users = Get-VSTeamUser -ErrorAction SilentlyContinue | Sort-Object name + + $objs = @() + + foreach ($User in $Users) { + $User.AddTypeName('Team.Provider.User') + + $objs += $User + } + + return $objs + } +} \ No newline at end of file diff --git a/Source/Classes/_classes.json b/Source/Classes/_classes.json index 4b22f265b..23ab01714 100644 --- a/Source/Classes/_classes.json +++ b/Source/Classes/_classes.json @@ -34,6 +34,9 @@ "VSTeamBuildDefinition.ps1", "VSTeamExtension.ps1", "VSTeamFeed.ps1", + "VSTeamUsers.ps1", + "VSTeamGroups.ps1", + "VSTeamPermissions.ps1", "VSTeamProcess.ps1", "VSTeamRef.ps1", "VSTeamTeam.ps1", diff --git a/Source/en-US/about_vsteam_provider.help.txt b/Source/en-US/about_vsteam_provider.help.txt index 5c290e302..68e8e8b68 100644 --- a/Source/en-US/about_vsteam_provider.help.txt +++ b/Source/en-US/about_vsteam_provider.help.txt @@ -11,6 +11,17 @@ SHORT DESCRIPTION - Agent1 - JobRequest1 - JobRequest2 + - Extensions + - Extension1 + - Extension2 + - Feeds + - Feed1 + - Feed2 + - Memberships + - Groups + - Group1 + - Users + - User1 - Project1 - Project2 - Builds @@ -33,10 +44,10 @@ SHORT DESCRIPTION - Ref2 LONG DESCRIPTION - You use the New-PSDrive cmdlet to mount a drive to your account. + You use the New-PSDrive cmdlet to mount a drive to your account. You can also use the -Drive parameter of Set-VSTeamAccount to have - the required command written to the console so you can copy and + the required command written to the console so you can copy and paste the command. The provider caches the results. To force a round trip to skip the @@ -49,7 +60,7 @@ EXAMPLES Get-ChildItem Set-VSTeamAccount -Profile '[profileName]' -Drive '[driveName]' - + To map a drive run the following command: New-PSDrive -Name driveName -PSProvider SHiPS -Root 'VSTeam#VSTeamAccount' diff --git a/Source/formats/Team.Build.TableView.ps1xml b/Source/formats/Team.Build.TableView.ps1xml index 628c730ad..562b693a6 100644 --- a/Source/formats/Team.Build.TableView.ps1xml +++ b/Source/formats/Team.Build.TableView.ps1xml @@ -1 +1 @@ -Team.Build.TableViewTeam.Provider.BuildVSTeamBuildDisplayModenamestatusresultBuildDefinition +Team.PSDrive.Default.TableViewMicrosoft.PowerShell.SHiPS.SHiPSDirectoryTeam.AccountTeam.PoolTeam.QueuesTeam.PoolsTeam.Provider.PoolsTeam.BuildsTeam.BuildDefinitionsTeam.ReleasesTeam.RepositoriesTeam.TeamsTeam.PermissionsTeam.GroupsTeam.UsersDisplayModeName \ No newline at end of file diff --git a/Source/formats/Team.PSDrive.Default.TableView.ps1xml b/Source/formats/Team.PSDrive.Default.TableView.ps1xml index 487aa7255..562b693a6 100644 --- a/Source/formats/Team.PSDrive.Default.TableView.ps1xml +++ b/Source/formats/Team.PSDrive.Default.TableView.ps1xml @@ -1 +1 @@ -Team.PSDrive.Default.TableViewMicrosoft.PowerShell.SHiPS.SHiPSDirectoryTeam.AccountTeam.PoolTeam.QueuesTeam.PoolsTeam.Provider.PoolsTeam.BuildsTeam.BuildDefinitionsTeam.ReleasesTeam.RepositoriesTeam.TeamsDisplayModeName +Team.PSDrive.Default.TableViewMicrosoft.PowerShell.SHiPS.SHiPSDirectoryTeam.AccountTeam.PoolTeam.QueuesTeam.PoolsTeam.Provider.PoolsTeam.BuildsTeam.BuildDefinitionsTeam.ReleasesTeam.RepositoriesTeam.TeamsTeam.PermissionsTeam.GroupsTeam.UsersDisplayModeName \ No newline at end of file diff --git a/unit/test/teamspsdrive.Tests.ps1 b/unit/test/teamspsdrive.Tests.ps1 index 2853497ab..e3ed06419 100644 --- a/unit/test/teamspsdrive.Tests.ps1 +++ b/unit/test/teamspsdrive.Tests.ps1 @@ -110,7 +110,7 @@ InModuleScope VSTeam { } } } - + Describe 'VSTS Build Definition' { # Mock the call to Get-Projects by the dynamic parameter for ProjectName Mock Invoke-RestMethod { return @() } -ParameterFilter { @@ -209,7 +209,8 @@ InModuleScope VSTeam { # Skip 0 because that will be Agent Pools # Skip 1 because that will be Extensions # Skip 2 because that will be Feeds - $project = $account.GetChildItem()[3] + # Skip 3 because that will be Permissions + $project = $account.GetChildItem()[4] It 'Should return projects' { $project | Should Not Be $null @@ -538,5 +539,29 @@ InModuleScope VSTeam { $team | Should Not Be $null } } + + Context 'Permissions' { + Set-StrictMode -Version Latest + Mock Get-VSTeamGroup { return [VSTeamGroup]::new(@{})} + Mock Get-VSTeamUser { return [VSTeamGroup]::new(@{})} + + $permissions = [VSTeamPermissions]::new('Permissions') + + It 'Should create Permissions' { + $permissions | Should Not Be $null + $permissions.GetChildItem().Count | Should Be 2 + } + + $groups = $permissions.GetChildItem()[0] + $users = $permissions.GetChildItem()[1] + + It 'Should return groups' { + $groups | Should Not Be $null + } + + It 'Should return users' { + $users | Should Not Be $null + } + } } } \ No newline at end of file