Skip to content

Commit

Permalink
Merge pull request #82 from packagist/suborganization-rename
Browse files Browse the repository at this point in the history
Add suborganization API and deprecated subrepository API
  • Loading branch information
glaubinix authored Dec 12, 2024
2 parents 2f24c2a + da7a9df commit e389d73
Show file tree
Hide file tree
Showing 17 changed files with 1,033 additions and 142 deletions.
251 changes: 126 additions & 125 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace PrivatePackagist\ApiClient\Api;

/**
* @deprecated Use the Subrepositories API instead
* @deprecated Use the Suborganizations API instead
*/
class Projects extends Subrepositories
{
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Projects/MirroredRepositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace PrivatePackagist\ApiClient\Api\Projects;

/**
* @deprecated Use Subrepositories\MirroredRepositories instead
* @deprecated Use \PrivatePackagist\ApiClient\Api\Suborganizations\MirroredRepositories instead
*/
class MirroredRepositories extends \PrivatePackagist\ApiClient\Api\Subrepositories\MirroredRepositories
{
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Projects/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace PrivatePackagist\ApiClient\Api\Projects;

/**
* @deprecated Use Subrepositories\Packages instead
* @deprecated Use \PrivatePackagist\ApiClient\Api\Suborganizations\Packages instead
*/
class Packages extends \PrivatePackagist\ApiClient\Api\Subrepositories\Packages
{
Expand Down
94 changes: 94 additions & 0 deletions src/Api/Suborganizations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/**
* (c) Packagist Conductors GmbH <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PrivatePackagist\ApiClient\Api;

use PrivatePackagist\ApiClient\Exception\InvalidArgumentException;

class Suborganizations extends AbstractApi
{
public function all()
{
return $this->get('/suborganizations/');
}

public function show($suborganizationName)
{
return $this->get(sprintf('/suborganizations/%s/', $suborganizationName));
}

public function create($name)
{
return $this->post('/suborganizations/', ['name' => $name]);
}

public function remove($suborganizationName)
{
return $this->delete(sprintf('/suborganizations/%s/', $suborganizationName));
}

public function listTeams($suborganizationName)
{
return $this->get(sprintf('/suborganizations/%s/teams/', $suborganizationName));
}

public function addOrEditTeams($suborganizationName, array $teams)
{
foreach ($teams as $team) {
if (!isset($team['id'])) {
throw new InvalidArgumentException('Parameter "id" is required.');
}

if (!isset($team['permission'])) {
throw new InvalidArgumentException('Parameter "permission" is required.');
}
}

return $this->post(sprintf('/suborganizations/%s/teams/', $suborganizationName), $teams);
}

public function removeTeam($suborganizationName, $teamId)
{
return $this->delete(sprintf('/suborganizations/%s/teams/%s/', $suborganizationName, $teamId));
}

public function listTokens($suborganizationName)
{
return $this->get(sprintf('/suborganizations/%s/tokens/', $suborganizationName));
}

public function createToken($suborganizationName, array $tokenData)
{
return $this->post(sprintf('/suborganizations/%s/tokens/', $suborganizationName), $tokenData);
}

public function removeToken($suborganizationName, $tokenId)
{
return $this->delete(sprintf('/suborganizations/%s/tokens/%s/', $suborganizationName, $tokenId));
}

public function regenerateToken($suborganizationName, $tokenId, array $confirmation)
{
if (!isset($confirmation['IConfirmOldTokenWillStopWorkingImmediately'])) {
throw new InvalidArgumentException('Confirmation is required to regenerate the Composer repository token.');
}

return $this->post(sprintf('/suborganizations/%s/tokens/%s/regenerate', $suborganizationName, $tokenId), $confirmation);
}

public function packages()
{
return new Suborganizations\Packages($this->client);
}

public function mirroredRepositories()
{
return new Suborganizations\MirroredRepositories($this->client);
}
}
64 changes: 64 additions & 0 deletions src/Api/Suborganizations/MirroredRepositories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* (c) Packagist Conductors GmbH <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PrivatePackagist\ApiClient\Api\Suborganizations;

use PrivatePackagist\ApiClient\Api\AbstractApi;
use PrivatePackagist\ApiClient\Exception\InvalidArgumentException;

class MirroredRepositories extends AbstractApi
{
public function all($suborganizationName)
{
return $this->get(sprintf('/suborganizations/%s/mirrored-repositories/', $suborganizationName));
}

public function add($suborganizationName, array $mirroredRepositories)
{
foreach ($mirroredRepositories as $mirroredRepository) {
if (!isset($mirroredRepository['id'], $mirroredRepository['mirroringBehavior'])) {
throw new InvalidArgumentException('The "id" and the "mirroringBehavior" are required to add a mirrored repository to a project');
}
}

return $this->post(sprintf('/suborganizations/%s/mirrored-repositories/', $suborganizationName), $mirroredRepositories);
}

public function show($suborganizationName, $mirroredRepositoryId)
{
return $this->get(sprintf('/suborganizations/%s/mirrored-repositories/%s/', $suborganizationName, $mirroredRepositoryId));
}

public function edit($suborganizationName, $mirroredRepositoryId, $mirroringBehavior)
{
return $this->put(sprintf('/suborganizations/%s/mirrored-repositories/%s/', $suborganizationName, $mirroredRepositoryId), [
'mirroringBehavior' => $mirroringBehavior,
]);
}

public function remove($suborganizationName, $mirroredRepositoryId)
{
return $this->delete(sprintf('/suborganizations/%s/mirrored-repositories/%s/', $suborganizationName, $mirroredRepositoryId));
}

public function listPackages($suborganizationName, $mirroredRepositoryId)
{
return $this->get(sprintf('/suborganizations/%s/mirrored-repositories/%s/packages/', $suborganizationName, $mirroredRepositoryId));
}

public function addPackages($suborganizationName, $mirroredRepositoryId, array $packages)
{
return $this->post(sprintf('/suborganizations/%s/mirrored-repositories/%s/packages/', $suborganizationName, $mirroredRepositoryId), $packages);
}

public function removePackages($suborganizationName, $mirroredRepositoryId)
{
return $this->delete(sprintf('/suborganizations/%s/mirrored-repositories/%s/packages/', $suborganizationName, $mirroredRepositoryId));
}
}
70 changes: 70 additions & 0 deletions src/Api/Suborganizations/Packages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* (c) Packagist Conductors GmbH <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PrivatePackagist\ApiClient\Api\Suborganizations;

use PrivatePackagist\ApiClient\Api\AbstractApi;
use PrivatePackagist\ApiClient\Exception\InvalidArgumentException;
use PrivatePackagist\ApiClient\Payload\CustomPackageConfig;
use PrivatePackagist\ApiClient\Payload\VcsPackageConfig;

class Packages extends AbstractApi
{
public function all($suborganizationName, array $filters = [])
{
if (isset($filters['origin']) && !in_array($filters['origin'], \PrivatePackagist\ApiClient\Api\Packages::AVAILABLE_ORIGINS, true)) {
throw new InvalidArgumentException('Filter "origin" has to be one of: "' . implode('", "', \PrivatePackagist\ApiClient\Api\Packages::AVAILABLE_ORIGINS) . '".');
}

return $this->get(sprintf('/suborganizations/%s/packages/', $suborganizationName), $filters);
}

public function show($suborganizationName, $packageIdOrName)
{
return $this->get(sprintf('/suborganizations/%s/packages/%s', $suborganizationName, $packageIdOrName));
}

public function createVcsPackage($suborganizationName, $url, $credentialId = null, $type = 'vcs', $defaultSuborganizationAccess = null)
{
$data = new VcsPackageConfig($url, $credentialId, $type, $defaultSuborganizationAccess);

return $this->post(sprintf('/suborganizations/%s/packages/', $suborganizationName), $data->toParameters());
}

public function createCustomPackage($suborganizationName, $customJson, $credentialId = null, $defaultSuborganizationAccess = null)
{
$data = new CustomPackageConfig($customJson, $credentialId, $defaultSuborganizationAccess);

return $this->post(sprintf('/suborganizations/%s/packages/', $suborganizationName), $data->toParameters());
}

public function editVcsPackage($suborganizationName, $packageIdOrName, $url, $credentialId = null, $type = 'vcs', $defaultSuborganizationAccess = null)
{
$data = new VcsPackageConfig($url, $credentialId, $type, $defaultSuborganizationAccess);

return $this->put(sprintf('/suborganizations/%s/packages/%s/', $suborganizationName, $packageIdOrName), $data->toParameters());
}

public function editCustomPackage($suborganizationName, $packageIdOrName, $customJson, $credentialId = null, $defaultSuborganizationAccess = null)
{
$data = new CustomPackageConfig($customJson, $credentialId, $defaultSuborganizationAccess);

return $this->put(sprintf('/suborganizations/%s/packages/%s/', $suborganizationName, $packageIdOrName), $data->toParameters());
}

public function remove($suborganizationName, $packageIdOrName)
{
return $this->delete(sprintf('/suborganizations/%s/packages/%s/', $suborganizationName, $packageIdOrName));
}

public function listDependents($suborganizationName, $packageIdOrName)
{
return $this->get(sprintf('/suborganizations/%s/packages/%s/dependents/', $suborganizationName, $packageIdOrName));
}
}
3 changes: 3 additions & 0 deletions src/Api/Subrepositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

use PrivatePackagist\ApiClient\Exception\InvalidArgumentException;

/**
* @deprecated Use the Suborganizations API instead
*/
class Subrepositories extends AbstractApi
{
public function all()
Expand Down
3 changes: 3 additions & 0 deletions src/Api/Subrepositories/MirroredRepositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use PrivatePackagist\ApiClient\Api\AbstractApi;
use PrivatePackagist\ApiClient\Exception\InvalidArgumentException;

/**
* @deprecated Use \PrivatePackagist\ApiClient\Api\Suborganizations\MirroredRepositories instead
*/
class MirroredRepositories extends AbstractApi
{
public function all($subrepositoryName)
Expand Down
3 changes: 3 additions & 0 deletions src/Api/Subrepositories/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use PrivatePackagist\ApiClient\Payload\CustomPackageConfig;
use PrivatePackagist\ApiClient\Payload\VcsPackageConfig;

/**
* @deprecated Use \PrivatePackagist\ApiClient\Api\Suborganizations\Packages instead
*/
class Packages extends AbstractApi
{
public function all($subrepositoryName, array $filters = [])
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function create(string $name, TeamPermissions $permissions): array
'permissions' => [
'canEditTeamPackages' => (bool) $permissions->canEditTeamPackages,
'canAddPackages' => (bool) $permissions->canAddPackages,
'canCreateSubrepositories' => (bool) $permissions->canCreateSubrepositories,
'canCreateSuborganizations' => $permissions->canCreateSuborganizations || $permissions->canCreateSubrepositories,
'canViewVendorCustomers' => (bool) $permissions->canViewVendorCustomers,
'canManageVendorCustomers' => (bool) $permissions->canManageVendorCustomers,
],
Expand All @@ -46,7 +46,7 @@ public function edit($teamId, string $name, TeamPermissions $permissions): array
'permissions' => [
'canEditTeamPackages' => (bool) $permissions->canEditTeamPackages,
'canAddPackages' => (bool) $permissions->canAddPackages,
'canCreateSubrepositories' => (bool) $permissions->canCreateSubrepositories,
'canCreateSuborganizations' => $permissions->canCreateSuborganizations || $permissions->canCreateSubrepositories,
'canViewVendorCustomers' => (bool) $permissions->canViewVendorCustomers,
'canManageVendorCustomers' => (bool) $permissions->canManageVendorCustomers,
],
Expand Down
13 changes: 11 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,28 @@ public function customers()
}

/**
* @deprecated Use Client::subrepositories instead
* @deprecated Use Client::suborganizations instead
*/
#[\Deprecated('Use Client::subrepositories instead', '1.16.1')]
#[\Deprecated('Use Client::suborganizations instead', '1.16.1')]
public function projects()
{
return new Api\Subrepositories($this, $this->responseMediator);
}

/**
* @deprecated Use Client::suborganizations instead
*/
#[\Deprecated('Use Client::suborganizations instead', '1.38.0')]
public function subrepositories()
{
return new Api\Subrepositories($this, $this->responseMediator);
}

public function suborganizations()
{
return new Api\Suborganizations($this, $this->responseMediator);
}

public function organization()
{
return new Api\Organization($this, $this->responseMediator);
Expand Down
17 changes: 14 additions & 3 deletions src/TeamPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ final class TeamPermissions
{
public const PERMISSION_CAN_EDIT_TEAM_PACKAGES = 1 << 0;
public const PERMISSION_CAN_ADD_PACKAGES = 1 << 1;
/** @deprecated Use PERMISSION_CAN_CREATE_SUBORGANIZATIONS instead */
#[\Deprecated('Use TeamPermissions::PERMISSION_CAN_CREATE_SUBORGANIZATIONS instead', '1.38.0')]
public const PERMISSION_CAN_CREATE_SUBREPOSITORIES = 1 << 2;
public const PERMISSION_CAN_CREATE_SUBORGANIZATIONS = 1 << 2;
public const PERMISSION_CAN_VIEW_VENDOR_CUSTOMERS = 1 << 3;
public const PERMISSION_CAN_MANAGE_VENDOR_CUSTOMERS = 1 << 4;

/** @var bool */
public $canEditTeamPackages = false;
/** @var bool */
public $canAddPackages = false;
/** @var bool */
/**
* @var bool
* @deprecated Use $canCreateSuborganizations instead
*/
public $canCreateSubrepositories = false;
public $canCreateSuborganizations = false;
/** @var bool */
public $canViewVendorCustomers = false;
/** @var bool */
Expand All @@ -33,18 +40,22 @@ public static function fromFlags(int $flags): self
$permissions = new self;
$permissions->canEditTeamPackages = ($flags & self::PERMISSION_CAN_EDIT_TEAM_PACKAGES) > 0;
$permissions->canAddPackages = ($flags & self::PERMISSION_CAN_ADD_PACKAGES) > 0;
$permissions->canCreateSubrepositories = ($flags & self::PERMISSION_CAN_CREATE_SUBREPOSITORIES) > 0;
$permissions->canCreateSubrepositories = ($flags & self::PERMISSION_CAN_CREATE_SUBORGANIZATIONS) > 0;
$permissions->canCreateSuborganizations = ($flags & self::PERMISSION_CAN_CREATE_SUBORGANIZATIONS) > 0;
$permissions->canViewVendorCustomers = ($flags & self::PERMISSION_CAN_VIEW_VENDOR_CUSTOMERS) > 0;
$permissions->canManageVendorCustomers = ($flags & self::PERMISSION_CAN_MANAGE_VENDOR_CUSTOMERS) > 0;
return $permissions;
}

public static function fromTeamResponse(array $team): self
{
$canCreateSuborganizations = isset($team['permissions']['canCreateSuborganizations']) && $team['permissions']['canCreateSuborganizations'] || isset($team['permissions']['canCreateSubrepositories']) && $team['permissions']['canCreateSubrepositories'];

$permissions = new self;
$permissions->canEditTeamPackages = isset($team['permissions']['canEditTeamPackages']) && $team['permissions']['canEditTeamPackages'];
$permissions->canAddPackages = isset($team['permissions']['canAddPackages']) && $team['permissions']['canAddPackages'];
$permissions->canCreateSubrepositories = isset($team['permissions']['canCreateSubrepositories']) && $team['permissions']['canCreateSubrepositories'];
$permissions->canCreateSubrepositories = $canCreateSuborganizations;
$permissions->canCreateSuborganizations = $canCreateSuborganizations;
$permissions->canViewVendorCustomers = isset($team['permissions']['canViewVendorCustomers']) && $team['permissions']['canViewVendorCustomers'];
$permissions->canManageVendorCustomers = isset($team['permissions']['canManageVendorCustomers']) && $team['permissions']['canManageVendorCustomers'];
return $permissions;
Expand Down
Loading

0 comments on commit e389d73

Please sign in to comment.