-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-pcpm-vc4v-cmvx
- Loading branch information
Showing
6 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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
19 changes: 19 additions & 0 deletions
19
src/bundle/Resources/config/services/role_form_mappers.yml
This file contains 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,19 @@ | ||
services: | ||
Ibexa\AdminUi\Limitation\Mapper\MemberOfLimitationMapper: | ||
parent: ezrepoforms.limitation.form_mapper.multiple_selection | ||
arguments: | ||
$userService: '@ezpublish.api.service.user' | ||
$repository: '@ezpublish.api.repository' | ||
$searchService: '@ezpublish.api.service.search' | ||
$translator: '@translator' | ||
tags: | ||
- { name: ez.limitation.formMapper, limitationType: MemberOf } | ||
- { name: ez.limitation.valueMapper, limitationType: MemberOf } | ||
|
||
Ibexa\AdminUi\Limitation\Mapper\RoleLimitationMapper: | ||
parent: ezrepoforms.limitation.form_mapper.multiple_selection | ||
arguments: | ||
$roleService: '@ezpublish.api.service.role' | ||
tags: | ||
- { name: ez.limitation.formMapper, limitationType: Role } | ||
- { name: ez.limitation.valueMapper, limitationType: Role } |
This file contains 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 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,112 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems 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\Limitation\Mapper; | ||
|
||
use eZ\Publish\API\Repository\Repository; | ||
use eZ\Publish\API\Repository\SearchService; | ||
use eZ\Publish\API\Repository\UserService; | ||
use eZ\Publish\API\Repository\Values\Content\Query; | ||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier; | ||
use eZ\Publish\API\Repository\Values\Content\Query\SortClause\ContentName; | ||
use eZ\Publish\API\Repository\Values\User\Limitation; | ||
use EzSystems\RepositoryForms\Limitation\LimitationValueMapperInterface; | ||
use EzSystems\RepositoryForms\Limitation\Mapper\MultipleSelectionBasedMapper; | ||
use Ibexa\Core\Limitation\MemberOfLimitationType; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
final class MemberOfLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface | ||
{ | ||
/** @var \eZ\Publish\API\Repository\UserService */ | ||
private $userService; | ||
|
||
/** @var \eZ\Publish\API\Repository\Repository */ | ||
private $repository; | ||
|
||
/** @var \eZ\Publish\API\Repository\SearchService */ | ||
private $searchService; | ||
|
||
/** @var \Symfony\Component\Translation\TranslatorInterface */ | ||
private $translator; | ||
|
||
public function __construct( | ||
UserService $userService, | ||
Repository $repository, | ||
SearchService $searchService, | ||
TranslatorInterface $translator | ||
) { | ||
$this->userService = $userService; | ||
$this->repository = $repository; | ||
$this->searchService = $searchService; | ||
$this->translator = $translator; | ||
} | ||
|
||
protected function getSelectionChoices(): array | ||
{ | ||
$userGroups = $this->loadUserGroups(); | ||
$choices = []; | ||
$choices[MemberOfLimitationType::SELF_USER_GROUP] = $this->getSelfUserGroupLabel(); | ||
|
||
foreach ($userGroups as $userGroup) { | ||
$choices[$userGroup->id] = $userGroup->getName(); | ||
} | ||
|
||
return $choices; | ||
} | ||
|
||
public function mapLimitationValue(Limitation $limitation): array | ||
{ | ||
$values = []; | ||
foreach ($limitation->limitationValues as $groupId) { | ||
if ($groupId === MemberOfLimitationType::SELF_USER_GROUP) { | ||
$values[] = $this->getSelfUserGroupLabel(); | ||
continue; | ||
} | ||
$values[] = $this->userService->loadUserGroup($groupId)->getName(); | ||
} | ||
|
||
return $values; | ||
} | ||
|
||
/** | ||
* @return \eZ\Publish\API\Repository\Values\User\UserGroup[] | ||
*/ | ||
private function loadUserGroups(): array | ||
{ | ||
return $this->repository->sudo(function () { | ||
$query = new Query(); | ||
$query->filter = new ContentTypeIdentifier('user_group'); | ||
$query->offset = 0; | ||
$query->limit = 100; | ||
$query->performCount = true; | ||
$query->sortClauses[] = new ContentName(); | ||
|
||
$groups = []; | ||
do { | ||
$results = $this->searchService->findContent($query); | ||
foreach ($results->searchHits as $hit) { | ||
$groups[] = $this->userService->loadUserGroup($hit->valueObject->id); | ||
} | ||
|
||
$query->offset += $query->limit; | ||
} while ($query->offset < $results->totalCount); | ||
|
||
return $groups; | ||
}); | ||
} | ||
|
||
private function getSelfUserGroupLabel(): string | ||
{ | ||
return $this->translator->trans( | ||
/** @Desc("Self") */ | ||
'policy.limitation.member_of.self_user_group', | ||
[], | ||
'ezrepoforms_role' | ||
); | ||
} | ||
} |
This file contains 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,47 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems 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\Limitation\Mapper; | ||
|
||
use eZ\Publish\API\Repository\RoleService; | ||
use eZ\Publish\API\Repository\Values\User\Limitation; | ||
use EzSystems\RepositoryForms\Limitation\LimitationValueMapperInterface; | ||
use EzSystems\RepositoryForms\Limitation\Mapper\MultipleSelectionBasedMapper; | ||
|
||
final class RoleLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface | ||
{ | ||
/** @var \eZ\Publish\API\Repository\RoleService */ | ||
private $roleService; | ||
|
||
public function __construct( | ||
RoleService $roleService | ||
) { | ||
$this->roleService = $roleService; | ||
} | ||
|
||
protected function getSelectionChoices(): array | ||
{ | ||
$choices = []; | ||
foreach ($this->roleService->loadRoles() as $role) { | ||
$choices[$role->id] = $role->identifier; | ||
} | ||
|
||
return $choices; | ||
} | ||
|
||
public function mapLimitationValue(Limitation $limitation): array | ||
{ | ||
$values = []; | ||
|
||
foreach ($limitation->limitationValues as $roleId) { | ||
$values[] = $this->roleService->loadRole((int)$roleId)->identifier; | ||
} | ||
|
||
return $values; | ||
} | ||
} |