WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/13/2018 04:23:35 AM (2 years ago)
Author:
pento
Message:

REST API: Tweak permission checks for taxonomy and term endpoints

To match behaviour in the Classic Editor, we need to slightly loosen permissions on taxonomy and term endpoints. This allows users to create terms to assign to a post that they're editing.

Props danielbachhuber.
Fixes #44096.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php

    r43087 r43440  
    1313class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcase {
    1414    protected static $administrator;
     15    protected static $contributor;
    1516    protected static $subscriber;
    1617
     
    1920            array(
    2021                'role' => 'administrator',
     22            )
     23        );
     24        self::$contributor   = $factory->user->create(
     25            array(
     26                'role' => 'subscriber',
    2127            )
    2228        );
     
    721727    public function test_create_item_incorrect_permissions() {
    722728        wp_set_current_user( self::$subscriber );
     729        $request = new WP_REST_Request( 'POST', '/wp/v2/categories' );
     730        $request->set_param( 'name', 'Incorrect permissions' );
     731        $response = rest_get_server()->dispatch( $request );
     732        $this->assertErrorResponse( 'rest_cannot_create', $response, 403 );
     733    }
     734
     735    public function test_create_item_incorrect_permissions_contributor() {
     736        wp_set_current_user( self::$contributor );
    723737        $request = new WP_REST_Request( 'POST', '/wp/v2/categories' );
    724738        $request->set_param( 'name', 'Incorrect permissions' );
Note: See TracChangeset for help on using the changeset viewer.