|
@@ 268-302 (lines=35) @@
|
| 265 |
|
* |
| 266 |
|
* @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
| 267 |
|
*/ |
| 268 |
|
public function addPolicyByRoleDraft(APIRoleDraft $roleDraft, APIPolicyCreateStruct $policyCreateStruct) |
| 269 |
|
{ |
| 270 |
|
$values = $this->requestParser->parse('role', $roleDraft->id); |
| 271 |
|
$inputMessage = $this->outputVisitor->visit($policyCreateStruct); |
| 272 |
|
$inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Policy'); |
| 273 |
|
|
| 274 |
|
$result = $this->client->request( |
| 275 |
|
'POST', |
| 276 |
|
$this->requestParser->generate('policies', array('role' => $values['role'])), |
| 277 |
|
$inputMessage |
| 278 |
|
); |
| 279 |
|
|
| 280 |
|
$createdPolicy = $this->inputDispatcher->parse($result); |
| 281 |
|
|
| 282 |
|
// @todo Workaround for missing roleId in Policy XSD definition |
| 283 |
|
$createdPolicyArray = array( |
| 284 |
|
'id' => $createdPolicy->id, |
| 285 |
|
'roleId' => $roleDraft->id, |
| 286 |
|
'module' => $createdPolicy->module, |
| 287 |
|
'function' => $createdPolicy->function, |
| 288 |
|
); |
| 289 |
|
|
| 290 |
|
$createdPolicy = new Policy($createdPolicyArray); |
| 291 |
|
|
| 292 |
|
$existingPolicies = $roleDraft->getPolicies(); |
| 293 |
|
$existingPolicies[] = $createdPolicy; |
| 294 |
|
|
| 295 |
|
return new RoleDraft( |
| 296 |
|
array( |
| 297 |
|
'id' => $roleDraft->id, |
| 298 |
|
'identifier' => $roleDraft->identifier, |
| 299 |
|
), |
| 300 |
|
$existingPolicies |
| 301 |
|
); |
| 302 |
|
} |
| 303 |
|
|
| 304 |
|
/** |
| 305 |
|
* Removes a policy from a role draft. |
|
@@ 527-561 (lines=35) @@
|
| 524 |
|
* |
| 525 |
|
* @return \eZ\Publish\API\Repository\Values\User\Role |
| 526 |
|
*/ |
| 527 |
|
public function addPolicy(APIRole $role, APIPolicyCreateStruct $policyCreateStruct) |
| 528 |
|
{ |
| 529 |
|
$values = $this->requestParser->parse('role', $role->id); |
| 530 |
|
$inputMessage = $this->outputVisitor->visit($policyCreateStruct); |
| 531 |
|
$inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Policy'); |
| 532 |
|
|
| 533 |
|
$result = $this->client->request( |
| 534 |
|
'POST', |
| 535 |
|
$this->requestParser->generate('policies', array('role' => $values['role'])), |
| 536 |
|
$inputMessage |
| 537 |
|
); |
| 538 |
|
|
| 539 |
|
$createdPolicy = $this->inputDispatcher->parse($result); |
| 540 |
|
|
| 541 |
|
// @todo Workaround for missing roleId in Policy XSD definition |
| 542 |
|
$createdPolicyArray = array( |
| 543 |
|
'id' => $createdPolicy->id, |
| 544 |
|
'roleId' => $role->id, |
| 545 |
|
'module' => $createdPolicy->module, |
| 546 |
|
'function' => $createdPolicy->function, |
| 547 |
|
); |
| 548 |
|
|
| 549 |
|
$createdPolicy = new Policy($createdPolicyArray); |
| 550 |
|
|
| 551 |
|
$existingPolicies = $role->getPolicies(); |
| 552 |
|
$existingPolicies[] = $createdPolicy; |
| 553 |
|
|
| 554 |
|
return new Role( |
| 555 |
|
array( |
| 556 |
|
'id' => $role->id, |
| 557 |
|
'identifier' => $role->identifier, |
| 558 |
|
), |
| 559 |
|
$existingPolicies |
| 560 |
|
); |
| 561 |
|
} |
| 562 |
|
|
| 563 |
|
/** |
| 564 |
|
* Removes a policy from the role. |