Make WordPress Core


Ignore:
Timestamp:
07/13/2018 04:23:35 AM (8 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-tags-controller.php

    r43087 r43440  
    1414        protected static $administrator;
    1515        protected static $editor;
     16        protected static $contributor;
    1617        protected static $subscriber;
    1718
     
    3132                        array(
    3233                                'role' => 'editor',
     34                        )
     35                );
     36                self::$contributor   = $factory->user->create(
     37                        array(
     38                                'role' => 'contributor',
    3339                        )
    3440                );
     
    611617        public function test_create_item() {
    612618                wp_set_current_user( self::$administrator );
     619                $request = new WP_REST_Request( 'POST', '/wp/v2/tags' );
     620                $request->set_param( 'name', 'My Awesome Term' );
     621                $request->set_param( 'description', 'This term is so awesome.' );
     622                $request->set_param( 'slug', 'so-awesome' );
     623                $response = rest_get_server()->dispatch( $request );
     624                $this->assertEquals( 201, $response->get_status() );
     625                $headers = $response->get_headers();
     626                $data    = $response->get_data();
     627                $this->assertContains( '/wp/v2/tags/' . $data['id'], $headers['Location'] );
     628                $this->assertEquals( 'My Awesome Term', $data['name'] );
     629                $this->assertEquals( 'This term is so awesome.', $data['description'] );
     630                $this->assertEquals( 'so-awesome', $data['slug'] );
     631        }
     632
     633        public function test_create_item_contributor() {
     634                wp_set_current_user( self::$contributor );
    613635                $request = new WP_REST_Request( 'POST', '/wp/v2/tags' );
    614636                $request->set_param( 'name', 'My Awesome Term' );
Note: See TracChangeset for help on using the changeset viewer.