add tnc_col_all_* capabilities support #274

This commit is contained in:
Leo Germani 2019-10-21 11:44:26 -03:00
parent 7e91b4bd69
commit 807fe2759d
2 changed files with 21 additions and 1 deletions

View File

@ -186,7 +186,14 @@ class Roles {
$col_id = preg_replace('/[a-z_]+(\d+)[a-z_]+?$/', '$1', $cap );
if ( $user->has_cap('manage_tainacan_collection_' . $col_id) ) {
if ( ! is_numeric($col_id) ) {
continue;
}
// check for tnc_col_all_* capabilities
$all_collections_cap = preg_replace('/([a-z_]+)(\d+)([a-z_]+?)$/', '${1}all${3}', $cap );
if ( $user->has_cap('manage_tainacan_collection_' . $col_id) || $user->has_cap($all_collections_cap) ) {
$allcaps = array_merge($allcaps, [ $cap => true ]);
} else {
// check if the user is the owner

View File

@ -278,6 +278,19 @@ class Capabilities extends TAINACAN_UnitTestCase {
}
function test_super_all_collection () {
$this->assertFalse( user_can($this->subscriber, 'tnc_col_25_read_private_filters') );
$this->subscriber->add_cap('tnc_col_all_read_private_filters');
$this->subscriber->get_role_caps();
$this->assertTrue( user_can($this->subscriber, 'tnc_col_25_read_private_filters') );
$this->assertTrue( user_can($this->subscriber, 'tnc_col_36_read_private_filters') );
$this->assertFalse( user_can($this->subscriber, 'tnc_col_25_edit_posts') );
}
// function test_items_capabilities() {
//
// $collection = $this->tainacan_entity_factory->create_entity(