Skip to content

Commit 29e156a

Browse files
authored
Merge pull request from GHSA-pcpm-vc4v-cmvx
1 parent 390997c commit 29e156a

7 files changed

Lines changed: 199 additions & 0 deletions

File tree

src/bundle/Resources/config/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ imports:
3030
- { resource: services/events.yaml }
3131
- { resource: services/twig.yaml }
3232
- { resource: services/autosave.yaml }
33+
- { resource: services/role_form_mappers.yaml }
3334

3435
services:
3536
_defaults:

src/bundle/Resources/config/services/role_form_mappers.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,22 @@ services:
223223
tags:
224224
- { name: ez.limitation.formMapper, limitationType: Subtree }
225225
- { name: ez.limitation.valueMapper, limitationType: Subtree }
226+
227+
Ibexa\AdminUi\Limitation\Mapper\MemberOfLimitationMapper:
228+
parent: ezplatform.content_forms.limitation.form_mapper.multiple_selection
229+
arguments:
230+
$userService: '@ezpublish.api.service.user'
231+
$repository: '@ezpublish.api.repository'
232+
$contentService: '@ezpublish.api.service.content'
233+
$translator: '@translator'
234+
tags:
235+
- { name: ez.limitation.formMapper, limitationType: MemberOf }
236+
- { name: ez.limitation.valueMapper, limitationType: MemberOf }
237+
238+
Ibexa\AdminUi\Limitation\Mapper\RoleLimitationMapper:
239+
parent: ezplatform.content_forms.limitation.form_mapper.multiple_selection
240+
arguments:
241+
$roleService: '@ezpublish.api.service.role'
242+
tags:
243+
- { name: ez.limitation.formMapper, limitationType: Role }
244+
- { name: ez.limitation.valueMapper, limitationType: Role }

src/bundle/Resources/translations/ezplatform_content_forms_policies.en.xliff

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
<target>Language</target>
2727
<note>key: policy.limitation.identifier.language</note>
2828
</trans-unit>
29+
<trans-unit id="b40e3e09e55ef852a5d9e1592e9c895715b1313c" resname="policy.limitation.identifier.memberof">
30+
<source>MemberOf</source>
31+
<target>MemberOf</target>
32+
<note>key: policy.limitation.identifier.memberof</note>
33+
</trans-unit>
2934
<trans-unit id="ab9163a435d32610a7a1af8df07ab38eebc4c7c6" resname="policy.limitation.identifier.newsection">
3035
<source>New Section</source>
3136
<target>New Section</target>
@@ -71,6 +76,11 @@
7176
<target>PersonalizationAccess</target>
7277
<note>key: policy.limitation.identifier.personalizationaccess</note>
7378
</trans-unit>
79+
<trans-unit id="9f2e53e094725bbc243ad777547724ab923a31d1" resname="policy.limitation.identifier.role">
80+
<source>Role</source>
81+
<target>Role</target>
82+
<note>key: policy.limitation.identifier.role</note>
83+
</trans-unit>
7484
<trans-unit id="bb77b27363dad566197a200290f0f0b18baa4705" resname="policy.limitation.identifier.section">
7585
<source>Section</source>
7686
<target>Section</target>

src/bundle/Resources/translations/ezplatform_content_forms_role.en.xliff

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
<target state="new">Self</target>
1212
<note>key: policy.limitation.group.self</note>
1313
</trans-unit>
14+
<trans-unit id="e797dbd775ecc5788f41ceeb960b70a9d7a116ca" resname="policy.limitation.member_of.self_user_group">
15+
<source>Self</source>
16+
<target state="new">Self</target>
17+
<note>key: policy.limitation.member_of.self_user_group</note>
18+
</trans-unit>
1419
<trans-unit id="cc7c597ffa43ef724b881b127a4124fd35c8c6f6" resname="policy.limitation.owner.self">
1520
<source>Self</source>
1621
<target state="new">Self</target>

