Applied API role specs to tag visits

This commit is contained in:
Alejandro Celaya
2021-01-04 11:14:28 +01:00
parent 4a1e7b761a
commit 8aa6bdb934
17 changed files with 214 additions and 37 deletions

View File

@@ -7,7 +7,9 @@ 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\BelongsToApiKeyInlined;
use Shlinkio\Shlink\Core\ShortUrl\Spec\BelongsToDomain;
use Shlinkio\Shlink\Core\ShortUrl\Spec\BelongsToDomainInlined;
use Shlinkio\Shlink\Rest\Entity\ApiKeyRole;
class Role
@@ -15,14 +17,15 @@ class Role
public const AUTHORED_SHORT_URLS = 'AUTHORED_SHORT_URLS';
public const DOMAIN_SPECIFIC = 'DOMAIN_SPECIFIC';
public static function toSpec(ApiKeyRole $role): Specification
public static function toSpec(ApiKeyRole $role, bool $inlined): Specification
{
if ($role->name() === self::AUTHORED_SHORT_URLS) {
return new BelongsToApiKey($role->apiKey());
return $inlined ? new BelongsToApiKeyInlined($role->apiKey()) : new BelongsToApiKey($role->apiKey());
}
if ($role->name() === self::DOMAIN_SPECIFIC) {
return new BelongsToDomain($role->meta()['domain_id'] ?? -1);
$domainId = $role->meta()['domain_id'] ?? -1;
return $inlined ? new BelongsToDomainInlined($domainId) : new BelongsToDomain($domainId);
}
return Spec::andX();