Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project group permissions and user permissions; #87

Open
wants to merge 2 commits into
base: 4.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
46 changes: 46 additions & 0 deletions src/Api/Workspaces/Projects/AbstractProjectsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Bitbucket API Client.
*
* (c) Graham Campbell <[email protected]>
*
* 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 <[email protected]>
*/
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 <[email protected]>
*
* 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 <[email protected]>
*/
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 <[email protected]>
*
* 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 <[email protected]>
*/
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);
}
}