Skip to content

Commit

Permalink
[Customer] Remove channel code from customer routes
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Jul 19, 2019
1 parent e23f952 commit 58805d6
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 222 deletions.
16 changes: 11 additions & 5 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@

* The channel code has been removed from routes:

| Old Route | New route |
|:--------------------------------------|:---------------------------------------|
| `{channelCode}/address-book/*` | `address-book/*` |
| `{channelCode}/checkout/*` | `checkout/*` |
| `{channelCode}/orders/*` | `orders/*` |
| Old Route | New route |
|:-----------------------------------------|:------------------------------------|
| `{channelCode}/address-book/*` | `address-book/*` |
| `{channelCode}/checkout/*` | `checkout/*` |
| `{channelCode}/me` | `me` |
| `{channelCode}/orders/*` | `orders/*` |
| `{channelCode}/password-reset/*` | `password-reset/*` |
| `{channelCode}/register` | `orders/*` |
| `{channelCode}/request-password-reset` | `request-password-reset` |
| `{channelCode}/resend-verification-link` | `resend-verification-link` |
| `{channelCode}/verify-account` | `verify-account` |

# UPGRADE FROM 1.0.0-beta.17 to 1.0.0-beta.18

Expand Down
19 changes: 8 additions & 11 deletions doc/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,8 @@ paths:
description: "Requested taxon with children."
schema:
$ref: "#/definitions/TaxonDetails"
/{channelCode}/request-password-reset:
parameters:
- $ref: "#/parameters/ChannelCode"

/request-password-reset:
put:
tags:
- "users"
Expand All @@ -703,9 +702,9 @@ paths:
description: "Reset password request has been sent."
500:
description: "User with provided email has not been found."
/{channelCode}/password-reset/{token}:

/password-reset/{token}:
parameters:
- $ref: "#/parameters/ChannelCode"
- in: "path"
name: "token"
description: "Password reset token."
Expand All @@ -728,9 +727,8 @@ paths:
description: "Update password request success."
400:
description: "Token not found."
/{channelCode}/register:
parameters:
- $ref: "#/parameters/ChannelCode"

/register:
post:
tags:
- "users"
Expand Down Expand Up @@ -793,9 +791,8 @@ paths:
description: "Order with given tokenValue not found"
security:
- bearerAuth: []
/{channelCode}/me:
parameters:
- $ref: "#/parameters/ChannelCode"

/me:
get:
tags:
- "users"
Expand Down
17 changes: 14 additions & 3 deletions src/Controller/Customer/RegisterCustomerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface;
use Sylius\ShopApiPlugin\Request\Customer\RegisterCustomerRequest;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -27,26 +28,36 @@ final class RegisterCustomerAction
/** @var ValidationErrorViewFactoryInterface */
private $validationErrorViewFactory;

/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
ViewHandlerInterface $viewHandler,
MessageBusInterface $bus,
ValidatorInterface $validator,
ValidationErrorViewFactoryInterface $validationErrorViewFactory
ValidationErrorViewFactoryInterface $validationErrorViewFactory,
ChannelContextInterface $channelContext
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
$this->channelContext = $channelContext;
}

