1919use Ibexa \Contracts \Core \Repository \Values \User \User as RepositoryUser ;
2020use Ibexa \Contracts \Core \Repository \Values \User \UserGroupRoleAssignment ;
2121use Ibexa \Contracts \Core \Repository \Values \User \UserRoleAssignment ;
22+ use Ibexa \Contracts \Core \SiteAccess \ConfigResolverInterface ;
2223use Ibexa \Contracts \Rest \Exceptions \NotFoundException ;
2324use Ibexa \Core \Base \Exceptions \UnauthorizedException ;
2425use Ibexa \Rest \Message ;
@@ -103,6 +104,8 @@ class User extends RestController
103104 /** @var \Ibexa\Contracts\Core\Repository\PermissionResolver */
104105 private $ permissionResolver ;
105106
107+ private ConfigResolverInterface $ configResolver ;
108+
106109 public function __construct (
107110 UserService $ userService ,
108111 RoleService $ roleService ,
@@ -111,7 +114,8 @@ public function __construct(
111114 LocationService $ locationService ,
112115 SectionService $ sectionService ,
113116 Repository $ repository ,
114- PermissionResolver $ permissionResolver
117+ PermissionResolver $ permissionResolver ,
118+ ConfigResolverInterface $ configResolver
115119 ) {
116120 $ this ->userService = $ userService ;
117121 $ this ->roleService = $ roleService ;
@@ -121,6 +125,7 @@ public function __construct(
121125 $ this ->sectionService = $ sectionService ;
122126 $ this ->repository = $ repository ;
123127 $ this ->permissionResolver = $ permissionResolver ;
128+ $ this ->configResolver = $ configResolver ;
124129 }
125130
126131 /**
@@ -234,20 +239,38 @@ public function redirectToCurrentUser(?UserInterface $user): Values\TemporaryRed
234239 );
235240 }
236241
242+ /**
243+ * Create a new user group under the root location.
244+ *
245+ * @throws \Ibexa\Contracts\Rest\Exceptions\NotFoundException
246+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
247+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException
248+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException
249+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
250+ */
251+ public function createRootUserGroup (Request $ request ): Values \CreatedUserGroup
252+ {
253+ $ rootPath = $ this ->configResolver ->getParameter ('users_group_root_subtree_path ' );
254+
255+ return $ this ->createUserGroup ($ rootPath , $ request );
256+ }
257+
237258 /**
238259 * Create a new user group under the given parent
239260 * To create a top level group use /user/groups/1/5/subgroups.
240261 *
241- * @param $groupPath
262+ * @param string $groupPath
242263 *
243- * @throws \Ibexa\Rest\Server\Exceptions\BadRequestException
244- *
245- * @return \Ibexa\Rest\Server\Values\CreatedUserGroup
264+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException
265+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException
266+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
267+ * @throws \Ibexa\Contracts\Rest\Exceptions\NotFoundException
268+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
246269 */
247- public function createUserGroup ($ groupPath , Request $ request )
270+ public function createUserGroup ($ groupPath , Request $ request ): Values \ CreatedUserGroup
248271 {
249272 $ userGroupLocation = $ this ->locationService ->loadLocation (
250- $ this ->extractLocationIdFromPath ($ groupPath )
273+ ( int ) $ this ->extractLocationIdFromPath ($ groupPath )
251274 );
252275
253276 $ createdUserGroup = $ this ->userService ->createUserGroup (
0 commit comments