Skip to content

Commit

Permalink
Add SyliusApi VAT field to serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Apr 29, 2024
1 parent 2d15bc9 commit b9ba9ae
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 30 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ Add default config if you want to get access to the default fixtures this plugin

imports:
- { resource: "@FluxSESyliusEUVatPlugin/config/config.yaml" }
- { resource: "@FluxSESyliusEUVatPlugin/config/admin.yaml" } # If you are using SyliusAdminBundle
# If you are using SyliusAdminBundle
- { resource: "@FluxSESyliusEUVatPlugin/config/admin.yaml" }

```

Expand Down
4 changes: 4 additions & 0 deletions config/api_resources/address.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'%sylius.model.address.class%':
properties:
vatNumber:
writable: true
35 changes: 35 additions & 0 deletions config/serialization/Address.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" ?>

<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="FluxSE\SyliusEUVatPlugin\Entity\VATNumberAwareInterface">
<attribute name="vatNumber">
<group>admin:address:index</group>
<group>sylius:admin:address:index</group>
<group>admin:address:show</group>
<group>sylius:admin:address:show</group>
<group>admin:address:update</group>
<group>sylius:admin:address:update</group>
<group>admin:order:index</group>
<group>sylius:admin:order:index</group>
<group>admin:order:show</group>
<group>sylius:admin:order:show</group>
<group>shop:address:create</group>
<group>sylius:shop:address:create</group>
<group>shop:address:index</group>
<group>sylius:shop:address:index</group>
<group>shop:address:show</group>
<group>sylius:shop:address:show</group>
<group>shop:address:update</group>
<group>sylius:shop:address:update</group>
<group>shop:cart:update</group>
<group>sylius:shop:cart:update</group>
<group>shop:cart:show</group>
<group>sylius:shop:cart:show</group>
<group>shop:order:account:show</group>
<group>sylius:shop:order:account:show</group>
</attribute>
</class>
</serializer>
14 changes: 14 additions & 0 deletions src/DependencyInjection/FluxSESyliusEUVatExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,19 @@ public function load(array $configs, ContainerBuilder $container): void
public function prepend(ContainerBuilder $container): void
{
$this->prependDoctrineMigrations($container);

if ($container->hasExtension('sylius_api')) {
$this->prependApiPlatformMapping($container);
}
}

private function prependApiPlatformMapping(ContainerBuilder $container): void
{
/** @var array<string, array<string, string>> $metadata */
$metadata = $container->getParameter('kernel.bundles_metadata');

$path = $metadata['FluxSESyliusEUVatPlugin']['path'] . '/config/api_resources';

$container->prependExtensionConfig('api_platform', ['mapping' => ['paths' => [$path]]]);
}
}
2 changes: 0 additions & 2 deletions tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__) . '../../../vendor/autoload.php';
Expand Down
4 changes: 3 additions & 1 deletion tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
imports:
- { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" }

- { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" }

- { resource: "@SyliusAdminBundle/Resources/config/app/config.yml" }

- { resource: "@SyliusShopBundle/Resources/config/app/config.yml" }
- { resource: "../parameters.yaml" }

- { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" }

parameters:
sylius_core.public_dir: '%kernel.project_dir%/public'
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/config/packages/sylius_api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sylius_api:
enabled: true
2 changes: 2 additions & 0 deletions tests/Application/config/parameters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
locale: en_US
4 changes: 0 additions & 4 deletions tests/Application/config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en_US
30 changes: 9 additions & 21 deletions tests/Application/config/symfony/6.4/packages/security.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
parameters:
sylius.security.admin_regex: "^/%sylius_admin.path_name%"
sylius.security.api_regex: "^/api"
sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++"
sylius.security.new_api_route: "/new-api"
sylius.security.new_api_regex: "^%sylius.security.new_api_route%"
sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin"
sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%"
sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/shop"
sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%"

security:
enable_authenticator_manager: true
providers:
Expand All @@ -20,13 +9,8 @@ security:
id: sylius.shop_user_provider.email_or_name_based
sylius_api_shop_user_provider:
id: sylius.shop_user_provider.email_or_name_based
sylius_api_chain_provider:
chain:
providers: [ sylius_api_shop_user_provider, sylius_api_admin_user_provider ]

password_hashers:
Sylius\Component\User\Model\UserInterface: argon2i

firewalls:
admin:
switch_user: true
Expand Down Expand Up @@ -60,7 +44,7 @@ security:
stateless: true
entry_point: jwt
json_login:
check_path: "%sylius.security.new_api_admin_route%/authentication-token"
check_path: "%sylius.security.new_api_admin_route%/administrators/token"
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
Expand All @@ -73,7 +57,7 @@ security:
stateless: true
entry_point: jwt
json_login:
check_path: "%sylius.security.new_api_shop_route%/authentication-token"
check_path: "%sylius.security.new_api_shop_route%/customers/token"
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
Expand Down Expand Up @@ -108,6 +92,10 @@ security:
target: sylius_shop_homepage
invalidate_session: false

image_resolver:
pattern: ^/media/cache/resolve
security: false

dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
Expand All @@ -129,9 +117,9 @@ security:
- { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS }
- { path: "%sylius.security.shop_regex%/account", role: ROLE_USER }

- { path: "%sylius.security.new_api_admin_route%/reset-password-requests", role: PUBLIC_ACCESS }
- { path: "%sylius.security.new_api_admin_route%/administrators/reset-password", role: PUBLIC_ACCESS }
- { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS }
- { path: "%sylius.security.new_api_admin_route%/authentication-token", role: PUBLIC_ACCESS }
- { path: "%sylius.security.new_api_admin_route%/administrators/token", role: PUBLIC_ACCESS }
- { path: "%sylius.security.new_api_user_account_regex%/.*", role: ROLE_USER }
- { path: "%sylius.security.new_api_shop_route%/authentication-token", role: PUBLIC_ACCESS }
- { path: "%sylius.security.new_api_shop_route%/customers/token", role: PUBLIC_ACCESS }
- { path: "%sylius.security.new_api_shop_regex%/.*", role: PUBLIC_ACCESS }
4 changes: 3 additions & 1 deletion tests/Application/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

require_once dirname(__DIR__) . '/../../vendor/autoload_runtime.php';

return static fn(array $context) => new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
return static function (array $context) {
return new Kernel($context['APP_ENV'], (bool)$context['APP_DEBUG']);
};

0 comments on commit b9ba9ae

Please sign in to comment.