From 8b6a3e7622937877250fe2b0bf66f7c69f2755d8 Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Tue, 29 Apr 2025 14:45:46 +0200 Subject: [PATCH 1/6] Remove security attribute to get charge collection --- src/ApiResource/Gateway/ChargeApiResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ApiResource/Gateway/ChargeApiResource.php b/src/ApiResource/Gateway/ChargeApiResource.php index 23b2b05..212ea8d 100644 --- a/src/ApiResource/Gateway/ChargeApiResource.php +++ b/src/ApiResource/Gateway/ChargeApiResource.php @@ -24,7 +24,7 @@ use Symfony\Component\Validator\Constraints as Assert; provider: ApiResourceStateProvider::class )] #[API\Get()] -#[API\GetCollection(security: "is_granted('IS_AUTHENTICATED_FULLY')")] +#[API\GetCollection()] #[API\Patch( input: ChargeUpdationDto::class, processor: ChargeStateProcessor::class, From ffd3d12a6a7987ba647b6cfb624900d9a52dd01d Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Wed, 30 Apr 2025 10:38:24 +0200 Subject: [PATCH 2/6] Update extension to toggle public visibility --- src/Doctrine/GatewayChargeExtension.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Doctrine/GatewayChargeExtension.php b/src/Doctrine/GatewayChargeExtension.php index cbdb24d..76554b4 100644 --- a/src/Doctrine/GatewayChargeExtension.php +++ b/src/Doctrine/GatewayChargeExtension.php @@ -10,6 +10,8 @@ final class GatewayChargeExtension extends AbstractQueryResourceExtensionInterfa { use UserTrait; + private const ARE_PUBLIC = true; + protected function supports(string $resourceClass): bool { return $resourceClass === Charge::class; @@ -17,6 +19,10 @@ final class GatewayChargeExtension extends AbstractQueryResourceExtensionInterfa protected function applyFilters(QueryBuilder $queryBuilder, string $rootAlias): void { + if (self::ARE_PUBLIC) { + return; + } + $user = $this->getAuthenticatedUser(); if ($this->isAdmin($user)) { From e78f21eb6c159a40f1f624bb402a99812d2eb33a Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Wed, 30 Apr 2025 10:39:29 +0200 Subject: [PATCH 3/6] Hide checkout for unauthenticated user --- src/ApiResource/Gateway/ChargeApiResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ApiResource/Gateway/ChargeApiResource.php b/src/ApiResource/Gateway/ChargeApiResource.php index 212ea8d..f821eb7 100644 --- a/src/ApiResource/Gateway/ChargeApiResource.php +++ b/src/ApiResource/Gateway/ChargeApiResource.php @@ -37,7 +37,7 @@ class ChargeApiResource /** * The Checkout to which this Charge item belongs to. */ - #[API\ApiProperty(writable: false)] + #[API\ApiProperty(writable: false, security: "is_granted('ROLE_USER')")] public CheckoutApiResource $checkout; /** From 5824d767e30cee9ea855c0d0223d8f24d0074b59 Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Wed, 30 Apr 2025 12:13:07 +0200 Subject: [PATCH 4/6] Change role needed to see the origin of the charges --- src/ApiResource/Gateway/ChargeApiResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ApiResource/Gateway/ChargeApiResource.php b/src/ApiResource/Gateway/ChargeApiResource.php index f821eb7..cb3d6ff 100644 --- a/src/ApiResource/Gateway/ChargeApiResource.php +++ b/src/ApiResource/Gateway/ChargeApiResource.php @@ -37,7 +37,7 @@ class ChargeApiResource /** * The Checkout to which this Charge item belongs to. */ - #[API\ApiProperty(writable: false, security: "is_granted('ROLE_USER')")] + #[API\ApiProperty(writable: false, security: 'is_granted("IS_AUTHENTICATED_FULLY")')] public CheckoutApiResource $checkout; /** From 61fca1ff6e3583fc2c4ca754c3299a5b598d1d0f Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Mon, 5 May 2025 14:56:34 +0200 Subject: [PATCH 5/6] Delete GatewayCharge Extension --- src/Doctrine/GatewayChargeExtension.php | 39 ------------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/Doctrine/GatewayChargeExtension.php diff --git a/src/Doctrine/GatewayChargeExtension.php b/src/Doctrine/GatewayChargeExtension.php deleted file mode 100644 index 76554b4..0000000 --- a/src/Doctrine/GatewayChargeExtension.php +++ /dev/null @@ -1,39 +0,0 @@ -getAuthenticatedUser(); - - if ($this->isAdmin($user)) { - return; - } - - $queryBuilder - ->leftJoin("$rootAlias.checkout", 'c') - ->leftJoin('c.origin', 'co') - ->leftJoin('co.user', 'u') - ->andWhere('u.id = :userId') - ->setParameter('userId', $user->getId()); - } -} From 3769aa5d93430ab70b4a977330fde6f54ee27c6d Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Wed, 7 May 2025 15:10:10 +0200 Subject: [PATCH 6/6] Make TipjarApiResource --- .../Accounting/AccountingApiResource.php | 5 ++- src/ApiResource/TipjarApiResource.php | 42 +++++++++++++++++++ src/Entity/Tipjar.php | 10 ++--- 3 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 src/ApiResource/TipjarApiResource.php diff --git a/src/ApiResource/Accounting/AccountingApiResource.php b/src/ApiResource/Accounting/AccountingApiResource.php index 29c26c5..befca59 100644 --- a/src/ApiResource/Accounting/AccountingApiResource.php +++ b/src/ApiResource/Accounting/AccountingApiResource.php @@ -5,6 +5,7 @@ namespace App\ApiResource\Accounting; use ApiPlatform\Doctrine\Orm\State\Options; use ApiPlatform\Metadata as API; use App\ApiResource\Project\ProjectApiResource; +use App\ApiResource\TipjarApiResource; use App\ApiResource\User\UserApiResource; use App\Entity\Accounting\Accounting; use App\Entity\Money; @@ -56,7 +57,7 @@ class AccountingApiResource /** * The resource owning this Accounting. * - * @return UserApiResource|ProjectApiResource|Tipjar + * @return UserApiResource|ProjectApiResource|TipjarApiResource */ public function getOwner(): ?object { @@ -79,5 +80,5 @@ class AccountingApiResource public ?ProjectApiResource $project = null; #[API\ApiProperty(readable: false, writable: false)] - public ?Tipjar $tipjar = null; + public ?TipjarApiResource $tipjar = null; } diff --git a/src/ApiResource/TipjarApiResource.php b/src/ApiResource/TipjarApiResource.php new file mode 100644 index 0000000..5b58421 --- /dev/null +++ b/src/ApiResource/TipjarApiResource.php @@ -0,0 +1,42 @@ +