src/bundle/Resources/views/themes/admin/limitation/limitation_values.html.twig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,15 @@
116116
{{ values|join(', ') }}
117117
{% endapply %}
118118
{% endblock %}
119+
120+
{% block ez_limitation_memberof_value %}
121+
{% apply spaceless %}
122+
{{ values|join(', ') }}
123+
{% endapply %}
124+
{% endblock %}
125+
126+
{% block ez_limitation_role_value %}
127+
{% apply spaceless %}
128+
{{ values|join(', ') }}
129+
{% endapply %}
130+
{% endblock %}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\AdminUi\Limitation\Mapper;
10+
11+
use eZ\Publish\API\Repository\ContentService;
12+
use eZ\Publish\API\Repository\Repository;
13+
use eZ\Publish\API\Repository\UserService;
14+
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier;
15+
use eZ\Publish\API\Repository\Values\Content\Query\SortClause\ContentName;
16+
use eZ\Publish\API\Repository\Values\Filter\Filter;
17+
use eZ\Publish\API\Repository\Values\User\Limitation;
18+
use EzSystems\EzPlatformAdminUi\Limitation\LimitationValueMapperInterface;
19+
use EzSystems\EzPlatformAdminUi\Limitation\Mapper\MultipleSelectionBasedMapper;
20+
use Ibexa\Core\Limitation\MemberOfLimitationType;
21+
use Symfony\Contracts\Translation\TranslatorInterface;
22+
23+
final class MemberOfLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface
24+
{
25+
/** @var \eZ\Publish\API\Repository\UserService */
26+
private $userService;
27+
28+
/** @var \eZ\Publish\API\Repository\Repository */
29+
private $repository;
30+
31+
/** @var \eZ\Publish\API\Repository\ContentService */
32+
private $contentService;
33+
34+
/** @var \Symfony\Contracts\Translation\TranslatorInterface */
35+
private $translator;
36+
37+
public function __construct(
38+
UserService $userService,
39+
Repository $repository,
40+
ContentService $contentService,
41+
TranslatorInterface $translator
42+
) {
43+
$this->userService = $userService;
44+
$this->repository = $repository;
45+
$this->contentService = $contentService;
46+
$this->translator = $translator;
47+
}
48+
49+
protected function getSelectionChoices(): array
50+
{
51+
$userGroups = $this->loadUserGroups();
52+
$choices = [];
53+
$choices[MemberOfLimitationType::SELF_USER_GROUP] = $this->getSelfUserGroupLabel();
54+
55+
foreach ($userGroups as $userGroup) {
56+
$choices[$userGroup->id] = $userGroup->getName();
57+
}
58+
59+
return $choices;
60+
}
61+
62+
public function mapLimitationValue(Limitation $limitation): array
63+
{
64+
$values = [];
65+
foreach ($limitation->limitationValues as $groupId) {
66+
if ((int)$groupId === MemberOfLimitationType::SELF_USER_GROUP) {
67+
$values[] = $this->getSelfUserGroupLabel();
68+
continue;
69+
}
70+
$values[] = $this->userService->loadUserGroup((int)$groupId)->getName();
71+
}
72+
73+
return $values;
74+
}
75+
76+
/**
77+
* @return \eZ\Publish\API\Repository\Values\User\UserGroup[]
78+
*/
79+
private function loadUserGroups(): array
80+
{
81+
return $this->repository->sudo(function () {
82+
$filter = new Filter();
83+
$filter->withCriterion(new ContentTypeIdentifier('user_group'));
84+
$filter->withSortClause(new ContentName());
85+
$results = $this->contentService->find($filter);
86+
87+
$groups = [];
88+
foreach ($results as $result) {
89+
$groups[] = $this->userService->loadUserGroup($result->id);
90+
}
91+
92+
return $groups;
93+
});
94+
}
95+
96+
private function getSelfUserGroupLabel(): string
97+
{
98+
return $this->translator->trans(
99+
/** @Desc("Self") */
100+
'policy.limitation.member_of.self_user_group',
101+
[],
102+
'ezplatform_content_forms_role'
103+
);
104+
}
105+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\AdminUi\Limitation\Mapper;
10+
11+
use eZ\Publish\API\Repository\RoleService;
12+
use eZ\Publish\API\Repository\Values\User\Limitation;
13+
use EzSystems\EzPlatformAdminUi\Limitation\LimitationValueMapperInterface;
14+
use EzSystems\EzPlatformAdminUi\Limitation\Mapper\MultipleSelectionBasedMapper;
15+
16+
final class RoleLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface
17+
{
18+
/** @var \eZ\Publish\API\Repository\RoleService */
19+
private $roleService;
20+
21+
public function __construct(
22+
RoleService $roleService
23+
) {
24+
$this->roleService = $roleService;
25+
}
26+
27+
protected function getSelectionChoices(): array
28+
{
29+
$choices = [];
30+
foreach ($this->roleService->loadRoles() as $role) {
31+
$choices[$role->id] = $role->identifier;
32+
}
33+
34+
return $choices;
35+
}
36+
37+
public function mapLimitationValue(Limitation $limitation): array
38+
{
39+
$values = [];
40+
41+
foreach ($limitation->limitationValues as $roleId) {
42+
$values[] = $this->roleService->loadRole((int)$roleId)->identifier;
43+
}
44+
45+
return $values;
46+
}
47+
}

0 commit comments

Comments
 (0)