From 2c7fbbfb4604fd08f76e7350a96971e04d04fb4b Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Tue, 16 May 2023 11:25:15 +0200 Subject: [PATCH 1/9] Team: Can Access All Packages --- src/Api/Teams.php | 8 ++++++-- tests/Api/TeamsTest.php | 42 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Api/Teams.php b/src/Api/Teams.php index 815f9ff..72ba58c 100644 --- a/src/Api/Teams.php +++ b/src/Api/Teams.php @@ -18,7 +18,7 @@ public function all() return $this->get('/teams/'); } - public function create(string $name, TeamPermissions $permissions): array + public function create(string $name, TeamPermissions $permissions, bool $canAccessAllPackages = false): array { $parameters = [ 'name' => $name, @@ -29,6 +29,7 @@ public function create(string $name, TeamPermissions $permissions): array 'canViewVendorCustomers' => (bool) $permissions->canViewVendorCustomers, 'canManageVendorCustomers' => (bool) $permissions->canManageVendorCustomers, ], + 'canAccessAllPackages' => $canAccessAllPackages, ]; return $this->post('/teams/', $parameters); @@ -39,7 +40,7 @@ public function show($teamId) return $this->get(sprintf('/teams/%s/', $teamId)); } - public function edit($teamId, string $name, TeamPermissions $permissions): array + public function edit($teamId, string $name, TeamPermissions $permissions, ?bool $canAccessAllPackages = null): array { $parameters = [ 'name' => $name, @@ -51,6 +52,9 @@ public function edit($teamId, string $name, TeamPermissions $permissions): array 'canManageVendorCustomers' => (bool) $permissions->canManageVendorCustomers, ], ]; + if ($canAccessAllPackages !== null) { + $parameters['canAccessAllPackages'] = $canAccessAllPackages; + } return $this->put(sprintf('/teams/%s/', $teamId), $parameters); } diff --git a/tests/Api/TeamsTest.php b/tests/Api/TeamsTest.php index 2145dc3..de923fb 100644 --- a/tests/Api/TeamsTest.php +++ b/tests/Api/TeamsTest.php @@ -106,6 +106,7 @@ public function testCreateTeam(): void 'canViewVendorCustomers' => true, 'canManageVendorCustomers' => false, ], + 'canAccessAllPackages' => false, ]; /** @var Teams&MockObject $api */ @@ -121,6 +122,7 @@ public function testCreateTeam(): void 'canViewVendorCustomers' => true, 'canManageVendorCustomers' => false, ], + 'canAccessAllPackages' => false, ])) ->willReturn($expected); @@ -157,7 +159,7 @@ public function testShowTeam(): void $this->assertSame($expected, $api->show(123)); } - public function testEditTeam(): void + public function testEditTeamLegacy(): void { $expected = [ 'id' => 123, @@ -193,6 +195,44 @@ public function testEditTeam(): void $this->assertSame($expected, $api->edit(123, 'New Team', $permissions)); } + public function testEditTeam(): void + { + $expected = [ + 'id' => 123, + 'name' => 'New Team', + 'permissions' => [ + 'canEditTeamPackages' => true, + 'canAddPackages' => false, + 'canCreateSubrepositories' => false, + 'canViewVendorCustomers' => true, + 'canManageVendorCustomers' => false, + ], + 'canAccessAllPackages' => true, + ]; + + /** @var Teams&MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with($this->equalTo('/teams/123/'), $this->equalTo([ + 'name' => 'New Team', + 'permissions' => [ + 'canEditTeamPackages' => true, + 'canAddPackages' => false, + 'canCreateSubrepositories' => false, + 'canViewVendorCustomers' => true, + 'canManageVendorCustomers' => false, + ], + 'canAccessAllPackages' => true, + ])) + ->willReturn($expected); + + $permissions = new TeamPermissions; + $permissions->canEditTeamPackages = true; + $permissions->canViewVendorCustomers = true; + $this->assertSame($expected, $api->edit(123, 'New Team', $permissions, true)); + } + public function testDeleteTeam(): void { $expected = []; From 54ba8c2884cedd6735c18045fecd41418634b5da Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Tue, 16 May 2023 11:44:24 +0200 Subject: [PATCH 2/9] Update README --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 28212e8..28b59ba 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,10 @@ $team = $client->teams()->all()[0]; $permissions = TeamPermissions::fromTeamResponse($team); ``` +Additionally, teams have a separate "All Package Access" flag, determining whether the team has access to all current and future +organization packages which do not have their permissions synchronized. Revoking "All Package Access" will not remove access to +packages the team can currently access, but will prevent access to new packages and allow revoking individual package access. + #### List an organization's teams ```php $teams = $client->teams()->all(); @@ -223,10 +227,12 @@ Returns an array of teams. use PrivatePackagist\ApiClient\TeamPermissions; $permissions = new TeamPermissions; -$team = $client->teams()->create('New Team Name', $permissions); +$team = $client->teams()->create('New Team Name', $permissions, $canAccessAllPackages); ``` Creates a team and sets permissions applied to team members. Returns the newly-created team. +The `$canAccessAllPackages` argument defaults to `false`. + #### Show a Team ```php @@ -240,10 +246,12 @@ Returns the team including all its members. use PrivatePackagist\ApiClient\TeamPermissions; $permissions = new TeamPermissions; -$team = $client->teams()->edit($teamId, 'Altered Team Name', $permissions); +$team = $client->teams()->edit($teamId, 'Altered Team Name', $permissions, $canAccessAllPackages); ``` Edits a team's name and permissions to be applied to team members. Returns the updated team. +The `$canAccessAllPackages` argument defaults to `null`, meaning that the setting is left unchanged. + #### Delete a Team ```php $client->teams()->remove($teamId); @@ -477,7 +485,7 @@ Returns the vendor bundle. $vendorBundleId = 42; $vendorBundleData = [ 'name' => 'Bundle name', - 'minimumAccessibleStability' => 'dev', + 'minimumAccessibleStability' => 'dev', 'versionConstraint' => '^1.0', 'assignAllPackages' => true, 'synchronizationIds' => [123], // A list of synchronization ids for which new packages should automatically be added to the bundle. From 198fce183fdafe124399512fadecd376eecbc658 Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Wed, 17 May 2023 20:58:56 +0200 Subject: [PATCH 3/9] Team Access: Update after API Endpoint Change --- README.md | 18 +++++++++++++- src/Api/Teams.php | 18 +++++++++----- tests/Api/TeamsTest.php | 54 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 28b59ba..5fb0c2f 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ * [Create a New Team](#create-a-new-team) * [Show a Team](#show-a-team) * [Edit a Team](#edit-a-team) + * [Grant All Package Access](#grant-all-package-access) + * [Revoke All Package Access](#revoke-all-package-access) * [Delete a Team](#delete-a-team) * [Add Member to Team (by User ID)](#add-member-to-team-by-user-id) * [Remove Member from Team](#remove-member-from-team) @@ -126,7 +128,7 @@ * [Validate incoming webhook payloads](#validate-incoming-webhook-payloads) * [License](#license) - + @@ -252,6 +254,20 @@ Edits a team's name and permissions to be applied to team members. Returns the u The `$canAccessAllPackages` argument defaults to `null`, meaning that the setting is left unchanged. +#### Grant All Package Access +```php +$team = $client->teams()->grantAccessToAllPackages($teamId); +``` + +Granting a team access to all packages will give this team access to all current and future organization packages which do not have their permissions synchronized. + +#### Revoke All Package Access +```php +$team = $client->teams()->revokeAccessToAllPackages($teamId); +``` + +Revoking a team's access to all packages will not remove access to packages the team can currently access, but will prevent access to new packages and allow revoking individual package access. + #### Delete a Team ```php $client->teams()->remove($teamId); diff --git a/src/Api/Teams.php b/src/Api/Teams.php index 72ba58c..f0965f4 100644 --- a/src/Api/Teams.php +++ b/src/Api/Teams.php @@ -18,7 +18,7 @@ public function all() return $this->get('/teams/'); } - public function create(string $name, TeamPermissions $permissions, bool $canAccessAllPackages = false): array + public function create(string $name, TeamPermissions $permissions): array { $parameters = [ 'name' => $name, @@ -29,7 +29,6 @@ public function create(string $name, TeamPermissions $permissions, bool $canAcce 'canViewVendorCustomers' => (bool) $permissions->canViewVendorCustomers, 'canManageVendorCustomers' => (bool) $permissions->canManageVendorCustomers, ], - 'canAccessAllPackages' => $canAccessAllPackages, ]; return $this->post('/teams/', $parameters); @@ -40,7 +39,7 @@ public function show($teamId) return $this->get(sprintf('/teams/%s/', $teamId)); } - public function edit($teamId, string $name, TeamPermissions $permissions, ?bool $canAccessAllPackages = null): array + public function edit($teamId, string $name, TeamPermissions $permissions): array { $parameters = [ 'name' => $name, @@ -52,13 +51,20 @@ public function edit($teamId, string $name, TeamPermissions $permissions, ?bool 'canManageVendorCustomers' => (bool) $permissions->canManageVendorCustomers, ], ]; - if ($canAccessAllPackages !== null) { - $parameters['canAccessAllPackages'] = $canAccessAllPackages; - } return $this->put(sprintf('/teams/%s/', $teamId), $parameters); } + public function grantAccessToAllPackages($teamId): array + { + return $this->put(sprintf('/teams/%s/all-package-access/grant', $teamId)); + } + + public function revokeAccessToAllPackages($teamId): array + { + return $this->put(sprintf('/teams/%s/all-package-access/revoke', $teamId)); + } + public function remove($teamId): array { return $this->delete(sprintf('/teams/%s/', $teamId)); diff --git a/tests/Api/TeamsTest.php b/tests/Api/TeamsTest.php index de923fb..f16e710 100644 --- a/tests/Api/TeamsTest.php +++ b/tests/Api/TeamsTest.php @@ -106,7 +106,6 @@ public function testCreateTeam(): void 'canViewVendorCustomers' => true, 'canManageVendorCustomers' => false, ], - 'canAccessAllPackages' => false, ]; /** @var Teams&MockObject $api */ @@ -122,7 +121,6 @@ public function testCreateTeam(): void 'canViewVendorCustomers' => true, 'canManageVendorCustomers' => false, ], - 'canAccessAllPackages' => false, ])) ->willReturn($expected); @@ -207,7 +205,6 @@ public function testEditTeam(): void 'canViewVendorCustomers' => true, 'canManageVendorCustomers' => false, ], - 'canAccessAllPackages' => true, ]; /** @var Teams&MockObject $api */ @@ -223,14 +220,61 @@ public function testEditTeam(): void 'canViewVendorCustomers' => true, 'canManageVendorCustomers' => false, ], - 'canAccessAllPackages' => true, ])) ->willReturn($expected); $permissions = new TeamPermissions; $permissions->canEditTeamPackages = true; $permissions->canViewVendorCustomers = true; - $this->assertSame($expected, $api->edit(123, 'New Team', $permissions, true)); + $this->assertSame($expected, $api->edit(123, 'New Team', $permissions)); + } + + public function testTeamGrant(): void + { + $expected = [ + 'id' => 123, + 'name' => 'New Team', + 'permissions' => [ + 'canEditTeamPackages' => true, + 'canAddPackages' => false, + 'canCreateSubrepositories' => false, + 'canViewVendorCustomers' => true, + 'canManageVendorCustomers' => false, + ], + ]; + + /** @var Teams&MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with($this->equalTo('/teams/123/all-package-access/grant'), $this->equalTo([])) + ->willReturn($expected); + + $this->assertSame($expected, $api->grantAccessToAllPackages(123)); + } + + public function testTeamRevoke(): void + { + $expected = [ + 'id' => 123, + 'name' => 'New Team', + 'permissions' => [ + 'canEditTeamPackages' => true, + 'canAddPackages' => false, + 'canCreateSubrepositories' => false, + 'canViewVendorCustomers' => true, + 'canManageVendorCustomers' => false, + ], + ]; + + /** @var Teams&MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with($this->equalTo('/teams/123/all-package-access/revoke'), $this->equalTo([])) + ->willReturn($expected); + + $this->assertSame($expected, $api->revokeAccessToAllPackages(123)); } public function testDeleteTeam(): void From 6b6fe735df7b35e5bf8d407b5a07df3123e1857b Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Wed, 17 May 2023 21:03:40 +0200 Subject: [PATCH 4/9] Team Access: Remove Reference to Old Argument Flags --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5fb0c2f..191393f 100644 --- a/README.md +++ b/README.md @@ -229,12 +229,10 @@ Returns an array of teams. use PrivatePackagist\ApiClient\TeamPermissions; $permissions = new TeamPermissions; -$team = $client->teams()->create('New Team Name', $permissions, $canAccessAllPackages); +$team = $client->teams()->create('New Team Name', $permissions); ``` Creates a team and sets permissions applied to team members. Returns the newly-created team. -The `$canAccessAllPackages` argument defaults to `false`. - #### Show a Team ```php @@ -248,12 +246,10 @@ Returns the team including all its members. use PrivatePackagist\ApiClient\TeamPermissions; $permissions = new TeamPermissions; -$team = $client->teams()->edit($teamId, 'Altered Team Name', $permissions, $canAccessAllPackages); +$team = $client->teams()->edit($teamId, 'Altered Team Name', $permissions); ``` Edits a team's name and permissions to be applied to team members. Returns the updated team. -The `$canAccessAllPackages` argument defaults to `null`, meaning that the setting is left unchanged. - #### Grant All Package Access ```php $team = $client->teams()->grantAccessToAllPackages($teamId); From 2e5ed00366ae6f766438896f6a66846f140cecba Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Wed, 17 May 2023 21:07:11 +0200 Subject: [PATCH 5/9] Team Access: Remove Legacy Unit Test --- tests/Api/TeamsTest.php | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/tests/Api/TeamsTest.php b/tests/Api/TeamsTest.php index f16e710..5981af7 100644 --- a/tests/Api/TeamsTest.php +++ b/tests/Api/TeamsTest.php @@ -157,42 +157,6 @@ public function testShowTeam(): void $this->assertSame($expected, $api->show(123)); } - public function testEditTeamLegacy(): void - { - $expected = [ - 'id' => 123, - 'name' => 'New Team', - 'permissions' => [ - 'canEditTeamPackages' => true, - 'canAddPackages' => false, - 'canCreateSubrepositories' => false, - 'canViewVendorCustomers' => true, - 'canManageVendorCustomers' => false, - ], - ]; - - /** @var Teams&MockObject $api */ - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('put') - ->with($this->equalTo('/teams/123/'), $this->equalTo([ - 'name' => 'New Team', - 'permissions' => [ - 'canEditTeamPackages' => true, - 'canAddPackages' => false, - 'canCreateSubrepositories' => false, - 'canViewVendorCustomers' => true, - 'canManageVendorCustomers' => false, - ], - ])) - ->willReturn($expected); - - $permissions = new TeamPermissions; - $permissions->canEditTeamPackages = true; - $permissions->canViewVendorCustomers = true; - $this->assertSame($expected, $api->edit(123, 'New Team', $permissions)); - } - public function testEditTeam(): void { $expected = [ From 605794d69facbbaa36841654ed64cee61509316e Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Thu, 18 May 2023 10:27:12 +0200 Subject: [PATCH 6/9] Team Access: Remove Unnecessary Paragraph in README --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 191393f..62eab6e 100644 --- a/README.md +++ b/README.md @@ -214,10 +214,6 @@ $team = $client->teams()->all()[0]; $permissions = TeamPermissions::fromTeamResponse($team); ``` -Additionally, teams have a separate "All Package Access" flag, determining whether the team has access to all current and future -organization packages which do not have their permissions synchronized. Revoking "All Package Access" will not remove access to -packages the team can currently access, but will prevent access to new packages and allow revoking individual package access. - #### List an organization's teams ```php $teams = $client->teams()->all(); From ce72bb2d0fac5790f906600bb6954d2332b0135d Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Thu, 18 May 2023 11:22:23 +0200 Subject: [PATCH 7/9] Add Legacy HTTPlug Message Implementation --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index ab73c4b..9aea97b 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "require-dev": { "phpunit/phpunit": "^8.0 || ^9.0", "guzzlehttp/guzzle": "^7", + "php-http/message-factory": "^1.1", "php-http/mock-client": "^1.0", "friendsofphp/php-cs-fixer": "^3.0", "phpstan/phpstan": "^1.2" From 75758b9389907938ae42f32d9a01a059257a7ef6 Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Thu, 18 May 2023 11:46:44 +0200 Subject: [PATCH 8/9] Promote php-http/message-factory to required dependency --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9aea97b..552d7ea 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ "php-http/discovery": "^1.0", "psr/http-client-implementation": "^1.0", "php-http/client-common": "^1.9 || ^2.0", + "php-http/message-factory": "^1.1", "composer-runtime-api": "^2.0" }, "require-dev": { "phpunit/phpunit": "^8.0 || ^9.0", "guzzlehttp/guzzle": "^7", - "php-http/message-factory": "^1.1", "php-http/mock-client": "^1.0", "friendsofphp/php-cs-fixer": "^3.0", "phpstan/phpstan": "^1.2" From 3cdb1e11377eaf9bc498fbd2ec06160fe1173ee0 Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Thu, 18 May 2023 12:27:58 +0200 Subject: [PATCH 9/9] Composer: Make Dependency Constraint be Less Restrictive --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 552d7ea..987103d 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "php-http/discovery": "^1.0", "psr/http-client-implementation": "^1.0", "php-http/client-common": "^1.9 || ^2.0", - "php-http/message-factory": "^1.1", + "php-http/message-factory": "^1.0", "composer-runtime-api": "^2.0" }, "require-dev": {