Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
CI bot committed Jan 8, 2025
2 parents 8960cdc + 9a9daa0 commit 1aff74f
Show file tree
Hide file tree
Showing 40 changed files with 176 additions and 253 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ For all events except start 3 events are triggered. `oro_workflow.<event_name>`,
* Changed a field value of the `type` field on a string instead of the removed `\Oro\Bundle\ThemeBundle\Entity\Enum\ThemeConfigurationType` enum for `\Oro\Bundle\ThemeBundle\Entity\ThemeConfiguration` entity.

#### ApiBundle
* The `masterRequest` attribute in API context was replaced with `mainRequest`. If you have API processors that use the `masterRequest` attribute in the `oro.api.processor` service tag it should be replaces with the `mainRequest` attribute.
* Changed `\Oro\Bundle\ApiBundle\Filter\FilterValueAccessorInterface` to be able to use filters by same field but with different operators, e.g. `?filter[id][gt]=1&filter[id][lt]=10`:
- added `getOne` method
- changed return value for `get` method from `?FilterValue` to `FilterValue[]`
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/ActionBundle/Helper/ContextHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getActionParameters(array $context)
{
$request = $this->requestStack->getMainRequest();
if (!$request) {
throw new \RuntimeException('Master Request is not defined');
throw new \RuntimeException('The main request is not defined.');
}
$params = [
self::ROUTE_PARAM => $request->attributes->get('_route'),
Expand Down
42 changes: 5 additions & 37 deletions src/Oro/Bundle/ActionBundle/Provider/OriginalUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,19 @@
use Oro\Bundle\ActionBundle\Button\ButtonSearchContext;
use Oro\Bundle\DataGridBundle\Converter\UrlConverter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;

/**
* Provides original URL for action button extensions,
* basically original URL refers to the master request URL, but
* in case when master request was ajax request provider tries to
* basically original URL refers to the main request URL, but
* in case when main request was ajax request provider tries to
* build URL using url parameter "originalRoute" (it uses for datagrids)
*/
class OriginalUrlProvider
{
/** @var RequestStack */
private $requestStack;

/** @var RouterInterface */
private $router;

/** @var UrlConverter */
private $datagridUrlConverter;

public function __construct(
RequestStack $requestStack,
RouterInterface $router,
UrlConverter $datagridUrlConverter
private readonly RequestStack $requestStack,
private readonly UrlConverter $datagridUrlConverter
) {
$this->requestStack = $requestStack;
$this->router = $router;
$this->datagridUrlConverter = $datagridUrlConverter;
}

/**
Expand All @@ -42,7 +28,7 @@ public function __construct(
*/
public function getOriginalUrl(ButtonSearchContext $buttonSearchContext = null): ?string
{
$originalUrl = $this->getMasterRequestUri();
$originalUrl = $this->requestStack->getMainRequest()?->getRequestUri();
if (null === $originalUrl) {
return null;
}
Expand All @@ -63,22 +49,4 @@ public function getOriginalUrl(ButtonSearchContext $buttonSearchContext = null):
*/
return $this->datagridUrlConverter->convertGridUrlToPageUrl($datagridName, $originalUrl);
}

private function getMasterRequestUri(): ?string
{
$request = $this->requestStack->getMainRequest();

/**
* Based on the "requestStack" contract "MasterRequest" could be "null". it could happens in case
* if this service is called during the console command work.
*
* Example of such case is the building of the MarketingList datasource, where datagrid used as a source of
* the data.
*/
if (!$request) {
return null;
}

return $request->getRequestUri();
}
}
1 change: 0 additions & 1 deletion src/Oro/Bundle/ActionBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ services:
class: 'Oro\Bundle\ActionBundle\Provider\OriginalUrlProvider'
arguments:
- '@request_stack'
- '@router'
- '@oro_datagrid.converter.url_converter'

Oro\Bundle\ActionBundle\Provider\OriginalUrlProvider:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function testGetActionParameters(array $context, array $expected)
public function testGetActionParametersException()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Master Request is not defined');
$this->expectExceptionMessage('The main request is not defined');

$this->helper->getActionParameters([]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ protected function setUp(): void
* @dataProvider getRequestRouteProvider
*/
public function testGetRequestRoute(
?Request $masterRequest,
?Request $mainRequest,
string $executionRoute,
?string $expected
): void {
$this->requestStack->expects($this->once())
->method('getMainRequest')
->willReturn($masterRequest);
->willReturn($mainRequest);

$this->routeProvider->expects($executionRoute ? $this->once() : $this->never())
->method('getExecutionRoute')
Expand All @@ -49,64 +49,52 @@ public function testGetRequestRoute(
public function getRequestRouteProvider(): array
{
return [
'empty master request' => [
'masterRequest' => null,
'empty main request' => [
'mainRequest' => null,
'executionRoute' => '',
'expected' => null,
'expected' => null
],
'empty route name' => [
'masterRequest' => new Request(),
'mainRequest' => new Request(),
'executionRoute' => 'execution_route',
'expected' => null,
'expected' => null
],
'execution route name' => [
'masterRequest' => new Request([
'_route' => 'execution_route',
]),
'mainRequest' => new Request(['_route' => 'execution_route']),
'executionRoute' => 'execution_route',
'expected' => null,
'expected' => null
],
'exists route name' => [
'masterRequest' => new Request([
'_route' => 'test_route',
]),
'mainRequest' => new Request(['_route' => 'test_route']),
'executionRoute' => 'execution_route',
'expected' => 'test_route',
'expected' => 'test_route'
],
'exists route name with datagrid route' => [
'masterRequest' => new Request([
'mainRequest' => new Request([
'_route' => DefaultOperationRequestHelper::DATAGRID_ROUTE,
'gridName' => 'test-grid',
'test-grid' => [
'originalRoute' => 'test_original_route'
]
'test-grid' => ['originalRoute' => 'test_original_route']
]),
'executionRoute' => 'test_route',
'expected' => 'test_original_route',
'expected' => 'test_original_route'
],
'exists route name with mass action route' => [
'masterRequest' => new Request([
'mainRequest' => new Request([
'_route' => DefaultOperationRequestHelper::MASS_ACTION_ROUTE,
'gridName' => 'test-grid',
'test-grid' => [
'originalRoute' => 'test_original_route'
]
'test-grid' => ['originalRoute' => 'test_original_route']
]),
'executionRoute' => 'test_route',
'expected' => 'test_original_route',
'expected' => 'test_original_route'
],
'exists route name with datagrid widget route' => [
'masterRequest' => new Request(
[
'_route' => DefaultOperationRequestHelper::DATAGRID_WIDGET_ROUTE,
'gridName' => 'test-grid',
'test-grid' => [
'originalRoute' => 'test_original_route',
],
]
),
'mainRequest' => new Request([
'_route' => DefaultOperationRequestHelper::DATAGRID_WIDGET_ROUTE,
'gridName' => 'test-grid',
'test-grid' => ['originalRoute' => 'test_original_route']
]),
'executionRoute' => 'test_route',
'expected' => 'test_original_route',
'expected' => 'test_original_route'
],
];
}
Expand All @@ -115,13 +103,13 @@ public function getRequestRouteProvider(): array
* @dataProvider isExecutionRouteRequestProvider
*/
public function isExecutionRouteRequest(
?Request $masterRequest,
?Request $mainRequest,
?string $executionRoute,
?bool $expected
): void {
$this->requestStack->expects($this->once())
->method('getMainRequest')
->willReturn($masterRequest);
->willReturn($mainRequest);

$this->routeProvider->expects($executionRoute ? $this->once() : $this->never())
->method('getExecutionRoute')
Expand All @@ -133,29 +121,25 @@ public function isExecutionRouteRequest(
public function isExecutionRouteRequestProvider(): array
{
return [
'empty master request' => [
'masterRequest' => null,
'empty main request' => [
'mainRequest' => null,
'executionRoute' => null,
'expected' => false,
'expected' => false
],
'empty route name' => [
'masterRequest' => new Request(),
'mainRequest' => new Request(),
'executionRoute' => 'execution_route',
'expected' => false,
'expected' => false
],
'execution route name' => [
'masterRequest' => new Request([
'_route' => 'execution_route',
]),
'mainRequest' => new Request(['_route' => 'execution_route']),
'executionRoute' => 'execution_route',
'expected' => true,
'expected' => true
],
'exists route name' => [
'masterRequest' => new Request([
'_route' => 'test_route',
]),
'mainRequest' => new Request(['_route' => 'test_route']),
'executionRoute' => 'execution_route',
'expected' => false,
'expected' => false
]
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
use Oro\Bundle\DataGridBundle\Converter\UrlConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;

class OriginalUrlProviderTest extends \PHPUnit\Framework\TestCase
{
/** @var RouterInterface|\PHPUnit\Framework\MockObject\MockObject */
private $router;

/** @var RequestStack|\PHPUnit\Framework\MockObject\MockObject */
private $requestStack;

Expand All @@ -26,13 +22,11 @@ class OriginalUrlProviderTest extends \PHPUnit\Framework\TestCase
#[\Override]
protected function setUp(): void
{
$this->router = $this->createMock(RouterInterface::class);
$this->requestStack = $this->createMock(RequestStack::class);
$this->datagridUrlConverter = $this->createMock(UrlConverter::class);

$this->urlProvider = new OriginalUrlProvider(
$this->requestStack,
$this->router,
$this->datagridUrlConverter
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getContext(
$context->getRequestType()->set($this->docViewDetector->getRequestType());
$context->setVersion($this->docViewDetector->getVersion());
$context->setLastGroup(ApiActionGroup::INITIALIZE);
$context->setMasterRequest(true);
$context->setMainRequest(true);
if ($associationName && $context instanceof SubresourceContext) {
$context->setParentClassName($entityClass);
$context->setAssociationName($associationName);
Expand Down
8 changes: 4 additions & 4 deletions src/Oro/Bundle/ApiBundle/Processor/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Context extends NormalizeResultContext implements ContextInterface
/** the response status code */
private const RESPONSE_STATUS_CODE = 'responseStatusCode';

/** indicates whether the current action processes a master API request */
private const MAIN_REQUEST = 'masterRequest';
/** indicates whether the current action processes a main API request */
private const MAIN_REQUEST = 'mainRequest';

/** indicates whether the current request is CORS request */
private const CORS = 'cors';
Expand Down Expand Up @@ -223,9 +223,9 @@ public function isMainRequest(): bool
}

#[\Override]
public function setMasterRequest(bool $master): void
public function setMainRequest(bool $main): void
{
$this->set(self::MAIN_REQUEST, $master);
$this->set(self::MAIN_REQUEST, $main);
}

#[\Override]
Expand Down
6 changes: 3 additions & 3 deletions src/Oro/Bundle/ApiBundle/Processor/ContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ public function getFilterValues(): FilterValueAccessorInterface;
public function setFilterValues(FilterValueAccessorInterface $accessor): void;

/**
* Indicates whether the current action processes a master API request
* Indicates whether the current action processes a main API request
* or it is executed as part of another action.
*/
public function isMainRequest(): bool;

/**
* Sets a flag indicates whether the current action processes a master API request
* Sets a flag indicates whether the current action processes a main API request
* or it is executed as part of another action.
*/
public function setMasterRequest(bool $master): void;
public function setMainRequest(bool $main): void;

/**
* Indicates whether the current request is CORS request.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Oro\Bundle\ApiBundle\Processor\Shared;

use Oro\Component\ChainProcessor\ContextInterface;
use Oro\Component\ChainProcessor\ProcessorInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

/**
* Disables an access to an API resource.
*/
class DisableResourceAccess implements ProcessorInterface
{
public function __construct(
private readonly string $message
) {
}

#[\Override]
public function process(ContextInterface $context): void
{
throw new AccessDeniedException($this->message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ public function process(ContextInterface $context): void
return;
}

if ($context->isMainRequest()) {
$context->addError(
Error::createValidationError(Constraint::VALUE, 'The option is not supported.')
->setSource(ErrorSource::createByPointer('/' . JsonApiDoc::META . '/' . JsonApiDoc::META_UPDATE))
);
}
$context->addError(
Error::createValidationError(Constraint::VALUE, 'The option is not supported.')
->setSource(ErrorSource::createByPointer('/' . JsonApiDoc::META . '/' . JsonApiDoc::META_UPDATE))
);
}
}
2 changes: 1 addition & 1 deletion src/Oro/Bundle/ApiBundle/Request/RequestActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ protected function prepareContext(Context $context, Request $request): void
foreach ($this->requestType as $type) {
$requestType->add($type);
}
$context->setMasterRequest(true);
$context->setMainRequest(true);
$context->setRequestHeaders($this->getRequestHeaders($request));
$context->setHateoas(true);
}
Expand Down
Loading

0 comments on commit 1aff74f

Please sign in to comment.