|
@@ 79-115 (lines=37) @@
|
| 76 |
|
* |
| 77 |
|
* @return \eZ\Publish\Core\REST\Server\Values\CreatedRole |
| 78 |
|
*/ |
| 79 |
|
public function createRole(Request $request) |
| 80 |
|
{ |
| 81 |
|
$publish = ($request->query->has('publish') && $request->query->get('publish') === 'true'); |
| 82 |
|
|
| 83 |
|
try { |
| 84 |
|
$roleDraft = $this->roleService->createRole( |
| 85 |
|
$this->inputDispatcher->parse( |
| 86 |
|
new Message( |
| 87 |
|
[ |
| 88 |
|
'Content-Type' => $request->headers->get('Content-Type'), |
| 89 |
|
// @todo Needs refactoring! Temporary solution so parser has access to get parameters |
| 90 |
|
'__publish' => $publish, |
| 91 |
|
], |
| 92 |
|
$request->getContent() |
| 93 |
|
) |
| 94 |
|
) |
| 95 |
|
); |
| 96 |
|
} catch (InvalidArgumentException $e) { |
| 97 |
|
throw new ForbiddenException($e->getMessage()); |
| 98 |
|
} catch (UnauthorizedException $e) { |
| 99 |
|
throw new ForbiddenException($e->getMessage()); |
| 100 |
|
} catch (LimitationValidationException $e) { |
| 101 |
|
throw new BadRequestException($e->getMessage()); |
| 102 |
|
} catch (Exceptions\Parser $e) { |
| 103 |
|
throw new BadRequestException($e->getMessage()); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
if ($publish) { |
| 107 |
|
$this->roleService->publishRoleDraft($roleDraft); |
| 108 |
|
|
| 109 |
|
$role = $this->roleService->loadRole($roleDraft->id); |
| 110 |
|
|
| 111 |
|
return new Values\CreatedRole(['role' => new Values\RestRole($role)]); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
return new Values\CreatedRole(['role' => new Values\RestRole($roleDraft)]); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
/** |
| 118 |
|
* Creates a new RoleDraft for an existing Role. |
|
@@ 124-160 (lines=37) @@
|
| 121 |
|
* |
| 122 |
|
* @return \eZ\Publish\Core\REST\Server\Values\CreatedRole |
| 123 |
|
*/ |
| 124 |
|
public function createRoleDraft(Request $request) |
| 125 |
|
{ |
| 126 |
|
$publish = ($request->query->has('publish') && $request->query->get('publish') === 'true'); |
| 127 |
|
|
| 128 |
|
try { |
| 129 |
|
$roleDraft = $this->roleService->createRoleDraft( |
| 130 |
|
$this->inputDispatcher->parse( |
| 131 |
|
new Message( |
| 132 |
|
[ |
| 133 |
|
'Content-Type' => $request->headers->get('Content-Type'), |
| 134 |
|
// @todo Needs refactoring! Temporary solution so parser has access to get parameters |
| 135 |
|
'__publish' => $publish, |
| 136 |
|
], |
| 137 |
|
$request->getContent() |
| 138 |
|
) |
| 139 |
|
) |
| 140 |
|
); |
| 141 |
|
} catch (InvalidArgumentException $e) { |
| 142 |
|
throw new ForbiddenException($e->getMessage()); |
| 143 |
|
} catch (UnauthorizedException $e) { |
| 144 |
|
throw new ForbiddenException($e->getMessage()); |
| 145 |
|
} catch (LimitationValidationException $e) { |
| 146 |
|
throw new BadRequestException($e->getMessage()); |
| 147 |
|
} catch (Exceptions\Parser $e) { |
| 148 |
|
throw new BadRequestException($e->getMessage()); |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
if ($publish) { |
| 152 |
|
$this->roleService->publishRoleDraft($roleDraft); |
| 153 |
|
|
| 154 |
|
$role = $this->roleService->loadRole($roleDraft->id); |
| 155 |
|
|
| 156 |
|
return new Values\CreatedRole(['role' => new Values\RestRole($role)]); |
| 157 |
|
} |
| 158 |
|
|
| 159 |
|
return new Values\CreatedRole(['role' => new Values\RestRole($roleDraft)]); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
/** |
| 163 |
|
* Loads list of roles. |