Skip to content

Commit

Permalink
Add project group permissions and user permissions;
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoffm committed Oct 28, 2024
1 parent 8a006de commit 2b3950f
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Api/Workspaces/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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.
*
Expand Down
47 changes: 47 additions & 0 deletions src/Api/Workspaces/Projects/AbstractProjectsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Bitbucket API Client.
*
* (c) Graham Campbell <hello@gjcampbell.co.uk>
*
* 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 <p.d.barsallo@gmail.com>
*/
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;
}
}
95 changes: 95 additions & 0 deletions src/Api/Workspaces/Projects/GroupPermissions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Bitbucket API Client.
*
* (c) Graham Campbell <hello@gjcampbell.co.uk>
*
* 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 <hello@gjcampbell.co.uk>
*/
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);
}
}
110 changes: 110 additions & 0 deletions src/Api/Workspaces/Projects/UserPermissions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Bitbucket API Client.
*
* (c) Graham Campbell <hello@gjcampbell.co.uk>
*
* 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 <hello@gjcampbell.co.uk>
*/
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);
}
}

0 comments on commit 2b3950f

Please sign in to comment.