public function __invoke(Request $request): Response
{
$registerCustomerRequest = new RegisterCustomerRequest($request);
$channel = $this->channelContext->getChannel();

$registerCustomerRequest = new RegisterCustomerRequest($request, $channel->getCode());

$validationResults = $this->validator->validate($registerCustomerRequest);

if (0 !== count($validationResults)) {
return $this->viewHandler->handle(View::create($this->validationErrorViewFactory->create($validationResults), Response::HTTP_BAD_REQUEST));
return $this->viewHandler->handle(View::create(
$this->validationErrorViewFactory->create($validationResults),
Response::HTTP_BAD_REQUEST
));
}

$this->bus->dispatch($registerCustomerRequest->getCommand());
Expand Down
16 changes: 13 additions & 3 deletions src/Controller/Customer/RequestPasswordResettingAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\ShopApiPlugin\Command\Customer\GenerateResetPasswordToken;
use Sylius\ShopApiPlugin\Command\Customer\SendResetPasswordToken;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -20,16 +21,25 @@ final class RequestPasswordResettingAction
/** @var MessageBusInterface */
private $bus;

public function __construct(ViewHandlerInterface $viewHandler, MessageBusInterface $bus)
{
/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
ViewHandlerInterface $viewHandler,
MessageBusInterface $bus,
ChannelContextInterface $channelContext
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->channelContext = $channelContext;
}

public function __invoke(Request $request): Response
{
$channel = $this->channelContext->getChannel();

$this->bus->dispatch(new GenerateResetPasswordToken($request->request->get('email')));
$this->bus->dispatch(new SendResetPasswordToken($request->request->get('email'), $request->attributes->get('channelCode')));
$this->bus->dispatch(new SendResetPasswordToken($request->request->get('email'), $channel->getCode()));

return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT));
}
Expand Down
17 changes: 14 additions & 3 deletions src/Controller/Customer/ResendVerificationTokenAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface;
use Sylius\ShopApiPlugin\Request\Customer\ResendVerificationTokenRequest;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -27,26 +28,36 @@ final class ResendVerificationTokenAction
/** @var ValidationErrorViewFactoryInterface */
private $validationErrorViewFactory;

/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
ViewHandlerInterface $viewHandler,
MessageBusInterface $bus,
ValidatorInterface $validator,
ValidationErrorViewFactoryInterface $validationErrorViewFactory
ValidationErrorViewFactoryInterface $validationErrorViewFactory,
ChannelContextInterface $channelContext
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
$this->channelContext = $channelContext;
}

