add read cap by default for new roles #376

This commit is contained in:
leogermani 2020-04-13 19:36:56 -03:00 committed by vnmedeiros
parent 8eaf1d7c77
commit c009862185
2 changed files with 20 additions and 0 deletions

View File

@ -146,6 +146,10 @@ class REST_Roles_Controller extends REST_Controller {
}
if ($new_role instanceof \WP_Role) {
// every role should at least be able to read
$new_role->add_cap( 'read' );
return new \WP_REST_Response($this->_prepare_item_for_response($role_slug, $name, $new_role->capabilities, $request), 201);
}

View File

@ -483,6 +483,22 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
}
function test_new_role_can_read() {
$request = new \WP_REST_Request('POST', $this->namespace . '/roles');
$request->set_query_params(['name' => 'New role']);
$create = $this->server->dispatch($request);
$this->assertEquals( 201, $create->get_status() );
$role = get_role('tainacan-new-role');
$this->assertTrue( $role->has_cap( 'read' ) );
}
}
?>