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); + } +}