public function __invoke(Request $request): Response
{
$resendVerificationTokenRequest = new ResendVerificationTokenRequest($request);
$channel = $this->channelContext->getChannel();

$resendVerificationTokenRequest = new ResendVerificationTokenRequest($request, $channel->getCode());

$validationResults = $this->validator->validate($resendVerificationTokenRequest);

if (0 !== count($validationResults)) {
return $this->viewHandler->handle(View::create($this->validationErrorViewFactory->create($validationResults), Response::HTTP_BAD_REQUEST));
return $this->viewHandler->handle(View::create(
$this->validationErrorViewFactory->create($validationResults),
Response::HTTP_BAD_REQUEST
));
}

$this->bus->dispatch($resendVerificationTokenRequest->getCommand());
Expand Down
4 changes: 2 additions & 2 deletions src/Request/Customer/RegisterCustomerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class RegisterCustomerRequest
/** @var string */
protected $channelCode;

public function __construct(Request $request)
public function __construct(Request $request, string $channelCode)
{
$this->channelCode = $request->attributes->get('channelCode');
$this->channelCode = $channelCode;

$this->email = $request->request->get('email');
$this->plainPassword = $request->request->get('plainPassword');
Expand Down
4 changes: 2 additions & 2 deletions src/Request/Customer/ResendVerificationTokenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class ResendVerificationTokenRequest
/** @var string */
protected $channelCode;

public function __construct(Request $request)
public function __construct(Request $request, string $channelCode)
{
$this->email = $request->request->get('email');
$this->channelCode = $request->attributes->get('channelCode');
$this->channelCode = $channelCode;
}

public function getCommand(): SendVerificationToken
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ sylius_shop_api_taxon:

sylius_shop_api_register:
resource: "@ShopApiPlugin/Resources/config/routing/register.yml"
prefix: /shop-api/{channelCode}
prefix: /shop-api

sylius_shop_api_checkout:
resource: "@ShopApiPlugin/Resources/config/routing/checkout.yml"
prefix: /shop-api/checkout

sylius_shop_api_customer:
resource: "@ShopApiPlugin/Resources/config/routing/customer.yml"
prefix: /shop-api/{channelCode}
prefix: /shop-api

sylius_shop_api_product_list:
resource: "@ShopApiPlugin/Resources/config/routing/productList.yml"
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/services/actions/customer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<argument type="service" id="sylius_shop_api_plugin.command_bus" />
<argument type="service" id="validator" />
<argument type="service" id="sylius.shop_api_plugin.factory.validation_error_view_factory" />
<argument type="service" id="sylius.context.channel" />
</service>

<service id="sylius.shop_api_plugin.controller.customer.verify_account_action"
Expand All @@ -29,13 +30,15 @@
<argument type="service" id="sylius_shop_api_plugin.command_bus" />
<argument type="service" id="validator" />
<argument type="service" id="sylius.shop_api_plugin.factory.validation_error_view_factory" />
<argument type="service" id="sylius.context.channel" />
</service>

<service id="sylius.shop_api_plugin.controller.customer.request_password_resetting_action"
class="Sylius\ShopApiPlugin\Controller\Customer\RequestPasswordResettingAction"
>
<argument type="service" id="fos_rest.view_handler" />
<argument type="service" id="sylius_shop_api_plugin.command_bus" />
<argument type="service" id="sylius.context.channel" />
</service>

<service id="sylius.shop_api_plugin.controller.customer.logged_in_customer_details_action"
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/Customer/CustomerLoginApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function it_requires_to_verify_email_address_for_newly_created_customers(
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/register', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/register', [], [], self::CONTENT_TYPE_HEADER, $data);

$data =
<<<EOT
Expand Down
31 changes: 4 additions & 27 deletions tests/Controller/Customer/CustomerRegisterApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function it_allows_to_register_in_shop_and_sends_a_verification_email_if_
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/register', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/register', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
Expand Down Expand Up @@ -67,7 +67,7 @@ public function it_allows_to_register_in_shop_and_automatically_enables_user_if_
}
EOT;

$this->client->request('POST', '/shop-api/WEB_DE/register', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', 'http://web-de.com/shop-api/register', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
Expand Down Expand Up @@ -108,7 +108,7 @@ public function it_does_not_allow_to_register_in_shop_if_email_is_already_taken(
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/register', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/register', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();

Expand All @@ -131,36 +131,13 @@ public function it_does_not_allow_to_register_in_shop_without_passing_required_d
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/register', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/register', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();

$this->assertResponse($response, 'customer/validation_registration_data_response', Response::HTTP_BAD_REQUEST);
}

/**
* @test
*/
public function it_does_not_allow_to_register_in_non_existent_channel(): void
{
$this->loadFixturesFromFiles(['channel.yml']);

$data =
<<<EOT
{
"firstName": "Vin",
"lastName": "Diesel",
"plainPassword": "somepass"
}
EOT;

$this->client->request('POST', '/shop-api/SPACE_KLINGON/register', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();

$this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND);
}

protected function getContainer(): ContainerInterface
{
return static::$sharedKernel->getContainer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function it_allows_to_reset_user_password(): void

$data = '{"email": "oliver@queen.com"}';

$this->client->request('PUT', '/shop-api/WEB_GB/request-password-reset', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('PUT', '/shop-api/request-password-reset', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
Expand All @@ -34,21 +34,6 @@ public function it_allows_to_reset_user_password(): void
$this->assertTrue($emailChecker->hasRecipient('oliver@queen.com'));
}

/**
* @test
*/
public function it_does_not_allow_to_reset_user_password_in_non_existent_channel(): void
{
$this->loadFixturesFromFiles(['channel.yml', 'customer.yml']);

$data = '{"email": "oliver@queen.com"}';

$this->client->request('PUT', '/shop-api/SPACE_KLINGON/request-password-reset', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND);
}

protected function getContainer(): ContainerInterface
{
return static::$sharedKernel->getContainer();
Expand Down
Loading

0 comments on commit 58805d6

Please sign in to comment.