Skip to content
Open
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 @@ -719,7 +719,7 @@ protected function get_user( $request ) {
return $error;
}

if ( is_multisite() && ! user_can( $user->ID, 'manage_sites' ) && ! is_user_member_of_blog( $user->ID ) ) {
if ( is_multisite() && ! current_user_can( 'manage_network_users' ) && ! user_can( $user->ID, 'manage_sites' ) && ! is_user_member_of_blog( $user->ID ) ) {
return $error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,4 +1112,36 @@ private function setup_app_password_authenticated_request() {

return $item;
}

/**
* @ticket 60029
* @group ms-required
*/
public function test_create_item_for_user_without_role_on_main_site() {
Copy link
Member

Choose a reason for hiding this comment

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

These tests are interesting but the only question that comes to my mind is that I can't see with these tests is that the actual method WP_REST_Application_Passwords_Controller::get_user that is causing the issue is not being asserted. So the test is failing because of an error, not because of a wrong assert.

if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}

wp_set_current_user( self::$admin );

$blog_id = self::factory()->blog->create();
$user_id = self::factory()->user->create();

// Remove user from main site if they were automatically added.
if ( is_user_member_of_blog( $user_id ) ) {
remove_user_from_blog( $user_id, get_current_blog_id() );
}
add_user_to_blog( $blog_id, $user_id, 'subscriber' );

$this->assertFalse( is_user_member_of_blog( $user_id ) );

$request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/users/%d/application-passwords', $user_id ) );
$request->set_body_params( array( 'name' => 'Test App' ) );
$response = rest_do_request( $request );
$this->assertSame( 201, $response->get_status() );

$passwords = WP_Application_Passwords::get_user_application_passwords( $user_id );
$this->assertCount( 1, $passwords );
$this->assertSame( 'Test App', $passwords[0]['name'] );
}
}
Loading