Skip to content

Commit 3ff680b

Browse files
Add project permissions config APIs (#117)
1 parent f2110d7 commit 3ff680b

8 files changed

Lines changed: 382 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGE LOG
1111
* Added repository effective branching model API
1212
* Added repository pipelines config subresources
1313
* Added repository permissions config APIs
14+
* Added project permissions config APIs
1415
* Fixed result pager pagination when using partial response fields
1516
* Fixed result pager previous-page navigation
1617
* Fixed source directory listings for specific revisions

src/Api/Workspaces/Projects.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Bitbucket\Api\Workspaces;
1515

16+
use Bitbucket\Api\Workspaces\Projects\PermissionsConfig;
1617
use Bitbucket\HttpClient\Util\UriBuilder;
1718

1819
/**
@@ -72,6 +73,11 @@ public function remove(string $project, array $params = []): array
7273
return $this->delete($uri, $params);
7374
}
7475

76+
public function permissionsConfig(string $project): PermissionsConfig
77+
{
78+
return new PermissionsConfig($this->getClient(), $this->workspace, $project);
79+
}
80+
7581
/**
7682
* Build the projects URI from the given parts.
7783
*/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Bitbucket API Client.
7+
*
8+
* (c) Graham Campbell <hello@gjcampbell.co.uk>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Bitbucket\Api\Workspaces\Projects;
15+
16+
use Bitbucket\Api\Workspaces\AbstractWorkspacesApi;
17+
use Bitbucket\Client;
18+
19+
/**
20+
* The abstract projects API class.
21+
*
22+
* @author Graham Campbell <hello@gjcampbell.co.uk>
23+
*/
24+
abstract class AbstractProjectsApi extends AbstractWorkspacesApi
25+
{
26+
protected readonly string $project;
27+
28+
public function __construct(Client $client, string $workspace, string $project)
29+
{
30+
parent::__construct($client, $workspace);
31+
$this->project = $project;
32+
}
33+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Bitbucket API Client.
7+
*
8+
* (c) Graham Campbell <hello@gjcampbell.co.uk>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Bitbucket\Api\Workspaces\Projects;
15+
16+
use Bitbucket\Api\Workspaces\Projects\PermissionsConfig\Groups;
17+
use Bitbucket\Api\Workspaces\Projects\PermissionsConfig\Users;
18+
19+
/**
20+
* The permissions config API class.
21+
*
22+
* @author Graham Campbell <hello@gjcampbell.co.uk>
23+
*/
24+
class PermissionsConfig extends AbstractProjectsApi
25+
{
26+
public function groups(): Groups
27+
{
28+
return new Groups($this->getClient(), $this->workspace, $this->project);
29+
}
30+
31+
public function users(): Users
32+
{
33+
return new Users($this->getClient(), $this->workspace, $this->project);
34+
}
35+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Bitbucket API Client.
7+
*
8+
* (c) Graham Campbell <hello@gjcampbell.co.uk>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Bitbucket\Api\Workspaces\Projects\PermissionsConfig;
15+
16+
use Bitbucket\Api\Workspaces\Projects\AbstractProjectsApi;
17+
18+
/**
19+
* The abstract permissions config API class.
20+
*
21+
* @author Graham Campbell <hello@gjcampbell.co.uk>
22+
*/
23+
abstract class AbstractPermissionsConfigApi extends AbstractProjectsApi
24+
{
25+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Bitbucket API Client.
7+
*
8+
* (c) Graham Campbell <hello@gjcampbell.co.uk>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Bitbucket\Api\Workspaces\Projects\PermissionsConfig;
15+
16+
use Bitbucket\HttpClient\Util\UriBuilder;
17+
18+
/**
19+
* The groups API class.
20+
*
21+
* @author Graham Campbell <hello@gjcampbell.co.uk>
22+
*/
23+
class Groups extends AbstractPermissionsConfigApi
24+
{
25+
/**
26+
* @throws \Http\Client\Exception
27+
*/
28+
public function list(array $params = []): array
29+
{
30+
$uri = $this->buildGroupsUri();
31+
32+
return $this->get($uri, $params);
33+
}
34+
35+
/**
36+
* @throws \Http\Client\Exception
37+
*/
38+
public function show(string $group, array $params = []): array
39+
{
40+
$uri = $this->buildGroupsUri($group);
41+
42+
return $this->get($uri, $params);
43+
}
44+
45+
/**
46+
* @throws \Http\Client\Exception
47+
*/
48+
public function update(string $group, array $params = []): array
49+
{
50+
$uri = $this->buildGroupsUri($group);
51+
52+
return $this->put($uri, $params);
53+
}
54+
55+
/**
56+
* @throws \Http\Client\Exception
57+
*/
58+
public function remove(string $group, array $params = []): array
59+
{
60+
$uri = $this->buildGroupsUri($group);
61+
62+
return $this->delete($uri, $params);
63+
}
64+
65+
/**
66+
* Build the groups URI from the given parts.
67+
*/
68+
protected function buildGroupsUri(string ...$parts): string
69+
{
70+
return UriBuilder::build('workspaces', $this->workspace, 'projects', $this->project, 'permissions-config', 'groups', ...$parts);
71+
}
72+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Bitbucket API Client.
7+
*
8+
* (c) Graham Campbell <hello@gjcampbell.co.uk>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Bitbucket\Api\Workspaces\Projects\PermissionsConfig;
15+
16+
use Bitbucket\HttpClient\Util\UriBuilder;
17+
18+
/**
19+
* The users API class.
20+
*
21+
* @author Graham Campbell <hello@gjcampbell.co.uk>
22+
*/
23+
class Users extends AbstractPermissionsConfigApi
24+
{
25+
/**
26+
* @throws \Http\Client\Exception
27+
*/
28+
public function list(array $params = []): array
29+
{
30+
$uri = $this->buildUsersUri();
31+
32+
return $this->get($uri, $params);
33+
}
34+
35+
/**
36+
* @throws \Http\Client\Exception
37+
*/
38+
public function show(string $selectedUserId, array $params = []): array
39+
{
40+
$uri = $this->buildUsersUri($selectedUserId);
41+
42+
return $this->get($uri, $params);
43+
}
44+
45+
/**
46+
* @throws \Http\Client\Exception
47+
*/
48+
public function update(string $selectedUserId, array $params = []): array
49+
{
50+
$uri = $this->buildUsersUri($selectedUserId);
51+
52+
return $this->put($uri, $params);
53+
}
54+
55+
/**
56+
* @throws \Http\Client\Exception
57+
*/
58+
public function remove(string $selectedUserId, array $params = []): array
59+
{
60+
$uri = $this->buildUsersUri($selectedUserId);
61+
62+
return $this->delete($uri, $params);
63+
}
64+
65+
/**
66+
* Build the users URI from the given parts.
67+
*/
68+
protected function buildUsersUri(string ...$parts): string
69+
{
70+
return UriBuilder::build('workspaces', $this->workspace, 'projects', $this->project, 'permissions-config', 'users', ...$parts);
71+
}
72+
}

0 commit comments

Comments
 (0)