Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global styles revisions: ensure the revisions endpoint permissions match the global styles controller #50270

Merged
merged 4 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ public function get_item_permissions_check( $request ) {
return $post;
}

/*
* The same check as WP_REST_Global_Styles_Controller->get_item_permissions_check.
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding comment for context.

if ( ! current_user_can( 'read_post', $post->ID ) ) {
return new WP_Error(
'rest_cannot_view',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class Gutenberg_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_RES
*/
protected static $second_admin_id;

/**
* @var int
*/
protected static $author_id;

/**
* @var int
*/
Expand All @@ -37,6 +42,11 @@ public static function wpSetupBeforeClass( $factory ) {
'role' => 'administrator',
)
);
self::$author_id = $factory->user->create(
array(
'role' => 'author',
)
);
// This creates the global styles for the current theme.
self::$global_styles_id = wp_insert_post(
array(
Expand Down Expand Up @@ -160,6 +170,17 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'modified_gmt', $properties, 'Schema properties array does not have "modified_gmt" key' );
}

/**
* @covers Gutenberg_REST_Global_Styles_Revisions_Controller::get_item_permissions_check
*/
public function test_get_item_permissions_check() {
wp_set_current_user( self::$author_id );
$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );
$response = rest_get_server()->dispatch( $request );

$this->assertErrorResponse( 'rest_cannot_view', $response, 403 );
}

/**
* @doesNotPerformAssertions
*/
Expand Down