Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-1310: Created slots for assigning/unassigning user to groups #3125

Merged
merged 8 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions eZ/Publish/API/Repository/Tests/UserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,39 @@ public function testAssignUserToUserGroup()
);
}

/**
* @covers \eZ\Publish\API\Repository\UserService::assignUserToUserGroup
*/
public function testAssignUserToGroupWithLocationsValidation()
barw4 marked this conversation as resolved.
Show resolved Hide resolved
{
$repository = $this->getRepository();
$userService = $repository->getUserService();
$locationService = $repository->getLocationService();

$administratorGroupId = $this->generateId('group', 12);

$user = $this->createUserVersion1();

$group = $userService->loadUserGroup($administratorGroupId);
$groupLocation = $locationService->loadLocation($group->contentInfo->mainLocationId);

// Count number of child locations before assigning user to group
$count = $locationService->getLocationChildCount($groupLocation);
$expectedCount = $count + 1;

$userService->assignUserToUserGroup(
$user,
$group
);

$this->refreshSearch($repository);

// Count number of child locations after assigning user to group
$actualCount = $locationService->getLocationChildCount($groupLocation);

self::assertEquals($expectedCount, $actualCount);
}

/**
* Test for the assignUserToUserGroup() method.
*
Expand Down Expand Up @@ -2224,6 +2257,48 @@ public function testUnAssignUserFromUserGroupThrowsBadStateArgumentException()
/* END: Use Case */
}

/**
* @covers \eZ\Publish\API\Repository\UserService::unAssignUserFromUserGroup
*/
public function testUnAssignUserToGroupWithLocationValidation()
{
$repository = $this->getRepository();
$userService = $repository->getUserService();
$locationService = $repository->getLocationService();

$editorsGroupId = $this->generateId('group', 13);
$anonymousGroupId = $this->generateId('group', 42);

$user = $this->createUserVersion1();

$this->refreshSearch($repository);

$group = $userService->loadUserGroup($editorsGroupId);
$groupLocation = $locationService->loadLocation($group->contentInfo->mainLocationId);

// Count number of child locations before unassigning user from group
$count = $locationService->getLocationChildCount($groupLocation);
$expectedCount = $count - 1;

// Assigning user to different group to avoid removing all groups from user
$userService->assignUserToUserGroup(
$user,
$userService->loadUserGroup($anonymousGroupId)
);

$userService->unAssignUserFromUserGroup(
$user,
$userService->loadUserGroup($editorsGroupId)
);

$this->refreshSearch($repository);

// Count number of child locations after unassigning user from group
$actualCount = $locationService->getLocationChildCount($groupLocation);

self::assertEquals($expectedCount, $actualCount);
}

/**
* Test that multi-language logic for the loadUserGroup method respects prioritized language list.
*
Expand Down
25 changes: 25 additions & 0 deletions eZ/Publish/Core/Search/Common/Slot/AssignUserToUserGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\Core\Search\Common\Slot;
barw4 marked this conversation as resolved.
Show resolved Hide resolved

use eZ\Publish\Core\SignalSlot\Signal;

/**
* A Search Engine slot handling AssignUserToUserGroupSignal.
*/
class AssignUserToUserGroup extends AbstractSubtree
barw4 marked this conversation as resolved.
Show resolved Hide resolved
{
public function receive(Signal $signal): void
{
if (!$signal instanceof Signal\UserService\AssignUserToUserGroupSignal) {
return;
}

$content = $this->persistenceHandler->contentHandler()->load($signal->userId);
$this->searchHandler->indexContent($content);
}
}
26 changes: 26 additions & 0 deletions eZ/Publish/Core/Search/Common/Slot/UnAssignUserFromUserGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\Core\Search\Common\Slot;

use eZ\Publish\Core\SignalSlot\Signal;
use eZ\Publish\Core\Search\Common\Slot;

/**
* A Search Engine slot handling UnAssignUserFromUserGroup.
*/
class UnAssignUserFromUserGroup extends Slot
barw4 marked this conversation as resolved.
Show resolved Hide resolved
{
public function receive(Signal $signal): void
{
if (!$signal instanceof Signal\UserService\UnAssignUserFromUserGroupSignal) {
return;
}

$content = $this->persistenceHandler->contentHandler()->load($signal->userId);
$this->searchHandler->indexContent($content);
}
}