Skip to content

Commit ae2781e

Browse files
committed
Merged branch 4.6
2 parents 2116844 + 8615d63 commit ae2781e

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

src/bundle/Resources/config/routing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ ibexa.rest.load_root_user_group:
10341034

10351035
ibexa.rest.create_root_user_group:
10361036
path: /user/groups/subgroups
1037-
controller: Ibexa\Rest\Server\Controller\User\UserGroupCreateController::createUserGroup
1037+
controller: Ibexa\Rest\Server\Controller\User\UserGroupCreateController::createRootUserGroup
10381038
methods: [POST]
10391039

10401040
ibexa.rest.load_user_group:

src/lib/Server/Controller/User/UserBaseController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Ibexa\Contracts\Core\Repository\Values\Content\Language;
2121
use Ibexa\Contracts\Core\Repository\Values\User\User as RepositoryUser;
2222
use Ibexa\Contracts\Core\Repository\Values\User\UserRoleAssignment;
23+
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
2324
use Ibexa\Contracts\Rest\Exceptions\NotFoundException;
2425
use Ibexa\Rest\Server\Controller as RestController;
2526
use Ibexa\Rest\Server\Values;
@@ -46,6 +47,8 @@ class UserBaseController extends RestController
4647

4748
protected ContentService\RelationListFacadeInterface $relationListFacade;
4849

50+
protected ConfigResolverInterface $configResolver;
51+
4952
public function __construct(
5053
UserService $userService,
5154
RoleService $roleService,
@@ -55,7 +58,8 @@ public function __construct(
5558
SectionService $sectionService,
5659
Repository $repository,
5760
PermissionResolver $permissionResolver,
58-
ContentService\RelationListFacadeInterface $relationListFacade
61+
ContentService\RelationListFacadeInterface $relationListFacade,
62+
ConfigResolverInterface $configResolver
5963
) {
6064
$this->userService = $userService;
6165
$this->roleService = $roleService;
@@ -66,6 +70,7 @@ public function __construct(
6670
$this->repository = $repository;
6771
$this->permissionResolver = $permissionResolver;
6872
$this->relationListFacade = $relationListFacade;
73+
$this->configResolver = $configResolver;
6974
}
7075

7176
/**

src/lib/Server/Controller/User/UserGroupCreateController.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,20 @@ public function createUserGroup(string $groupPath, Request $request): Values\Cre
219219
]
220220
);
221221
}
222+
223+
/**
224+
* Create a new user group under the root location.
225+
*
226+
* @throws \Ibexa\Contracts\Rest\Exceptions\NotFoundException
227+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
228+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException
229+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException
230+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
231+
*/
232+
public function createRootUserGroup(Request $request): Values\CreatedUserGroup
233+
{
234+
$rootPath = $this->configResolver->getParameter('users_group_root_subtree_path');
235+
236+
return $this->createUserGroup($rootPath, $request);
237+
}
222238
}

tests/bundle/Functional/UserTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,51 @@ public function testCreateUserGroup(): string
7272
return $href;
7373
}
7474

75+
/**
76+
* Covers POST /user/groups/subgroups (user group creation under root subtree).
77+
*/
78+
public function testCreateRootUserGroup(): void
79+
{
80+
$text = $this->addTestSuffix(__FUNCTION__);
81+
$xml = <<< XML
82+
<?xml version="1.0" encoding="UTF-8"?>
83+
<UserGroupCreate>
84+
<mainLanguageCode>eng-GB</mainLanguageCode>
85+
<remoteId>{$text}</remoteId>
86+
<fields>
87+
<field>
88+
<fieldDefinitionIdentifier>name</fieldDefinitionIdentifier>
89+
<languageCode>eng-GB</languageCode>
90+
<fieldValue>{$text}</fieldValue>
91+
</field>
92+
<field>
93+
<fieldDefinitionIdentifier>description</fieldDefinitionIdentifier>
94+
<languageCode>eng-GB</languageCode>
95+
<fieldValue>Description of {$text}</fieldValue>
96+
</field>
97+
</fields>
98+
</UserGroupCreate>
99+
XML;
100+
$request = $this->createHttpRequest(
101+
'POST',
102+
'/api/ibexa/v2/user/groups/subgroups',
103+
'UserGroupCreate+xml',
104+
'UserGroup+json',
105+
$xml
106+
);
107+
$response = $this->sendHttpRequest($request);
108+
109+
self::assertHttpResponseCodeEquals($response, 201);
110+
self::assertHttpResponseHasHeader($response, self::HEADER_LOCATION);
111+
112+
$href = $response->getHeader(self::HEADER_LOCATION)[0];
113+
114+
$trimmedHref = str_replace('/api/ibexa/v2/user/groups/', '', $href);
115+
$parts = explode('/', $trimmedHref);
116+
117+
self::assertSame('1/5', $parts[0] . '/' . $parts[1]);
118+
}
119+
75120
/**
76121
* Covers GET /user/groups/{groupId}.
77122
*

0 commit comments

Comments
 (0)