Skip to content

Commit 89f00b2

Browse files
committed
Merge pull request #670 from StephaneDiot/impl/EZP-21678_Make_unimplemented_REST_features_return_a_501
Implement EZP-21678: Make unimplemented rest features return a 501 error code
2 parents 8c77001 + 23c0974 commit 89f00b2

File tree

5 files changed

+137
-3
lines changed

5 files changed

+137
-3
lines changed

eZ/Bundle/EzPublishRestBundle/Resources/config/routing.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,23 @@ ezpublish_rest_createView:
230230
_controller: ezpublish_rest.controller.content:createView
231231
methods: [POST]
232232

233-
# @todo this doesn't actually exist. Must generate a 404.
234-
ezpublish_rest_loadView:
235-
path: /content/views/{viewId}
233+
ezpublish_rest_listView:
234+
path: /content/views
235+
defaults:
236+
_controller: ezpublish_rest.controller.content:listView
237+
methods: [GET]
238+
239+
ezpublish_rest_getView:
240+
path : /content/views/{viewId}
241+
defaults:
242+
_controller: ezpublish_rest.controller.content:getView
243+
methods: [GET]
236244

237245
ezpublish_rest_loadViewResults:
238246
path: /content/views/{viewId}/results
247+
defaults:
248+
_controller: ezpublish_rest.controller.content:loadViewResults
249+
methods: [GET]
239250

240251
# Object states
241252

eZ/Bundle/EzPublishRestBundle/Resources/config/value_object_visitors.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ parameters:
99
ezpublish_rest.output.value_object_visitor.BadRequestException.class: eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\BadRequestException
1010
ezpublish_rest.output.value_object_visitor.ForbiddenException.class: eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\ForbiddenException
1111
ezpublish_rest.output.value_object_visitor.Exception.class: eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\Exception
12+
ezpublish_rest.output.value_object_visitor.NotImplementedException.class: eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\NotImplementedException
1213

1314
# Section
1415
ezpublish_rest.output.value_object_visitor.SectionList.class: eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\SectionList
@@ -168,6 +169,13 @@ services:
168169
tags:
169170
- { name: ezpublish_rest.output.value_object_visitor, type: eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException }
170171

172+
ezpublish_rest.output.value_object_visitor.NotImplementedException:
173+
parent: ezpublish_rest.output.value_object_visitor.base
174+
class: %ezpublish_rest.output.value_object_visitor.NotImplementedException.class%
175+
arguments: [ true ]
176+
tags:
177+
- { name: ezpublish_rest.output.value_object_visitor, type: eZ\Publish\API\Repository\Exceptions\NotImplementedException }
178+
171179
ezpublish_rest.output.value_object_visitor.Exception:
172180
parent: ezpublish_rest.output.value_object_visitor.base
173181
class: %ezpublish_rest.output.value_object_visitor.Exception.class%

eZ/Publish/Core/REST/Server/Controller/Content.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
2020
use eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException;
2121
use eZ\Publish\API\Repository\Exceptions\ContentValidationException;
22+
use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
2223
use eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException;
2324
use eZ\Publish\Core\REST\Server\Exceptions\BadRequestException;
2425

@@ -760,4 +761,34 @@ public function createView()
760761
)
761762
);
762763
}
764+
765+
/**
766+
* List content views
767+
*
768+
* @return NotImplementedException;
769+
*/
770+
public function listView()
771+
{
772+
return new NotImplementedException( 'ezpublish_rest.controller.content:listView' );
773+
}
774+
775+
/**
776+
* Get a content view
777+
*
778+
* @return NotImplementedException;
779+
*/
780+
public function getView()
781+
{
782+
return new NotImplementedException( 'ezpublish_rest.controller.content:getView' );
783+
}
784+
785+
/**
786+
* Get a content view results
787+
*
788+
* @return NotImplementedException;
789+
*/
790+
public function loadViewResults()
791+
{
792+
return new NotImplementedException( 'ezpublish_rest.controller.content:loadViewResults' );
793+
}
763794
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* File containing the NotImplementedException ValueObjectVisitor class
4+
*
5+
* @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved.
6+
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
7+
* @version //autogentag//
8+
*/
9+
10+
namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
11+
12+
/**
13+
* NotImplementedException value object visitor
14+
*/
15+
class NotImplementedException extends Exception
16+
{
17+
/**
18+
* Returns HTTP status code
19+
*
20+
* @return int
21+
*/
22+
protected function getStatus()
23+
{
24+
return 501;
25+
}
26+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* File containing a test class
4+
*
5+
* @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved.
6+
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
7+
* @version //autogentag//
8+
*/
9+
10+
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor;
11+
12+
use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
13+
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
14+
use eZ\Publish\Core\REST\Common;
15+
16+
class NotImplementedExceptionTest extends ExceptionTest
17+
{
18+
/**
19+
* Get expected status code
20+
*
21+
* @return int
22+
*/
23+
protected function getExpectedStatusCode()
24+
{
25+
return 501;
26+
}
27+
28+
/**
29+
* Get expected message
30+
*
31+
* @return string
32+
*/
33+
protected function getExpectedMessage()
34+
{
35+
return "Not Implemented";
36+
}
37+
38+
/**
39+
* Gets the exception
40+
*
41+
* @return \Exception
42+
*/
43+
protected function getException()
44+
{
45+
return new NotImplementedException( "Test" );
46+
47+
}
48+
49+
/**
50+
* Gets the exception visitor
51+
*
52+
* @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\NotImplementedException
53+
*/
54+
protected function internalGetVisitor()
55+
{
56+
return new ValueObjectVisitor\NotImplementedException;
57+
}
58+
}

0 commit comments

Comments
 (0)