diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 9219990..dd8ab34 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -47,6 +47,9 @@ FROM base AS prod COPY . /app RUN chown -R www-data:www-data /app +COPY /docker/php/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + USER www-data WORKDIR /app @@ -54,4 +57,6 @@ RUN composer install --prefer-dist --no-scripts --no-dev --optimize-autoloader EXPOSE 9000 +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + CMD ["php-fpm"] diff --git a/docker/php/entrypoint.sh b/docker/php/entrypoint.sh new file mode 100644 index 0000000..f9e1a07 --- /dev/null +++ b/docker/php/entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +echo "Creating the database if it does not exist..." +php bin/console doctrine:database:create --if-not-exists + +# Check if migrations need to be applied +if ! php bin/console doctrine:migrations:up-to-date --quiet; then + echo "Applying migrations..." + php bin/console doctrine:migrations:migrate --no-interaction +fi + +# Check if FORCE_SCHEMA_UPDATE is set to true +if [ "$FORCE_SCHEMA_UPDATE" = "true" ]; then + echo "Forcing schema update..." + php bin/console doctrine:schema:update --force +fi + +# Execute the CMD from the Dockerfile +exec "$@" diff --git a/src/ApiResource/Gateway/ChargeApiResource.php b/src/ApiResource/Gateway/ChargeApiResource.php index 620af8f..9136e83 100644 --- a/src/ApiResource/Gateway/ChargeApiResource.php +++ b/src/ApiResource/Gateway/ChargeApiResource.php @@ -21,7 +21,9 @@ use Symfony\Component\Validator\Constraints as Assert; provider: ApiResourceStateProvider::class )] #[API\Get()] -#[API\GetCollection()] +#[API\GetCollection( + security: "is_granted('IS_AUTHENTICATED_FULLY')" +)] class ChargeApiResource { #[API\ApiProperty(writable: false, identifier: true)] diff --git a/src/Benzina/ProjectsBudgetPump.php b/src/Benzina/ProjectsBudgetPump.php index 2d0c037..52908b0 100644 --- a/src/Benzina/ProjectsBudgetPump.php +++ b/src/Benzina/ProjectsBudgetPump.php @@ -6,6 +6,7 @@ use App\Entity\Money; use App\Entity\Project\BudgetItem; use App\Entity\Project\BudgetItemType; use App\Entity\Project\Project; +use App\Entity\Project\ProjectDeadline; use App\Repository\Project\ProjectRepository; use Goteo\Benzina\Pump\ArrayPumpTrait; use Goteo\Benzina\Pump\DoctrinePumpTrait; @@ -59,14 +60,8 @@ class ProjectsBudgetPump implements PumpInterface $budgetItem->setType($this->getCostType($record)); $budgetItem->setTitle($record['cost']); $budgetItem->setDescription($record['description'] ?? $record['cost']); - - $money = new Money($record['amount'] * 100, 'EUR'); - - if ($record['required'] > 0) { - $budgetItem->setOptimum($money); - } else { - $budgetItem->setMinimum($money); - } + $budgetItem->setMoney(new Money($record['amount'] * 100, 'EUR')); + $budgetItem->setDeadline($this->getDeadline($record)); $this->persist($budgetItem, $context); } @@ -87,4 +82,13 @@ class ProjectsBudgetPump implements PumpInterface return BudgetItemType::Infrastructure; } } + + private function getDeadline(array $record): ProjectDeadline + { + if ($record['required'] > 0) { + return ProjectDeadline::Minimum; + } + + return ProjectDeadline::Optimum; + } } diff --git a/src/Doctrine/GatewayChargeExtension.php b/src/Doctrine/GatewayChargeExtension.php new file mode 100644 index 0000000..4ab30bc --- /dev/null +++ b/src/Doctrine/GatewayChargeExtension.php @@ -0,0 +1,67 @@ +security->getUser(); + + if (!$user instanceof \App\Entity\User\User) { + return; // If the user is not an instance of User, we do not apply the filter + } + + // If the user has ROLE_ADMIN, we dont filter the results + if ($user->hasRoles(['ROLE_ADMIN'])) { + return; + } + + $rootAlias = $queryBuilder->getRootAliases()[0]; + + // Filter by the owner user + $queryBuilder + ->leftJoin("$rootAlias.checkout", 'c') // Relationship with Gatewaycheckout + ->leftJoin('c.origin', 'co') // Relationship with Accounting + ->leftJoin('co.user', 'u') // Relationship with User + ->andWhere('u.id = :userId') // Filter by the user in the Origin entity (accounting) + ->setParameter('userId', $user->getId()); + } + + public function applyToCollection( + QueryBuilder $queryBuilder, + QueryNameGeneratorInterface $queryNameGenerator, + string $resourceClass, + ?\ApiPlatform\Metadata\Operation $operation = null, + array $context = [], + ): void { + $this->addFilter($queryBuilder, $resourceClass); + } + + public function applyToItem( + QueryBuilder $queryBuilder, + QueryNameGeneratorInterface $queryNameGenerator, + string $resourceClass, + array $identifiers, + ?\ApiPlatform\Metadata\Operation $operation = null, + array $context = [], + ): void { + $this->addFilter($queryBuilder, $resourceClass); + } +}