From 2b3950fcf187e70ab6b29a68933f10f67cb51bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Machado?= Date: Mon, 28 Oct 2024 12:20:22 +0000 Subject: [PATCH 1/2] Add project group permissions and user permissions; --- src/Api/Workspaces/Projects.php | 18 +++ .../Projects/AbstractProjectsApi.php | 47 ++++++++ .../Workspaces/Projects/GroupPermissions.php | 95 +++++++++++++++ .../Workspaces/Projects/UserPermissions.php | 110 ++++++++++++++++++ 4 files changed, 270 insertions(+) create mode 100644 src/Api/Workspaces/Projects/AbstractProjectsApi.php create mode 100644 src/Api/Workspaces/Projects/GroupPermissions.php create mode 100644 src/Api/Workspaces/Projects/UserPermissions.php diff --git a/src/Api/Workspaces/Projects.php b/src/Api/Workspaces/Projects.php index fa5d454..921668f 100644 --- a/src/Api/Workspaces/Projects.php +++ b/src/Api/Workspaces/Projects.php @@ -13,6 +13,8 @@ namespace Bitbucket\Api\Workspaces; +use Bitbucket\Api\Workspaces\Projects\GroupPermissions; +use Bitbucket\Api\Workspaces\Projects\UserPermissions; use Bitbucket\HttpClient\Util\UriBuilder; /** @@ -95,6 +97,22 @@ public function remove(string $project, array $params = []) return $this->delete($uri, $params); } + /** + * @return UserPermissions + */ + public function userPermissions(string $project): UserPermissions + { + return new UserPermissions($this->getClient(), $this->workspace, $project); + } + + /** + * @return GroupPermissions + */ + public function groupPermissions(string $project): GroupPermissions + { + return new GroupPermissions($this->getClient(), $this->workspace, $project); + } + /** * Build the projects URI from the given parts. * diff --git a/src/Api/Workspaces/Projects/AbstractProjectsApi.php b/src/Api/Workspaces/Projects/AbstractProjectsApi.php new file mode 100644 index 0000000..ae5728d --- /dev/null +++ b/src/Api/Workspaces/Projects/AbstractProjectsApi.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Bitbucket\Api\Workspaces\Projects; + +use Bitbucket\Api\Workspaces\AbstractWorkspacesApi; +use Bitbucket\Client; + +/** + * The abstract projects API class. + * + * @author Patrick Barsallo + */ +abstract class AbstractProjectsApi extends AbstractWorkspacesApi +{ + + /** + * The project. + * + * @var string + */ + protected $project; + + /** + * Create a new API instance. + * + * @param Client $client + * @param string $project + * + * @return void + */ + public function __construct(Client $client, string $workspace, string $project) + { + parent::__construct($client, $workspace); + $this->project = $project; + } +} diff --git a/src/Api/Workspaces/Projects/GroupPermissions.php b/src/Api/Workspaces/Projects/GroupPermissions.php new file mode 100644 index 0000000..f3599e1 --- /dev/null +++ b/src/Api/Workspaces/Projects/GroupPermissions.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Bitbucket\Api\Workspaces\Projects; + +use Bitbucket\HttpClient\Util\UriBuilder; + +/** + * The branch restrictions API class. + * + * @author Graham Campbell + */ +class GroupPermissions extends AbstractProjectsApi +{ + /** + * @param array $params + * + * @throws \Http\Client\Exception + * + * @return array + */ + public function list(array $params = []) + { + $uri = $this->buildGroupsUri(); + + return $this->get($uri, $params); + } + + /** + * @param string $group + * @param array $params + * + * @throws \Http\Client\Exception + * + * @return array + */ + public function show(string $group, array $params = []) + { + $uri = $this->buildGroupsUri($group); + + return $this->get($uri, $params); + } + + /** + * @param string $group + * @param array $params + * + * @throws \Http\Client\Exception + * + * @return array + */ + public function update(string $group, array $params = []) + { + $uri = $this->buildGroupsUri($group); + + return $this->put($uri, $params); + } + + /** + * @param string $group + * @param array $params + * + * @throws \Http\Client\Exception + * + * @return array + */ + public function remove(string $group, array $params = []) + { + $uri = $this->buildGroupsUri($group); + + return $this->delete($uri, $params); + } + + /** + * Build the groups URI from the given parts. + * + * @param string ...$parts + * + * @return string + */ + public function buildGroupsUri(string ...$parts): string + { + return UriBuilder::build('workspaces', $this->workspace, 'projects', $this->project, 'permissions-config/groups', ...$parts); + } +} diff --git a/src/Api/Workspaces/Projects/UserPermissions.php b/src/Api/Workspaces/Projects/UserPermissions.php new file mode 100644 index 0000000..d951c77 --- /dev/null +++ b/src/Api/Workspaces/Projects/UserPermissions.php @@ -0,0 +1,110 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Bitbucket\Api\Workspaces\Projects; + +use Bitbucket\HttpClient\Util\UriBuilder; + +/** + * The branch restrictions API class. + * + * @author Graham Campbell + */ +class UserPermissions extends AbstractProjectsApi +{ + /** + * @param array $params + * + * @throws \Http\Client\Exception + * + * @return array + */ + public function list(array $params = []) + { + $uri = $this->buildUsersUri(); + + return $this->get($uri, $params); + } + + /** + * @param string $user + * @param array $params + * + * @throws \Http\Client\Exception + * + * @return array + */ + public function show(string $user, array $params = []) + { + $uri = $this->buildUsersUri($user); + + return $this->get($uri, $params); + } + + /** + * @param string $user + * @param array $params + * + * @throws \Http\Client\Exception + * + * @return array + */ + public function create(string $user, array $params = []) + { + $uri = $this->buildUsersUri($user); + + return $this->put($uri, $params); + } + + /** + * @param string $user + * @param array $params + * + * @throws \Http\Client\Exception + * + * @return array + */ + public function update(string $user, array $params = []) + { + $uri = $this->buildUsersUri($user); + + return $this->put($uri, $params); + } + + /** + * @param string $user + * @param array $params + * + * @throws \Http\Client\Exception + * + * @return array + */ + public function remove(string $user, array $params = []) + { + $uri = $this->buildUsersUri($user); + + return $this->delete($uri, $params); + } + + /** + * Build the groups URI from the given parts. + * + * @param string ...$parts + * + * @return string + */ + public function buildUsersUri(string ...$parts): string + { + return UriBuilder::build('workspaces', $this->workspace, 'projects', $this->project, 'permissions-config/users', ...$parts); + } +} From fe7f87ac4491f30246a94c769e44197508ce4851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Machado?= Date: Mon, 28 Oct 2024 14:37:40 +0000 Subject: [PATCH 2/2] StyleCI; --- src/Api/Workspaces/Projects/AbstractProjectsApi.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Api/Workspaces/Projects/AbstractProjectsApi.php b/src/Api/Workspaces/Projects/AbstractProjectsApi.php index ae5728d..dbc630e 100644 --- a/src/Api/Workspaces/Projects/AbstractProjectsApi.php +++ b/src/Api/Workspaces/Projects/AbstractProjectsApi.php @@ -23,7 +23,6 @@ */ abstract class AbstractProjectsApi extends AbstractWorkspacesApi { - /** * The project. *