Skip to content

Commit 198fce1

Browse files
committed
Team Access: Update after API Endpoint Change
1 parent 54ba8c2 commit 198fce1

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* [Create a New Team](#create-a-new-team)
1616
* [Show a Team](#show-a-team)
1717
* [Edit a Team](#edit-a-team)
18+
* [Grant All Package Access](#grant-all-package-access)
19+
* [Revoke All Package Access](#revoke-all-package-access)
1820
* [Delete a Team](#delete-a-team)
1921
* [Add Member to Team (by User ID)](#add-member-to-team-by-user-id)
2022
* [Remove Member from Team](#remove-member-from-team)
@@ -126,7 +128,7 @@
126128
* [Validate incoming webhook payloads](#validate-incoming-webhook-payloads)
127129
* [License](#license)
128130

129-
<!-- Added by: glaubinix, at: Thu 9 Feb 2023 15:40:34 GMT -->
131+
<!-- Added by: zanbaldwin, at: Wed May 17 20:53:35 CEST 2023 -->
130132

131133
<!--te-->
132134

@@ -252,6 +254,20 @@ Edits a team's name and permissions to be applied to team members. Returns the u
252254

253255
The `$canAccessAllPackages` argument defaults to `null`, meaning that the setting is left unchanged.
254256

257+
#### Grant All Package Access
258+
```php
259+
$team = $client->teams()->grantAccessToAllPackages($teamId);
260+
```
261+
262+
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.
263+
264+
#### Revoke All Package Access
265+
```php
266+
$team = $client->teams()->revokeAccessToAllPackages($teamId);
267+
```
268+
269+
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.
270+
255271
#### Delete a Team
256272
```php
257273
$client->teams()->remove($teamId);

src/Api/Teams.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function all()
1818
return $this->get('/teams/');
1919
}
2020

21-
public function create(string $name, TeamPermissions $permissions, bool $canAccessAllPackages = false): array
21+
public function create(string $name, TeamPermissions $permissions): array
2222
{
2323
$parameters = [
2424
'name' => $name,
@@ -29,7 +29,6 @@ public function create(string $name, TeamPermissions $permissions, bool $canAcce
2929
'canViewVendorCustomers' => (bool) $permissions->canViewVendorCustomers,
3030
'canManageVendorCustomers' => (bool) $permissions->canManageVendorCustomers,
3131
],
32-
'canAccessAllPackages' => $canAccessAllPackages,
3332
];
3433

3534
return $this->post('/teams/', $parameters);
@@ -40,7 +39,7 @@ public function show($teamId)
4039
return $this->get(sprintf('/teams/%s/', $teamId));
4140
}
4241

43-
public function edit($teamId, string $name, TeamPermissions $permissions, ?bool $canAccessAllPackages = null): array
42+
public function edit($teamId, string $name, TeamPermissions $permissions): array
4443
{
4544
$parameters = [
4645
'name' => $name,
@@ -52,13 +51,20 @@ public function edit($teamId, string $name, TeamPermissions $permissions, ?bool
5251
'canManageVendorCustomers' => (bool) $permissions->canManageVendorCustomers,
5352
],
5453
];
55-
if ($canAccessAllPackages !== null) {
56-
$parameters['canAccessAllPackages'] = $canAccessAllPackages;
57-
}
5854

5955
return $this->put(sprintf('/teams/%s/', $teamId), $parameters);
6056
}
6157

58+
public function grantAccessToAllPackages($teamId): array
59+
{
60+
return $this->put(sprintf('/teams/%s/all-package-access/grant', $teamId));
61+
}
62+
63+
public function revokeAccessToAllPackages($teamId): array
64+
{
65+
return $this->put(sprintf('/teams/%s/all-package-access/revoke', $teamId));
66+
}
67+
6268
public function remove($teamId): array
6369
{
6470
return $this->delete(sprintf('/teams/%s/', $teamId));

tests/Api/TeamsTest.php

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public function testCreateTeam(): void
106106
'canViewVendorCustomers' => true,
107107
'canManageVendorCustomers' => false,
108108
],
109-
'canAccessAllPackages' => false,
110109
];
111110

112111
/** @var Teams&MockObject $api */
@@ -122,7 +121,6 @@ public function testCreateTeam(): void
122121
'canViewVendorCustomers' => true,
123122
'canManageVendorCustomers' => false,
124123
],
125-
'canAccessAllPackages' => false,
126124
]))
127125
->willReturn($expected);
128126

@@ -207,7 +205,6 @@ public function testEditTeam(): void
207205
'canViewVendorCustomers' => true,
208206
'canManageVendorCustomers' => false,
209207
],
210-
'canAccessAllPackages' => true,
211208
];
212209

213210
/** @var Teams&MockObject $api */
@@ -223,14 +220,61 @@ public function testEditTeam(): void
223220
'canViewVendorCustomers' => true,
224221
'canManageVendorCustomers' => false,
225222
],
226-
'canAccessAllPackages' => true,
227223
]))
228224
->willReturn($expected);
229225

230226
$permissions = new TeamPermissions;
231227
$permissions->canEditTeamPackages = true;
232228
$permissions->canViewVendorCustomers = true;
233-
$this->assertSame($expected, $api->edit(123, 'New Team', $permissions, true));
229+
$this->assertSame($expected, $api->edit(123, 'New Team', $permissions));
230+
}
231+
232+
public function testTeamGrant(): void
233+
{
234+
$expected = [
235+
'id' => 123,
236+
'name' => 'New Team',
237+
'permissions' => [
238+
'canEditTeamPackages' => true,
239+
'canAddPackages' => false,
240+
'canCreateSubrepositories' => false,
241+
'canViewVendorCustomers' => true,
242+
'canManageVendorCustomers' => false,
243+
],
244+
];
245+
246+
/** @var Teams&MockObject $api */
247+
$api = $this->getApiMock();
248+
$api->expects($this->once())
249+
->method('put')
250+
->with($this->equalTo('/teams/123/all-package-access/grant'), $this->equalTo([]))
251+
->willReturn($expected);
252+
253+
$this->assertSame($expected, $api->grantAccessToAllPackages(123));
254+
}
255+
256+
public function testTeamRevoke(): void
257+
{
258+
$expected = [
259+
'id' => 123,
260+
'name' => 'New Team',
261+
'permissions' => [
262+
'canEditTeamPackages' => true,
263+
'canAddPackages' => false,
264+
'canCreateSubrepositories' => false,
265+
'canViewVendorCustomers' => true,
266+
'canManageVendorCustomers' => false,
267+
],
268+
];
269+
270+
/** @var Teams&MockObject $api */
271+
$api = $this->getApiMock();
272+
$api->expects($this->once())
273+
->method('put')
274+
->with($this->equalTo('/teams/123/all-package-access/revoke'), $this->equalTo([]))
275+
->willReturn($expected);
276+
277+
$this->assertSame($expected, $api->revokeAccessToAllPackages(123));
234278
}
235279

236280
public function testDeleteTeam(): void

0 commit comments

Comments
 (0)