Changeset 14214
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-core-components-rest-controller.php
r14042 r14214 267 267 */ 268 268 public function update_item_permissions_check( $request ) { 269 $retval = $this->get_items_permissions_check( $request ); 269 $retval = new WP_Error( 270 'bp_rest_authorization_required', 271 __( 'Sorry, you are not allowed to perform this action.', 'buddypress' ), 272 array( 273 'status' => rest_authorization_required_code(), 274 ) 275 ); 276 277 // Unlike `get_items`, toggling a component is an admin-only operation. 278 if ( bp_current_user_can( 'manage_options' ) ) { 279 $retval = true; 280 } 270 281 271 282 /** -
trunk/tests/phpunit/testcases/core/test-components-controller.php
r14070 r14214 347 347 348 348 /** 349 * @group update_item 350 */ 351 public function test_update_item_site_admin_only() { 352 $u = static::factory()->user->create( 353 array( 354 'role' => 'author', 355 ) 356 ); 357 358 $this->bp::set_current_user( $u ); 359 360 // Snapshot so we can prove no component was toggled. 361 $before = bp_get_option( 'bp-active-components' ); 362 363 $request = new WP_REST_Request( 'PUT', $this->endpoint_url ); 364 $request->set_query_params( array( 365 'name' => 'friends', 366 'action' => 'deactivate', 367 ) ); 368 $response = $this->server->dispatch( $request ); 369 370 $this->assertErrorResponse( 'bp_rest_authorization_required', $response, 403 ); 371 372 // The component toggle must not have executed. 373 $this->assertSame( $before, bp_get_option( 'bp-active-components' ) ); 374 } 375 376 /** 349 377 * @group delete_item 350 378 */
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)