mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Created specs for API key roles
This commit is contained in:
30
module/Rest/src/ApiKey/Role.php
Normal file
30
module/Rest/src/ApiKey/Role.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\ApiKey;
|
||||
|
||||
use Happyr\DoctrineSpecification\Spec;
|
||||
use Happyr\DoctrineSpecification\Specification\Specification;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Spec\BelongsToApiKey;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Spec\BelongsToDomain;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKeyRole;
|
||||
|
||||
class Role
|
||||
{
|
||||
public const AUTHORED_SHORT_URLS = 'AUTHORED_SHORT_URLS';
|
||||
public const DOMAIN_SPECIFIC = 'DOMAIN_SPECIFIC';
|
||||
|
||||
public static function toSpec(ApiKeyRole $role): Specification
|
||||
{
|
||||
if ($role->name() === self::AUTHORED_SHORT_URLS) {
|
||||
return new BelongsToApiKey($role->apiKey());
|
||||
}
|
||||
|
||||
if ($role->name() === self::DOMAIN_SPECIFIC) {
|
||||
return new BelongsToDomain($role->meta()['domain_id'] ?? -1);
|
||||
}
|
||||
|
||||
return Spec::andX();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user