Skip to content

Commit

Permalink
Fix EZP-25014: Impossible to update a policy with no limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
lolautruche committed Oct 21, 2015
1 parent 741470d commit 570e25c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions eZ/Publish/API/Repository/Tests/RoleServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,52 @@ public function testNewPolicyUpdateStruct()
);
}

public function testUpdatePolicyNoLimitation()
{
$repository = $this->getRepository();

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

// Instantiate new policy create
$policyCreate = $roleService->newPolicyCreateStruct('foo', 'bar');

// Instantiate a role create and add the policy create
$roleCreate = $roleService->newRoleCreateStruct('myRole');

// @todo uncomment when support for multilingual names and descriptions is added EZP-24776
// $roleCreate->mainLanguageCode = 'eng-US';

$roleCreate->addPolicy($policyCreate);

// Create a new role instance.
$roleDraft = $roleService->createRole($roleCreate);
$roleService->publishRoleDraft($roleDraft);
$role = $roleService->loadRole($roleDraft->id);

// Search for the new policy instance
$policy = null;
foreach ($role->getPolicies() as $policy) {
if ($policy->module === 'foo' && $policy->function === 'bar') {
break;
}
}

// Create an update struct
$policyUpdate = $roleService->newPolicyUpdateStruct();

// Update the the policy
$policy = $roleService->updatePolicy($policy, $policyUpdate);
/* END: Use Case */

$this->assertInstanceOf(
'\\eZ\\Publish\\API\\Repository\\Values\\User\\Policy',
$policy
);

self::assertEquals(array(), $policy->getLimitations());
}

/**
* Test for the updatePolicy() method.
*
Expand Down
2 changes: 1 addition & 1 deletion eZ/Publish/Core/Persistence/Legacy/User/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public function updatePolicy(Policy $policy)
$this->limitationConverter->toLegacy($policy);

$this->roleGateway->removePolicyLimitations($policy->id);
$this->roleGateway->addPolicyLimitations($policy->id, $policy->limitations);
$this->roleGateway->addPolicyLimitations($policy->id, $policy->limitations === '*' ? array() : $policy->limitations);
}

/**
Expand Down

0 comments on commit 570e25c

Please sign in to comment.