Skip to content

Commit da90d00

Browse files
authored
IBX-1310: Created slots for assigning/unassigning user to groups (#3125)
1 parent 17a60f8 commit da90d00

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

eZ/Publish/API/Repository/Tests/UserServiceTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,39 @@ public function testAssignUserToUserGroup()
21012101
);
21022102
}
21032103

2104+
/**
2105+
* @covers \eZ\Publish\API\Repository\UserService::assignUserToUserGroup
2106+
*/
2107+
public function testAssignUserToGroupWithLocationsValidation(): void
2108+
{
2109+
$repository = $this->getRepository();
2110+
$userService = $repository->getUserService();
2111+
$locationService = $repository->getLocationService();
2112+
2113+
$administratorGroupId = $this->generateId('group', 12);
2114+
2115+
$user = $this->createUserVersion1();
2116+
2117+
$group = $userService->loadUserGroup($administratorGroupId);
2118+
$groupLocation = $locationService->loadLocation($group->contentInfo->mainLocationId);
2119+
2120+
// Count number of child locations before assigning user to group
2121+
$count = $locationService->getLocationChildCount($groupLocation);
2122+
$expectedCount = $count + 1;
2123+
2124+
$userService->assignUserToUserGroup(
2125+
$user,
2126+
$group
2127+
);
2128+
2129+
$this->refreshSearch($repository);
2130+
2131+
// Count number of child locations after assigning user to group
2132+
$actualCount = $locationService->getLocationChildCount($groupLocation);
2133+
2134+
self::assertEquals($expectedCount, $actualCount);
2135+
}
2136+
21042137
/**
21052138
* Test for the assignUserToUserGroup() method.
21062139
*
@@ -2224,6 +2257,48 @@ public function testUnAssignUserFromUserGroupThrowsBadStateArgumentException()
22242257
/* END: Use Case */
22252258
}
22262259

2260+
/**
2261+
* @covers \eZ\Publish\API\Repository\UserService::unAssignUserFromUserGroup
2262+
*/
2263+
public function testUnAssignUserToGroupWithLocationValidation(): void
2264+
{
2265+
$repository = $this->getRepository();
2266+
$userService = $repository->getUserService();
2267+
$locationService = $repository->getLocationService();
2268+
2269+
$editorsGroupId = $this->generateId('group', 13);
2270+
$anonymousGroupId = $this->generateId('group', 42);
2271+
2272+
$user = $this->createUserVersion1();
2273+
2274+
$this->refreshSearch($repository);
2275+
2276+
$group = $userService->loadUserGroup($editorsGroupId);
2277+
$groupLocation = $locationService->loadLocation($group->contentInfo->mainLocationId);
2278+
2279+
// Count number of child locations before unassigning user from group
2280+
$count = $locationService->getLocationChildCount($groupLocation);
2281+
$expectedCount = $count - 1;
2282+
2283+
// Assigning user to different group to avoid removing all groups from user
2284+
$userService->assignUserToUserGroup(
2285+
$user,
2286+
$userService->loadUserGroup($anonymousGroupId)
2287+
);
2288+
2289+
$userService->unAssignUserFromUserGroup(
2290+
$user,
2291+
$userService->loadUserGroup($editorsGroupId)
2292+
);
2293+
2294+
$this->refreshSearch($repository);
2295+
2296+
// Count number of child locations after unassigning user from group
2297+
$actualCount = $locationService->getLocationChildCount($groupLocation);
2298+
2299+
self::assertEquals($expectedCount, $actualCount);
2300+
}
2301+
22272302
/**
22282303
* Test that multi-language logic for the loadUserGroup method respects prioritized language list.
22292304
*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
namespace eZ\Publish\Core\Search\Common\Slot;
8+
9+
use eZ\Publish\Core\SignalSlot\Signal;
10+
11+
/**
12+
* A Search Engine slot handling AssignUserToUserGroupSignal.
13+
*/
14+
final class AssignUserToUserGroup extends AbstractSubtree
15+
{
16+
public function receive(Signal $signal): void
17+
{
18+
if (!$signal instanceof Signal\UserService\AssignUserToUserGroupSignal) {
19+
return;
20+
}
21+
22+
$content = $this->persistenceHandler->contentHandler()->load($signal->userId);
23+
$this->searchHandler->indexContent($content);
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
namespace eZ\Publish\Core\Search\Common\Slot;
8+
9+
use eZ\Publish\Core\SignalSlot\Signal;
10+
use eZ\Publish\Core\Search\Common\Slot;
11+
12+
/**
13+
* A Search Engine slot handling UnAssignUserFromUserGroup.
14+
*/
15+
final class UnAssignUserFromUserGroup extends Slot
16+
{
17+
public function receive(Signal $signal): void
18+
{
19+
if (!$signal instanceof Signal\UserService\UnAssignUserFromUserGroupSignal) {
20+
return;
21+
}
22+
23+
$content = $this->persistenceHandler->contentHandler()->load($signal->userId);
24+
$this->searchHandler->indexContent($content);
25+
}
26+
}

0 commit comments

Comments
 (0)