Skip to content

Commit

Permalink
fix api-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Dec 19, 2023
1 parent 5b6d890 commit c0e5969
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
15 changes: 8 additions & 7 deletions databox/api/src/Entity/Core/RenditionDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class RenditionDefinition extends AbstractUuidEntity implements \Stringable
final public const GROUP_READ = 'renddef:read';
final public const GROUP_LIST = 'renddef:index';
final public const GROUP_WRITE = 'renddef:w';
private const GRANT_ADMIN_PROP = "object ? is_granted('READ_ADMIN', object) : true";

/**
* Override trait for annotation.
Expand All @@ -104,37 +105,37 @@ class RenditionDefinition extends AbstractUuidEntity implements \Stringable

#[Groups([RenditionDefinition::GROUP_LIST, RenditionDefinition::GROUP_READ, RenditionDefinition::GROUP_WRITE])]
#[ORM\Column(type: Types::BOOLEAN)]
#[ApiProperty(security: "is_granted('READ_ADMIN', object)")]
#[ApiProperty(security: self::GRANT_ADMIN_PROP)]
private bool $pickSourceFile = false;

#[Groups([RenditionDefinition::GROUP_LIST, RenditionDefinition::GROUP_READ, RenditionDefinition::GROUP_WRITE])]
#[ORM\Column(type: Types::BOOLEAN)]
#[ApiProperty(security: "is_granted('READ_ADMIN', object)")]
#[ApiProperty(security: self::GRANT_ADMIN_PROP)]
private bool $useAsOriginal = false;

#[Groups([RenditionDefinition::GROUP_LIST, RenditionDefinition::GROUP_READ, RenditionDefinition::GROUP_WRITE])]
#[ORM\Column(type: Types::BOOLEAN)]
#[ApiProperty(security: "is_granted('READ_ADMIN', object)")]
#[ApiProperty(security: self::GRANT_ADMIN_PROP)]
private bool $useAsPreview = false;

#[Groups([RenditionDefinition::GROUP_LIST, RenditionDefinition::GROUP_READ, RenditionDefinition::GROUP_WRITE])]
#[ORM\Column(type: Types::BOOLEAN)]
#[ApiProperty(security: "is_granted('READ_ADMIN', object)")]
#[ApiProperty(security: self::GRANT_ADMIN_PROP)]
private bool $useAsThumbnail = false;

#[Groups([RenditionDefinition::GROUP_LIST, RenditionDefinition::GROUP_READ, RenditionDefinition::GROUP_WRITE])]
#[ORM\Column(type: Types::BOOLEAN)]
#[ApiProperty(security: "is_granted('READ_ADMIN', object)")]
#[ApiProperty(security: self::GRANT_ADMIN_PROP)]
private bool $useAsThumbnailActive = false;

#[Groups([RenditionDefinition::GROUP_LIST, RenditionDefinition::GROUP_READ, RenditionDefinition::GROUP_WRITE])]
#[ORM\Column(type: Types::TEXT)]
#[ApiProperty(security: "is_granted('READ_ADMIN', object)")]
#[ApiProperty(security: self::GRANT_ADMIN_PROP)]
private ?string $definition = '';

#[Groups([RenditionDefinition::GROUP_LIST, RenditionDefinition::GROUP_READ, RenditionDefinition::GROUP_WRITE])]
#[ORM\Column(type: Types::SMALLINT, nullable: false)]
#[ApiProperty(security: "is_granted('READ_ADMIN', object)")]
#[ApiProperty(security: self::GRANT_ADMIN_PROP)]
private int $priority = 0;

/**
Expand Down
29 changes: 29 additions & 0 deletions databox/api/tests/Api/RenditionDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,33 @@ public function testUpdateRenditionDefinition(): void
'useAsThumbnail' => true,
]);
}

public function testGetRenditionDefinition(): void
{
self::enableFixtures();
$client = static::createClient();
$iri = $this->findIriBy(RenditionDefinition::class, ['name' => 'preview']);

$response = $client->request('GET', $iri, [
'headers' => [
'Authorization' => 'Bearer '.KeycloakClientTestMock::getJwtFor(KeycloakClientTestMock::USER_UID),
],
]);
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@id' => $iri,
]);
$this->assertArrayNotHasKey('useAsThumbnail', $response->toArray());

$client->request('GET', $iri, [
'headers' => [
'Authorization' => 'Bearer '.KeycloakClientTestMock::getJwtFor(KeycloakClientTestMock::ADMIN_UID),
],
]);
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@id' => $iri,
'useAsThumbnail' => false,
]);
}
}

0 comments on commit c0e5969

Please sign in to comment.