-
Notifications
You must be signed in to change notification settings - Fork 18
IBX-9266: Added REST endpoint loading available site accesses for location #1759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.6
Are you sure you want to change the base?
Changes from all commits
4eb1b3e
2448b4d
164b9fd
18e63f6
558b550
480f1d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Bundle\AdminUi\Controller\SiteAccess; | ||
|
|
||
| use Ibexa\AdminUi\REST\Value\SiteAccess\SiteAccessesList; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Location; | ||
| use Ibexa\Rest\Server\Controller as RestController; | ||
| use Ibexa\Rest\Server\Exceptions\BadRequestException; | ||
| use Psr\Container\NotFoundExceptionInterface; | ||
| use Symfony\Component\DependencyInjection\ServiceLocator; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
|
|
||
| final class SiteAccessController extends RestController | ||
| { | ||
| private ServiceLocator $siteAccessResolvers; | ||
|
|
||
| public function __construct( | ||
| ServiceLocator $siteAccessResolvers | ||
| ) { | ||
| $this->siteAccessResolvers = $siteAccessResolvers; | ||
| } | ||
|
|
||
| /** | ||
| * @throws \Psr\Container\ContainerExceptionInterface | ||
| * @throws \Psr\Container\NotFoundExceptionInterface | ||
| */ | ||
| public function loadForLocation(Request $request, Location $location): SiteAccessesList | ||
| { | ||
| $resolverType = $request->query->get('resolver_type', 'non_admin'); | ||
|
|
||
| try { | ||
| /** @var \Ibexa\AdminUi\Siteaccess\SiteaccessResolverInterface $siteAccessResolver */ | ||
| $siteAccessResolver = $this->siteAccessResolvers->get($resolverType); | ||
| } catch (NotFoundExceptionInterface $e) { | ||
| throw new BadRequestException($e->getMessage(), $e->getCode(), $e); | ||
| } | ||
|
|
||
| return new SiteAccessesList($siteAccessResolver->getSiteAccessesListForLocation($location)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\AdminUi\REST\Output\ValueObjectVisitor\SiteAccess; | ||
|
|
||
| use Ibexa\Contracts\Rest\Output\Generator; | ||
| use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; | ||
| use Ibexa\Contracts\Rest\Output\Visitor; | ||
|
|
||
| final class SiteAccessesListVisitor extends ValueObjectVisitor | ||
| { | ||
| /** | ||
| * @param \Ibexa\AdminUi\REST\Value\SiteAccess\SiteAccessesList $data | ||
| */ | ||
| public function visit(Visitor $visitor, Generator $generator, $data): void | ||
| { | ||
| $generator->startObjectElement('SiteAccessesList'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My preference here would be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue is that we also use |
||
| $visitor->setHeader('Content-Type', $generator->getMediaType('SiteAccessesList')); | ||
|
|
||
| $generator->startList('values'); | ||
| foreach ($data->getSiteAccesses() as $siteAccess) { | ||
| $generator->startObjectElement('SiteAccess'); | ||
|
|
||
| $generator->valueElement('name', $siteAccess->name); | ||
|
|
||
| $generator->endObjectElement('SiteAccess'); | ||
| } | ||
| $generator->endList('values'); | ||
|
|
||
| $generator->endObjectElement('SiteAccessesList'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\AdminUi\REST\Value\SiteAccess; | ||
|
|
||
| use Ibexa\Rest\Value as RestValue; | ||
|
|
||
| final class SiteAccessesList extends RestValue | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and the same remark for the object itself as in the previous comment. |
||
| { | ||
| /** @var \Ibexa\Core\MVC\Symfony\SiteAccess[] */ | ||
| private array $siteAccesses; | ||
|
|
||
| /** | ||
| * @param \Ibexa\Core\MVC\Symfony\SiteAccess[] $siteAccesses | ||
| */ | ||
| public function __construct(array $siteAccesses = []) | ||
| { | ||
| $this->siteAccesses = $siteAccesses; | ||
| } | ||
|
|
||
| /** | ||
| * @return \Ibexa\Core\MVC\Symfony\SiteAccess[] | ||
| */ | ||
| public function getSiteAccesses(): array | ||
| { | ||
| return $this->siteAccesses; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Tests\Integration\AdminUi\REST; | ||
|
|
||
| use Ibexa\Contracts\Test\Rest\Request\Value\EndpointRequestDefinition; | ||
|
|
||
| /** | ||
| * Coverage for /site-access/by-location/{locationId} REST endpoint. | ||
| */ | ||
| final class GetSiteAccessesListTest extends BaseAdminUiRestWebTestCase | ||
| { | ||
| /** | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ForbiddenException | ||
| */ | ||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| // to create a new user before logging-in via REST | ||
| $this->getIbexaTestCore()->setAdministratorUser(); | ||
|
|
||
| $this->loginAsUser( | ||
| $this->createUserWithPolicies( | ||
| 'editor', | ||
| [ | ||
| 'user/login' => [], | ||
| 'content/read' => [], | ||
| 'content/versionread' => [], | ||
| ] | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| protected static function getEndpointsToTest(): iterable | ||
| { | ||
| foreach (self::REQUIRED_FORMATS as $format) { | ||
| yield new EndpointRequestDefinition( | ||
| 'GET', | ||
| '/api/ibexa/v2/site-access/by-location/2?resolver_type=non_admin', | ||
| 'SiteAccessesList', | ||
| "application/vnd.ibexa.api.SiteAccessesList+$format", | ||
| ['HTTP_X-SiteAccess' => 'admin'], | ||
| null, | ||
| null, | ||
| 'SiteAccessesList' | ||
| ); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "type": "object", | ||
| "properties": { | ||
| "SiteAccessesList": { | ||
| "type": "object", | ||
| "properties": { | ||
| "_media-type": { | ||
| "type": "string" | ||
| }, | ||
| "values": { | ||
| "type": "array", | ||
| "items": [ | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "_media-type": { | ||
| "type": "string" | ||
| }, | ||
| "name": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "_media-type", | ||
| "name" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "required": [ | ||
| "_media-type", | ||
| "values" | ||
| ] | ||
| } | ||
| }, | ||
| "required": [ | ||
| "SiteAccessesList" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
| <xs:element name="SiteAccessesList"> | ||
| <xs:complexType> | ||
| <xs:sequence> | ||
| <xs:element name="SiteAccess" maxOccurs="unbounded" minOccurs="0"> | ||
| <xs:complexType> | ||
| <xs:sequence> | ||
| <xs:element name="name" type="xs:string" /> | ||
| </xs:sequence> | ||
| <xs:attribute name="media-type" type="xs:string" use="required" /> | ||
| </xs:complexType> | ||
| </xs:element> | ||
| </xs:sequence> | ||
| <xs:attribute name="media-type" type="xs:string" use="required" /> | ||
| </xs:complexType> | ||
| </xs:element> | ||
| </xs:schema> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "SiteAccessesList": { | ||
| "_media-type": "application/vnd.ibexa.api.SiteAccessesList+json", | ||
| "values": [ | ||
| { | ||
| "_media-type": "application/vnd.ibexa.api.SiteAccess+json", | ||
| "name": "__default_site_access__" | ||
| }, | ||
| { | ||
| "_media-type": "application/vnd.ibexa.api.SiteAccess+json", | ||
| "name": "__second_site_access__" | ||
| }, | ||
| { | ||
| "_media-type": "application/vnd.ibexa.api.SiteAccess+json", | ||
| "name": "ger" | ||
| }, | ||
| { | ||
| "_media-type": "application/vnd.ibexa.api.SiteAccess+json", | ||
| "name": "eng" | ||
| }, | ||
| { | ||
| "_media-type": "application/vnd.ibexa.api.SiteAccess+json", | ||
| "name": "ku6\"H" | ||
| } | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <SiteAccessesList media-type="application/vnd.ibexa.api.SiteAccessesList+xml"> | ||
| <SiteAccess media-type="application/vnd.ibexa.api.SiteAccess+xml"> | ||
| <name>__default_site_access__</name> | ||
| </SiteAccess> | ||
| <SiteAccess media-type="application/vnd.ibexa.api.SiteAccess+xml"> | ||
| <name>__second_site_access__</name> | ||
| </SiteAccess> | ||
| <SiteAccess media-type="application/vnd.ibexa.api.SiteAccess+xml"> | ||
| <name>ger</name> | ||
| </SiteAccess> | ||
| <SiteAccess media-type="application/vnd.ibexa.api.SiteAccess+xml"> | ||
| <name>eng</name> | ||
| </SiteAccess> | ||
| <SiteAccess media-type="application/vnd.ibexa.api.SiteAccess+xml"> | ||
| <name>ku6"H</name> | ||
| </SiteAccess> | ||
| </SiteAccessesList> |
Uh oh!
There was an error while loading. Please reload this page.