Merge branch 'develop' into feat/project-support-messages
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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 "$@"
|
||||
@@ -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)]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Doctrine;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Extension\QueryItemExtensionInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
||||
use App\Entity\Gateway\Charge;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
final class GatewayChargeExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface
|
||||
{
|
||||
public function __construct(private Security $security) {}
|
||||
|
||||
/**
|
||||
* Method that applies the filter.
|
||||
*/
|
||||
public function addFilter(QueryBuilder $queryBuilder, string $resourceClass)
|
||||
{
|
||||
if ($resourceClass !== Charge::class) {
|
||||
return; // Just apply the filter to GatewayCharge
|
||||
}
|
||||
|
||||
$user = $this->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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user