Skip to content

Commit 0c4b216

Browse files
authored
Revert "IBX-8180: OpenAPI compatible location swap endpoint (#107)"
This reverts commit 3f1fbf6.
1 parent 3f1fbf6 commit 0c4b216

File tree

16 files changed

+139
-392
lines changed

16 files changed

+139
-392
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
"symfony/routing": "^5.3",
4242
"symfony/security-bundle": "^5.3",
4343
"symfony/security-csrf": "^5.3",
44-
"symfony/yaml": "^5.3",
45-
"webmozart/assert": "^1.11"
44+
"symfony/yaml": "^5.3"
4645
},
4746
"require-dev": {
4847
"ibexa/ci-scripts": "^0.2@dev",

src/bundle/Resources/config/input_parsers.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -866,11 +866,3 @@ services:
866866
$validator: '@validator'
867867
tags:
868868
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.MoveLocationInput }
869-
870-
Ibexa\Rest\Server\Input\Parser\SwapLocationInput:
871-
parent: Ibexa\Rest\Server\Common\Parser
872-
arguments:
873-
$locationService: '@ibexa.api.service.location'
874-
$validator: '@validator'
875-
tags:
876-
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.SwapLocationInput }

src/bundle/Resources/config/routing.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,8 @@ ibexa.rest.languages.view:
432432

433433
# Locations
434434

435-
ibexa.rest.location.swap:
436-
path: /content/locations/{locationPath}
437-
controller: Ibexa\Rest\Server\Controller\Location::swap
438-
condition: 'ibexa_get_media_type(request) === "SwapLocationInput"'
439-
methods: [POST]
440-
options:
441-
options_route_suffix: 'SwapLocationInput'
442-
requirements:
443-
locationPath: "[0-9/]+"
444435

445-
ibexa.rest.location.move:
436+
ibexa.rest.move_location:
446437
path: /content/locations/{locationPath}
447438
controller: Ibexa\Rest\Server\Controller\Location::moveLocation
448439
condition: 'ibexa_get_media_type(request) === "MoveLocationInput"'

src/lib/Server/Controller/Location.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -338,27 +338,6 @@ public function swapLocation($locationPath, Request $request)
338338
return new Values\NoContent();
339339
}
340340

341-
/**
342-
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
343-
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
344-
*/
345-
public function swap(Request $request, string $locationPath): Values\NoContent
346-
{
347-
$locationId = $this->extractLocationIdFromPath($locationPath);
348-
$location = $this->locationService->loadLocation($locationId);
349-
350-
$destinationLocation = $this->inputDispatcher->parse(
351-
new Message(
352-
['Content-Type' => $request->headers->get('Content-Type')],
353-
$request->getContent(),
354-
),
355-
);
356-
357-
$this->locationService->swapLocation($location, $destinationLocation);
358-
359-
return new Values\NoContent();
360-
}
361-
362341
/**
363342
* Loads a location by remote ID.
364343
*

src/lib/Server/Input/Parser/AbstractDestinationLocationParser.php

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/lib/Server/Input/Parser/MoveLocation.php

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,77 @@
88

99
namespace Ibexa\Rest\Server\Input\Parser;
1010

11-
use Ibexa\Rest\Server\Validation\Builder\Input\Parser\BaseInputParserValidatorBuilder;
11+
use Ibexa\Contracts\Core\Repository\LocationService;
12+
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
13+
use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
14+
use Ibexa\Rest\Input\BaseParser;
15+
use Ibexa\Rest\Server\Exceptions\ValidationFailedException;
1216
use Ibexa\Rest\Server\Validation\Builder\Input\Parser\MoveLocationInputValidatorBuilder;
17+
use Symfony\Component\Validator\Validator\ValidatorInterface;
1318

14-
final class MoveLocation extends AbstractDestinationLocationParser
19+
final class MoveLocation extends BaseParser
1520
{
16-
protected const string PARSER = 'MoveLocation';
21+
public const string DESTINATION_KEY = 'destination';
1722

18-
protected function getValidatorBuilder(): BaseInputParserValidatorBuilder
23+
public function __construct(
24+
private readonly LocationService $locationService,
25+
private readonly ValidatorInterface $validator,
26+
) {
27+
}
28+
29+
/**
30+
* @phpstan-param array{
31+
* 'destination': string,
32+
* } $data
33+
*
34+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
35+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
36+
* @throws \Ibexa\Contracts\Rest\Exceptions\Parser
37+
*/
38+
public function parse(array $data, ParsingDispatcher $parsingDispatcher): Location
39+
{
40+
$this->validateInputData($data);
41+
42+
return $this->getLocationByPath($data[self::DESTINATION_KEY]);
43+
}
44+
45+
/**
46+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
47+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
48+
*/
49+
private function getLocationByPath(string $path): Location
50+
{
51+
return $this->locationService->loadLocation(
52+
$this->extractLocationIdFromPath($path)
53+
);
54+
}
55+
56+
private function extractLocationIdFromPath(string $path): int
57+
{
58+
$pathParts = explode('/', $path);
59+
60+
return (int)array_pop($pathParts);
61+
}
62+
63+
/**
64+
* @phpstan-assert array{
65+
* 'destination': string,
66+
* } $data
67+
*
68+
* @param array<mixed> $data
69+
*
70+
* @throws \Ibexa\Rest\Server\Exceptions\ValidationFailedException
71+
*/
72+
private function validateInputData(array $data): void
1973
{
20-
return new MoveLocationInputValidatorBuilder($this->validator);
74+
$builder = new MoveLocationInputValidatorBuilder($this->validator);
75+
$builder->validateInputArray($data);
76+
$violations = $builder->build()->getViolations();
77+
if ($violations->count() > 0) {
78+
throw new ValidationFailedException(
79+
'MoveLocation',
80+
$violations,
81+
);
82+
}
2183
}
2284
}

