Skip to content

Commit

Permalink
EZP-29083: Error after trying to delete role assignment (ezsystems#2377)
Browse files Browse the repository at this point in the history
* EZP-29083: Error after trying to delete role assignment

* EZP-29083: Error after trying to delete role assignment - integration test

* EZP-29083: Error after trying to delete role assignment - new implementation
  • Loading branch information
ViniTou authored and Łukasz Serwatka committed Aug 2, 2018
1 parent 9aef27a commit aa8af2f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
45 changes: 45 additions & 0 deletions eZ/Publish/API/Repository/Tests/RoleServiceTest.php
Expand Up @@ -1781,6 +1781,51 @@ public function testDeletePolicy()
$this->assertSame(array(), $role->getPolicies());
}

/**
* Test for the addPolicyByRoleDraft() method.
*
* @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft()
*/
public function testAddPolicyWithRoleAssignment()
{
$repository = $this->getRepository();

/* BEGIN: Use Case */
$roleService = $repository->getRoleService();
$userService = $repository->getUserService();

/* Create new user group */
$mainGroupId = $this->generateId('group', 4);
$parentUserGroup = $userService->loadUserGroup($mainGroupId);
$userGroupCreate = $userService->newUserGroupCreateStruct('eng-US');
$userGroupCreate->setField('name', 'newUserGroup');
$userGroup = $userService->createUserGroup($userGroupCreate, $parentUserGroup);

/* Create Role */
$roleCreate = $roleService->newRoleCreateStruct('newRole');
$roleDraft = $roleService->createRole($roleCreate);
$roleService->publishRoleDraft($roleDraft);

$role = $roleService->loadRole($roleDraft->id);
$roleService->assignRoleToUserGroup($role, $userGroup);

$roleAssignmentsBeforeNewPolicy = $roleService->getRoleAssignments($role)[0];

/* Add new policy to existing role */
$roleUpdateDraft = $roleService->createRoleDraft($role);
$roleUpdateDraft = $roleService->addPolicyByRoleDraft(
$roleUpdateDraft,
$roleService->newPolicyCreateStruct('content', 'create')
);
$roleService->publishRoleDraft($roleUpdateDraft);

$roleAfterUpdate = $roleService->loadRole($role->id);
$roleAssignmentsAfterNewPolicy = $roleService->getRoleAssignments($roleAfterUpdate)[0];
/* END: Use Case */

$this->assertNotEquals($roleAssignmentsBeforeNewPolicy->id, $roleAssignmentsAfterNewPolicy->id);
}

/**
* Test loading user/group role assignments.
*
Expand Down
11 changes: 8 additions & 3 deletions eZ/Publish/Core/Persistence/Cache/UserHandler.php
Expand Up @@ -304,7 +304,10 @@ public function loadRoleAssignmentsByRoleId($roleId)
$roleAssignments = $this->persistenceHandler->userHandler()->loadRoleAssignmentsByRoleId($roleId);

$cacheItem->set($roleAssignments);
$cacheTags = ['role-assignment-role-list-' . $roleId];
$cacheTags = [
'role-assignment-role-list-' . $roleId,
'role-' . $roleId, /* Role update (policies) changes role assignment id */
];
foreach ($roleAssignments as $roleAssignment) {
$cacheTags = $this->getCacheTagsForRoleAssignment($roleAssignment, $cacheTags);
}
Expand Down Expand Up @@ -333,8 +336,10 @@ public function loadRoleAssignmentsByGroupId($groupId, $inherit = false)
$roleAssignments = $this->persistenceHandler->userHandler()->loadRoleAssignmentsByGroupId($groupId, $inherit);

$cacheItem->set($roleAssignments);
// Tag below is for empty results, non empty it might have duplicated tags but cache will reduce those.
$cacheTags = ['role-assignment-group-list-' . $groupId];
$cacheTags = [
'role-assignment-group-list-' . $groupId, /* empty results, non empty it might have duplicated tags but cache will reduce those. */
'role-' . $groupId, /* Role update (policies) changes role assignment id */
];
foreach ($roleAssignments as $roleAssignment) {
$cacheTags = $this->getCacheTagsForRoleAssignment($roleAssignment, $cacheTags);
}
Expand Down

0 comments on commit aa8af2f

Please sign in to comment.