fix capabilities validation api roles #274

This commit is contained in:
leogermani 2019-12-10 16:51:05 -03:00
parent db269db8ca
commit a472915b11
2 changed files with 17 additions and 1 deletions

View File

@ -333,7 +333,7 @@ class REST_Roles_Controller extends REST_Controller {
public function validate_roles_capabilities_arg($value, $request, $param) {
if ( is_array($value) ) {
foreach ($value as $cap => $val) {
if ( ! in_array($cap, \tainacan_roles()->get_all_caps_slugs() ) ) {
if ( ! in_array( \tainacan_roles()->get_cap_generic_name($cap), \tainacan_roles()->get_all_caps_slugs() ) ) {
return false;
}
}

View File

@ -156,6 +156,22 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals( 400, $response->get_status() );
$request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/tainacan-new-role');
$request->set_query_params(
[
'name' => 'Changed name',
'capabilities' => [
'tnc_col_23_edit_items' => true
]
]
);
$response = $this->server->dispatch($request);
$this->assertEquals( 200, $response->get_status() );
}
public function test_get_role() {