Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 9cb9877

Browse files
committed
Use rest_authorization_required_code instead of 403
1 parent 43bd4cb commit 9cb9877

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/endpoints/class-papi-rest-api-options-controller.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function delete_option( WP_REST_Request $request ) {
2424
return (object) ['deleted' => true];
2525
}
2626

27-
return new WP_Error( 'papi_delete_option_error', __( 'Delete option value did not work. The property may not be found', 'papi-rest-api' ), ['status' => 500] );
27+
return new WP_Error( 'papi_delete_option_error', __( 'Delete option value did not work. The property may not be found.', 'papi-rest-api' ), ['status' => 500] );
2828
}
2929

3030
/**
@@ -37,7 +37,7 @@ public function delete_option( WP_REST_Request $request ) {
3737
public function delete_option_permissions_check( WP_REST_Request $request ) {
3838
foreach ( $this->get_option_types_capabilities() as $capability ) {
3939
if ( ! current_user_can( $capability ) ) {
40-
return new WP_Error( 'papi_cannot_delete_option', __( 'Sorry, you are not allowed to delete the option value', 'papi-rest-api' ), ['status' => 403] );
40+
return new WP_Error( 'papi_cannot_delete_option', __( 'Sorry, you are not allowed to delete the option value.', 'papi-rest-api' ), ['status' => rest_authorization_required_code()] );
4141
}
4242
}
4343

@@ -85,7 +85,7 @@ protected function get_option_property( WP_REST_Request $request ) {
8585
$property = $page->get_property( $request['slug'] );
8686

8787
if ( ! papi_is_property( $property ) ) {
88-
return new WP_Error( 'papi_slug_invalid', __( 'Option slug doesn\'t exist', 'papi-rest-api' ) , ['status' => 404] );
88+
return new WP_Error( 'papi_slug_invalid', __( 'Option slug doesn\'t exist.', 'papi-rest-api' ) , ['status' => 404] );
8989
}
9090

9191
return $this->create_property_item( $request, $property, [
@@ -189,7 +189,7 @@ public function update_option( WP_REST_Request $request ) {
189189
return $this->get_option_property( $request );
190190
}
191191

192-
return new WP_Error( 'papi_update_option_error', __( 'Update option value did not work. The property may not be found', 'papi-rest-api' ), ['status' => 500] );
192+
return new WP_Error( 'papi_update_option_error', __( 'Update option value did not work. The property may not be found.', 'papi-rest-api' ), ['status' => 500] );
193193
}
194194

195195
/**
@@ -202,7 +202,7 @@ public function update_option( WP_REST_Request $request ) {
202202
public function update_option_permissions_check( WP_REST_Request $request ) {
203203
foreach ( $this->get_option_types_capabilities() as $capability ) {
204204
if ( ! current_user_can( $capability ) ) {
205-
return new WP_Error( 'papi_cannot_update_option', __( 'Sorry, you are not allowed to update the option value', 'papi-rest-api' ), ['status' => 403] );
205+
return new WP_Error( 'papi_cannot_update_option', __( 'Sorry, you are not allowed to update the option value.', 'papi-rest-api' ), ['status' => rest_authorization_required_code()] );
206206
}
207207
}
208208

tests/cases/endpoints/class-papi-rest-api-options-controller-test.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function test_delete_option_value_access_denied() {
3232
$data = $response->get_data();
3333
$expected = [
3434
'code' => 'papi_cannot_delete_option',
35-
'message' => 'Sorry, you are not allowed to delete the option value',
36-
'data' => ['status' => 403]
35+
'message' => 'Sorry, you are not allowed to delete the option value.',
36+
'data' => ['status' => 401]
3737
];
3838

3939
$this->assertEquals( $expected, $data );
@@ -49,7 +49,7 @@ public function test_delete_option_value_error() {
4949
$data = $response->get_data();
5050
$expected = [
5151
'code' => 'papi_delete_option_error',
52-
'message' => 'Delete option value did not work. The property may not be found',
52+
'message' => 'Delete option value did not work. The property may not be found.',
5353
'data' => ['status' => 500]
5454
];
5555

@@ -105,7 +105,7 @@ public function test_get_missing_option_value() {
105105
$data = $response->get_data();
106106
$expected = [
107107
'code' => 'papi_slug_invalid',
108-
'message' => 'Option slug doesn\'t exist',
108+
'message' => 'Option slug doesn\'t exist.',
109109
'data' => ['status' => 404]
110110
];
111111

@@ -200,8 +200,8 @@ public function test_update_option_value_access_denied() {
200200
$data = $response->get_data();
201201
$expected = [
202202
'code' => 'papi_cannot_update_option',
203-
'message' => 'Sorry, you are not allowed to update the option value',
204-
'data' => ['status' => 403]
203+
'message' => 'Sorry, you are not allowed to update the option value.',
204+
'data' => ['status' => 401]
205205
];
206206

207207
$this->assertEquals( $expected, $data );
@@ -218,7 +218,7 @@ public function test_update_option_value_error() {
218218
$data = $response->get_data();
219219
$expected = [
220220
'code' => 'papi_update_option_error',
221-
'message' => 'Update option value did not work. The property may not be found',
221+
'message' => 'Update option value did not work. The property may not be found.',
222222
'data' => ['status' => 500]
223223
];
224224

0 commit comments

Comments
 (0)