diff --git a/eZ/Publish/API/Repository/Tests/RoleServiceTest.php b/eZ/Publish/API/Repository/Tests/RoleServiceTest.php index d05bcf8cd46..90cd37f6abf 100644 --- a/eZ/Publish/API/Repository/Tests/RoleServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/RoleServiceTest.php @@ -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. * diff --git a/eZ/Publish/Core/Persistence/Cache/UserHandler.php b/eZ/Publish/Core/Persistence/Cache/UserHandler.php index 2ff2e806a10..84577812574 100644 --- a/eZ/Publish/Core/Persistence/Cache/UserHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/UserHandler.php @@ -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); } @@ -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); }