-
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
Open
barw4
wants to merge
4
commits into
4.6
Choose a base branch
from
ibx-9266-siteaccess-load-for-location-rest-action
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?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\AdminUi\Siteaccess\SiteaccessResolverInterface; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Location; | ||
| use Ibexa\Rest\Server\Controller as RestController; | ||
|
|
||
| final class SiteAccessController extends RestController | ||
| { | ||
| private SiteaccessResolverInterface $nonAdminSiteAccessResolver; | ||
|
|
||
| public function __construct(SiteaccessResolverInterface $nonAdminSiteAccessResolver) | ||
| { | ||
| $this->nonAdminSiteAccessResolver = $nonAdminSiteAccessResolver; | ||
| } | ||
|
|
||
| public function loadNonAdminSiteAccessesForLocation(Location $location): SiteAccessesList | ||
| { | ||
| return new SiteAccessesList( | ||
| $this->nonAdminSiteAccessResolver->getSiteAccessesListForLocation($location) | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/lib/REST/Output/ValueObjectVisitor/SiteAccess/SiteAccessesListVisitor.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?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'); | ||
| $visitor->setHeader('Content-Type', $generator->getMediaType('SiteAccessesList')); | ||
|
|
||
| $generator->startList('values'); | ||
| foreach ($data->getSiteAccesses() as $siteAccess) { | ||
| $generator->startObjectElement('SiteAccess'); | ||
|
|
||
| $generator->startValueElement('name', $siteAccess->name); | ||
| $generator->endValueElement('name'); | ||
|
|
||
| $generator->endObjectElement('SiteAccess'); | ||
| } | ||
| $generator->endList('values'); | ||
|
|
||
| $generator->endObjectElement('SiteAccessesList'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/load-non-admin-for-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/load-non-admin-for-location/2', | ||
| 'SiteAccessesList', | ||
| "application/vnd.ibexa.api.SiteAccessesList+$format", | ||
| ['HTTP_X-SiteAccess' => 'admin'], | ||
| null, | ||
| null, | ||
| 'SiteAccessesList' | ||
| ); | ||
| } | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
tests/integration/Resources/REST/Schemas/SiteAccessesList.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] | ||
| } |
18 changes: 18 additions & 0 deletions
18
tests/integration/Resources/REST/Schemas/SiteAccessesList.xsd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
27 changes: 27 additions & 0 deletions
27
tests/integration/Resources/REST/Snapshots/SiteAccessesList.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| ] | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
tests/integration/Resources/REST/Snapshots/SiteAccessesList.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference here would be
SiteAccessListsimilarly as we refer to it on other places afair and the same as ContentInfoList, LocationList, etc.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that we also use
SiteAccessesListin a lot of places in directly related services, e.g.: https://github.com/ibexa/admin-ui/blob/main/src/lib/Siteaccess/NonAdminSiteaccessResolver.php#L33 (a lot of other places in admin-ui), therefore I wanted to stay consistent with it as I'm directly using this service. But obviously I can change it if you prefer it your way.