-
Notifications
You must be signed in to change notification settings - Fork 16
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-g6jc-xrc3-4wwq
IBX-3821: Added new Role and MemberOf limitations
- Loading branch information
Showing
8 changed files
with
194 additions
and
7 deletions.
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
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
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,100 @@ | ||
<?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\Limitation\Mapper; | ||
|
||
use Ibexa\AdminUi\Limitation\LimitationValueMapperInterface; | ||
use Ibexa\Contracts\Core\Repository\ContentService; | ||
use Ibexa\Contracts\Core\Repository\Repository; | ||
use Ibexa\Contracts\Core\Repository\UserService; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause\ContentName; | ||
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter; | ||
use Ibexa\Contracts\Core\Repository\Values\User\Limitation; | ||
use Ibexa\Core\Limitation\MemberOfLimitationType; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
final class MemberOfLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface | ||
{ | ||
private UserService $userService; | ||
|
||
private Repository $repository; | ||
|
||
private ContentService $contentService; | ||
|
||
private TranslatorInterface $translator; | ||
|
||
public function __construct( | ||
UserService $userService, | ||
Repository $repository, | ||
ContentService $contentService, | ||
TranslatorInterface $translator | ||
) { | ||
$this->userService = $userService; | ||
$this->repository = $repository; | ||
$this->contentService = $contentService; | ||
$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 ((int)$groupId === MemberOfLimitationType::SELF_USER_GROUP) { | ||
$values[] = $this->getSelfUserGroupLabel(); | ||
continue; | ||
} | ||
$values[] = $this->userService->loadUserGroup((int)$groupId)->getName(); | ||
} | ||
|
||
return $values; | ||
} | ||
|
||
/** | ||
* @return \Ibexa\Contracts\Core\Repository\Values\User\UserGroup[] | ||
*/ | ||
private function loadUserGroups(): array | ||
{ | ||
return $this->repository->sudo(function () { | ||
$filter = new Filter(); | ||
$filter->withCriterion(new ContentTypeIdentifier('user_group')); | ||
$filter->withSortClause(new ContentName()); | ||
$results = $this->contentService->find($filter); | ||
|
||
$groups = []; | ||
foreach ($results as $result) { | ||
$groups[] = $this->userService->loadUserGroup($result->id); | ||
} | ||
|
||
return $groups; | ||
}); | ||
} | ||
|
||
private function getSelfUserGroupLabel(): string | ||
{ | ||
return $this->translator->trans( | ||
/** @Desc("Self") */ | ||
'policy.limitation.member_of.self_user_group', | ||
[], | ||
'ezplatform_content_forms_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,45 @@ | ||
<?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\Limitation\Mapper; | ||
|
||
use Ibexa\AdminUi\Limitation\LimitationValueMapperInterface; | ||
use Ibexa\Contracts\Core\Repository\RoleService; | ||
use Ibexa\Contracts\Core\Repository\Values\User\Limitation; | ||
|
||
final class RoleLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface | ||
{ | ||
private RoleService $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; | ||
} | ||
} |
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