src/lib/Server/Input/Parser/SwapLocationInput.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/lib/Server/Validation/Builder/Input/Parser/SwapLocationInputValidatorBuilder.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/bundle/Functional/HttpOptionsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function providerForTestHttpOptions(): array
8181
['/content/objects/1/objectstates', ['GET', 'PATCH']],
8282
['/content/locations', ['GET']],
8383
['/content/locations/1/2', ['POST'], 'MoveLocationInput+json'],
84-
['/content/locations/1/2', ['POST'], 'SwapLocationInput+json'],
8584
['/content/locations/1/2', ['GET', 'PATCH', 'DELETE', 'COPY', 'MOVE', 'SWAP']],
8685
['/content/locations/1/2/children', ['GET']],
8786
['/content/objects/1/locations', ['GET', 'POST']],

tests/bundle/Functional/LocationTest.php

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private function createUrlAlias(string $locationHref, string $urlAlias): string
268268
/**
269269
* @depends testMoveSubtree
270270
*/
271-
public function testMoveLocation(string $locationHref): string
271+
public function testMoveLocation(string $locationHref): void
272272
{
273273
$request = $this->createHttpRequest(
274274
'POST',
@@ -282,55 +282,5 @@ public function testMoveLocation(string $locationHref): string
282282

283283
self::assertHttpResponseCodeEquals($response, 201);
284284
self::assertHttpResponseHasHeader($response, 'Location');
285-
286-
return $locationHref;
287-
}
288-
289-
/**
290-
* @depends testMoveLocation
291-
*/
292-
public function testSwap(string $locationHref): void
293-
{
294-
$request = $this->createHttpRequest(
295-
'COPY',
296-
$locationHref,
297-
'',
298-
'',
299-
'',
300-
['Destination' => '/api/ibexa/v2/content/locations/1/43']
301-
);
302-
$response = $this->sendHttpRequest($request);
303-
$newCopiedLocation = $response->getHeader('Location')[0];
304-
305-
$request = $this->createHttpRequest(
306-
'COPY',
307-
$locationHref,
308-
'',
309-
'',
310-
'',
311-
['Destination' => '/api/ibexa/v2/content/locations/1/43']
312-
);
313-
$response = $this->sendHttpRequest($request);
314-
$secondCopiedLocation = $response->getHeader('Location')[0];
315-
316-
$request = $this->createHttpRequest(
317-
'POST',
318-
$newCopiedLocation,
319-
'SwapLocationInput+json',
320-
'',
321-
json_encode([
322-
'SwapLocationInput' => [
323-
'destination' => str_replace(
324-
'/api/ibexa/v2/content/locations',
325-
'',
326-
$secondCopiedLocation,
327-
),
328-
],
329-
], JSON_THROW_ON_ERROR),
330-
);
331-
332-
$response = $this->sendHttpRequest($request);
333-
334-
self::assertHttpResponseCodeEquals($response, 204);
335285
}
336286
}

0 commit comments

Comments
 (0)