Skip to content
Merged
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
4 changes: 0 additions & 4 deletions backend/packages/Core/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ services:
App\Fishbowl\Stage\FishbowlValidateStage:
decorates: api_platform.graphql.resolver.stage.validate

App\Fishbowl\DataProvider\FishbowlDataProvider:
bind:
$collectionDataProvider: '@api_platform.doctrine.orm.default.collection_data_provider'

# Admin
App\Core\Admin\UserAdmin:
tags:
Expand Down
4 changes: 2 additions & 2 deletions backend/packages/Fishbowl/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ services:
App\Fishbowl\Stage\FishbowlValidateStage:
decorates: api_platform.graphql.resolver.stage.validate

App\Fishbowl\DataProvider\FishbowlDataProvider:
App\Fishbowl\State\FishbowlStateProvider:
bind:
$collectionDataProvider: '@api_platform.doctrine.orm.default.collection_data_provider'
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'

#Admin
App\Fishbowl\Admin\FishbowlAdmin:
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion backend/packages/Fishbowl/src/Entity/Fishbowl.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use App\Fishbowl\Resolver\FishbowlResolver;
use App\Fishbowl\Resolver\FishbowlRunMutationResolver;
use App\Fishbowl\State\FishbowlProcessor;
use App\Fishbowl\State\FishbowlStateProvider;
use App\Fishbowl\Validator\Constraints\FutureFishbowl;
use App\Fishbowl\Validator\Constraints\PrivateFishbowl;
use Doctrine\Common\Collections\ArrayCollection;
Expand All @@ -56,7 +57,7 @@
operations: [
new Get(),
new Put(security: 'object.getHost() == user'),
new GetCollection(security: 'is_granted(\'ROLE_USER\')'),
new GetCollection(security: 'is_granted(\'ROLE_USER\')', provider: FishbowlStateProvider::class),
new Post(security: 'is_granted(\'ROLE_USER\')'),
],
normalizationContext: ['groups' => ['fishbowl:read']],
Expand Down
48 changes: 48 additions & 0 deletions backend/packages/Fishbowl/src/State/FishbowlStateProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Stooa codebase.
*
* (c) 2020 - present Runroom SL
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\Fishbowl\State;

use ApiPlatform\Doctrine\Orm\State\CollectionProvider;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Fishbowl\Entity\Fishbowl;
use App\Fishbowl\Service\PrivateFishbowlService;

/**
* @implements ProviderInterface<Fishbowl>
*/
class FishbowlStateProvider implements ProviderInterface
{
public function __construct(
private readonly PrivateFishbowlService $privateFishbowlService,
private readonly CollectionProvider $collectionProvider
) {
}

/**
* @param array<array-key, mixed> $uriVariables
* @param array<mixed> $context
*/
public function provide(Operation $operation, array $uriVariables = [], array $context = [])
{
/** @var iterable<Fishbowl> $fishbowls */
$fishbowls = $this->collectionProvider->provide($operation, $uriVariables, $context);

foreach ($fishbowls as $fishbowl) {
$this->privateFishbowlService->decryptPrivatePassword($fishbowl);
}

return $fishbowls;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,46 @@ public function itGetsFishbowlsFilteredByAfterDate(): void
$this->assertSame($fishbowl->getName(), $response->toArray()['hydra:member'][0]['name']);
}

/** @test */
public function itGetsPasswordInPrivateFishbowls(): void
{
$now = new \DateTime();

$fishbowl = FishbowlFactory::createOne([
'name' => 'fishbowl name',
'startDateTime' => new \DateTime('+ 30 minutes'),
'timezone' => 'Europe/Madrid',
'duration' => \DateTime::createFromFormat('!H:i', '30:00'),
'currentStatus' => Fishbowl::STATUS_NOT_STARTED,
'host' => $this->host,
'isPrivate' => true,
'plainPassword' => 'password',
])->object();

$hostToken = $this->logIn($this->host);

$response = static::createClient()->request('GET', '/fishbowls', [
'query' => [
'finishDateTime[after]' => $now->format(\DateTimeInterface::ISO8601),
],
'auth_bearer' => $hostToken,
]);

$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/Fishbowl',
'@id' => '/fishbowls',
'@type' => 'hydra:Collection',
'hydra:totalItems' => 1,
]);

$this->assertMatchesResourceCollectionJsonSchema(Fishbowl::class);

$this->assertSame($fishbowl->getName(), $response->toArray()['hydra:member'][0]['name']);
$this->assertSame($fishbowl->getPlainPassword(), $response->toArray()['hydra:member'][0]['plainPassword']);
}

/** @test */
public function itGetsFishbowlsFilteredByBeforeDate(): void
{
Expand Down