Make WordPress Core


Ignore:
Timestamp:
12/11/2018 04:12:56 AM (8 years ago)
Author:
jorbin
Message:

REST API: Declare unfiltered_html capability in links.

Because user capabilities can be modified at runtime, the REST API needs to expose them in some evaluated but declarative manner for clients to interpret. JSON Hyper Schema targetSchema provides an appropriate paradigm for doing so.

Merges [43682] to trunk.

Props timothyblynjacobs.

Fixes #45014.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r43571 r43974  
    39933993        }
    39943994
     3995        public function test_assign_unfiltered_html_action_superadmin() {
     3996                $post_id = self::factory()->post->create();
     3997                wp_set_current_user( self::$superadmin_id );
     3998                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
     3999                $request->set_param( 'context', 'edit' );
     4000                $response = rest_do_request( $request );
     4001                $links    = $response->get_links();
     4002                $this->assertArrayHasKey( 'https://api.w.org/action-unfiltered-html', $links );
     4003        }
     4004
     4005        public function test_assign_unfiltered_html_action_editor() {
     4006                $post_id = self::factory()->post->create();
     4007                wp_set_current_user( self::$editor_id );
     4008                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
     4009                $request->set_param( 'context', 'edit' );
     4010                $response = rest_do_request( $request );
     4011                $links    = $response->get_links();
     4012                // Editors can only unfiltered html on single site.
     4013                if ( is_multisite() ) {
     4014                        $this->assertArrayNotHasKey( 'https://api.w.org/action-unfiltered-html', $links );
     4015                } else {
     4016                        $this->assertArrayHasKey( 'https://api.w.org/action-unfiltered-html', $links );
     4017                }
     4018        }
     4019
     4020        public function test_assign_unfiltered_html_action_author() {
     4021                $post_id = self::factory()->post->create();
     4022                wp_set_current_user( self::$author_id );
     4023                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
     4024                $request->set_param( 'context', 'edit' );
     4025                $response = rest_do_request( $request );
     4026                $links    = $response->get_links();
     4027                // Authors can't ever unfiltered html
     4028                $this->assertArrayNotHasKey( 'https://api.w.org/action-unfiltered-html', $links );
     4029        }
     4030
    39954031        public function tearDown() {
    39964032                _unregister_post_type( 'youseeeme' );
Note: See TracChangeset for help on using the changeset viewer.