- Timestamp:
- 07/13/2018 04:23:35 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
r43087 r43440 85 85 } 86 86 foreach ( $taxonomies as $taxonomy ) { 87 if ( ! empty( $taxonomy->show_in_rest ) && current_user_can( $taxonomy->cap-> manage_terms ) ) {87 if ( ! empty( $taxonomy->show_in_rest ) && current_user_can( $taxonomy->cap->assign_terms ) ) { 88 88 return true; 89 89 } … … 114 114 $data = array(); 115 115 foreach ( $taxonomies as $tax_type => $value ) { 116 if ( empty( $value->show_in_rest ) || ( 'edit' === $request['context'] && ! current_user_can( $value->cap-> manage_terms ) ) ) {116 if ( empty( $value->show_in_rest ) || ( 'edit' === $request['context'] && ! current_user_can( $value->cap->assign_terms ) ) ) { 117 117 continue; 118 118 } … … 146 146 return false; 147 147 } 148 if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap-> manage_terms ) ) {148 if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->assign_terms ) ) { 149 149 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); 150 150 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r43087 r43440 381 381 382 382 $taxonomy_obj = get_taxonomy( $this->taxonomy ); 383 if ( ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) { 383 if ( ( is_taxonomy_hierarchical( $this->taxonomy ) 384 && ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) 385 || ( ! is_taxonomy_hierarchical( $this->taxonomy ) 386 && ! current_user_can( $taxonomy_obj->cap->assign_terms ) ) ) { 384 387 return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) ); 385 388 } -
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r43087 r43440 13 13 class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcase { 14 14 protected static $administrator; 15 protected static $contributor; 15 16 protected static $subscriber; 16 17 … … 19 20 array( 20 21 'role' => 'administrator', 22 ) 23 ); 24 self::$contributor = $factory->user->create( 25 array( 26 'role' => 'subscriber', 21 27 ) 22 28 ); … … 721 727 public function test_create_item_incorrect_permissions() { 722 728 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 ); 723 737 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 724 738 $request->set_param( 'name', 'Incorrect permissions' ); -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r43087 r43440 14 14 protected static $administrator; 15 15 protected static $editor; 16 protected static $contributor; 16 17 protected static $subscriber; 17 18 … … 31 32 array( 32 33 'role' => 'editor', 34 ) 35 ); 36 self::$contributor = $factory->user->create( 37 array( 38 'role' => 'contributor', 33 39 ) 34 40 ); … … 611 617 public function test_create_item() { 612 618 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 ); 613 635 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 614 636 $request->set_param( 'name', 'My Awesome Term' ); -
trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php
r43087 r43440 50 50 public function test_get_items() { 51 51 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' ); 52 $response = rest_get_server()->dispatch( $request ); 53 $data = $response->get_data(); 54 $taxonomies = $this->get_public_taxonomies( get_taxonomies( '', 'objects' ) ); 55 $this->assertEquals( count( $taxonomies ), count( $data ) ); 56 $this->assertEquals( 'Categories', $data['category']['name'] ); 57 $this->assertEquals( 'category', $data['category']['slug'] ); 58 $this->assertEquals( true, $data['category']['hierarchical'] ); 59 $this->assertEquals( 'Tags', $data['post_tag']['name'] ); 60 $this->assertEquals( 'post_tag', $data['post_tag']['slug'] ); 61 $this->assertEquals( false, $data['post_tag']['hierarchical'] ); 62 $this->assertEquals( 'tags', $data['post_tag']['rest_base'] ); 63 } 64 65 public function test_get_items_context_edit() { 66 wp_set_current_user( self::$contributor_id ); 67 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' ); 68 $request->set_param( 'context', 'edit' ); 52 69 $response = rest_get_server()->dispatch( $request ); 53 70 $data = $response->get_data();
Note: See TracChangeset
for help on using the changeset viewer.