add supercaps to caps definitions #274

This commit is contained in:
leogermani 2019-11-28 18:16:17 -03:00
parent e077eb971b
commit afc912c9a0
2 changed files with 190 additions and 43 deletions

View File

@ -436,16 +436,14 @@ class REST_Roles_Controller extends REST_Controller {
} }
// inherited roles // inherited roles
$supercaps = []; $supercaps = $c['supercaps'];
if ( ( $cap == 'manage_tainacan_collection_%d' || \strpos($cap, 'tnc_col_') === 0 ) && $collection_id ) {
$supercaps = [
'manage_tainacan_collection_all',
'manage_tainacan_collection_' . $collection_id,
str_replace('%d', 'all', $cap)
];
}
$supercaps[] = 'manage_tainacan';
foreach ($supercaps as $supercap) { foreach ($supercaps as $supercap) {
if ($collection_id) {
$supercap = str_replace('%d', $collection_id, $supercap);
}
if ( array_key_exists($supercap, $role['capabilities']) ) { if ( array_key_exists($supercap, $role['capabilities']) ) {
$caps_return[$realcap]['roles_inherited'][$slug] = [ $caps_return[$realcap]['roles_inherited'][$slug] = [

View File

@ -38,12 +38,16 @@ class Roles {
'manage_tainacan' => [ 'manage_tainacan' => [
'display_name' => __('Manage Tainacan', 'tainacan'), 'display_name' => __('Manage Tainacan', 'tainacan'),
'description' => __('Manage all Tainacan features and all Collections', 'tainacan'), 'description' => __('Manage all Tainacan features and all Collections', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => []
], ],
'tnc_rep_edit_users' => [ 'tnc_rep_edit_users' => [
'display_name' => __('Manage Users', 'tainacan'), 'display_name' => __('Manage Users', 'tainacan'),
'description' => __('Manage users roles and permissions', 'tainacan'), 'description' => __('Manage users roles and permissions', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_edit_collections' => [ 'tnc_rep_edit_collections' => [
'display_name' => __('Create Collections', 'tainacan'), 'display_name' => __('Create Collections', 'tainacan'),
@ -51,77 +55,122 @@ class Roles {
'dependencies' => [ 'dependencies' => [
'upload_files' 'upload_files'
], ],
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_delete_collections' => [ 'tnc_rep_delete_collections' => [
'display_name' => __('Delete Collections', 'tainacan'), 'display_name' => __('Delete Collections', 'tainacan'),
'description' => __('Delete their own collections from the repository', 'tainacan'), 'description' => __('Delete their own collections from the repository', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_edit_taxonomies' => [ 'tnc_rep_edit_taxonomies' => [
'display_name' => __('Create and edit taxonomies', 'tainacan'), 'display_name' => __('Create and edit taxonomies', 'tainacan'),
'description' => __('Create new taxonomies and edit its terms', 'tainacan'), 'description' => __('Create new taxonomies and edit its terms', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_edit_others_taxonomies' => [ 'tnc_rep_edit_others_taxonomies' => [
'display_name' => __('Edit all Taxonomies', 'tainacan'), 'display_name' => __('Edit all Taxonomies', 'tainacan'),
'description' => __('Edit all taxonomies and terms, including taxonomies created by other users', 'tainacan'), 'description' => __('Edit all taxonomies and terms, including taxonomies created by other users', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_delete_taxonomies' => [ 'tnc_rep_delete_taxonomies' => [
'display_name' => __('Delete Taxonomies', 'tainacan'), 'display_name' => __('Delete Taxonomies', 'tainacan'),
'description' => __('Delete taxonomies', 'tainacan'), 'description' => __('Delete taxonomies', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_delete_others_taxonomies' => [ 'tnc_rep_delete_others_taxonomies' => [
'display_name' => __('Delete all Taxonomies', 'tainacan'), 'display_name' => __('Delete all Taxonomies', 'tainacan'),
'description' => __('Delete all taxonomies and terms, including taxonomies created by other users', 'tainacan'), 'description' => __('Delete all taxonomies and terms, including taxonomies created by other users', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_edit_metadata' => [ 'tnc_rep_edit_metadata' => [
'display_name' => __('Manage Repository Metadata', 'tainacan'), 'display_name' => __('Manage Repository Metadata', 'tainacan'),
'description' => __('Create/edit metadata in repository level', 'tainacan'), 'description' => __('Create/edit metadata in repository level', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_edit_filters' => [ 'tnc_rep_edit_filters' => [
'display_name' => __('Manage Repository Filters', 'tainacan'), 'display_name' => __('Manage Repository Filters', 'tainacan'),
'description' => __('Create/edit filters in repository level', 'tainacan'), 'description' => __('Create/edit filters in repository level', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_delete_metadata' => [ 'tnc_rep_delete_metadata' => [
'display_name' => __('Delete Repository Metadata', 'tainacan'), 'display_name' => __('Delete Repository Metadata', 'tainacan'),
'description' => __('Delete metadata in repository level', 'tainacan'), 'description' => __('Delete metadata in repository level', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_delete_filters' => [ 'tnc_rep_delete_filters' => [
'display_name' => __('Delete Repository Filters', 'tainacan'), 'display_name' => __('Delete Repository Filters', 'tainacan'),
'description' => __('Delete filters in repository level', 'tainacan'), 'description' => __('Delete filters in repository level', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_read_private_collections' => [ 'tnc_rep_read_private_collections' => [
'display_name' => __('View private collections', 'tainacan'), 'display_name' => __('View private collections', 'tainacan'),
'description' => __('Access to view and browse private collections', 'tainacan'), 'description' => __('Access to view and browse private collections', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_read_private_taxonomies' => [ 'tnc_rep_read_private_taxonomies' => [
'display_name' => __('View private taxonomies', 'tainacan'), 'display_name' => __('View private taxonomies', 'tainacan'),
'description' => __('Access to private taxonomies information', 'tainacan'), 'description' => __('Access to private taxonomies information', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_read_private_metadata' => [ 'tnc_rep_read_private_metadata' => [
'display_name' => __('View private repository metadata', 'tainacan'), 'display_name' => __('View private repository metadata', 'tainacan'),
'description' => __('Access to private metadata in repository level', 'tainacan'), 'description' => __('Access to private metadata in repository level', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_read_private_filters' => [ 'tnc_rep_read_private_filters' => [
'display_name' => __('View private repository filters', 'tainacan'), 'display_name' => __('View private repository filters', 'tainacan'),
'description' => __('Access to private filters in repository level', 'tainacan'), 'description' => __('Access to private filters in repository level', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
'tnc_rep_read_logs' => [ 'tnc_rep_read_logs' => [
'display_name' => __('View Logs', 'tainacan'), 'display_name' => __('View Logs', 'tainacan'),
'description' => __('Access to activities logs. Note that activity logs might contain information on private collections, items and metadata.', 'tainacan'), 'description' => __('Access to activities logs. Note that activity logs might contain information on private collections, items and metadata.', 'tainacan'),
'scope' => 'repository' 'scope' => 'repository',
'supercaps' => [
'manage_tainacan'
]
], ],
/** /**
@ -132,52 +181,110 @@ class Roles {
'manage_tainacan_collection_%d' => [ 'manage_tainacan_collection_%d' => [
'display_name' => __('Manage Collection', 'tainacan'), 'display_name' => __('Manage Collection', 'tainacan'),
'description' => __('Manage all collection settings, items, metadata, filters, etc.', 'tainacan'), 'description' => __('Manage all collection settings, items, metadata, filters, etc.', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all'
]
], ],
'tnc_col_%d_edit_users' => [ 'tnc_col_%d_edit_users' => [
'display_name' => __('Edit users permissions', 'tainacan'), 'display_name' => __('Edit users permissions', 'tainacan'),
'description' => __('Configure which roles and users have permission to perform actions in this collection', 'tainacan'), 'description' => __('Configure which roles and users have permission to perform actions in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_edit_users',
]
], ],
'tnc_col_%d_bulk_edit' => [ 'tnc_col_%d_bulk_edit' => [
'display_name' => __('Bulk edit items', 'tainacan'), 'display_name' => __('Bulk edit items', 'tainacan'),
'description' => __('Access to the Bulk edit items feature.', 'tainacan'), 'description' => __('Access to the Bulk edit items feature.', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_bulk_edit',
]
], ],
'tnc_col_%d_edit_metadata' => [ 'tnc_col_%d_edit_metadata' => [
'display_name' => __('Manage metadata', 'tainacan'), 'display_name' => __('Manage metadata', 'tainacan'),
'description' => __('Create/edit metadata in this collection', 'tainacan'), 'description' => __('Create/edit metadata in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_edit_metadata',
]
], ],
'tnc_col_%d_edit_filters' => [ 'tnc_col_%d_edit_filters' => [
'display_name' => __('Manage filters', 'tainacan'), 'display_name' => __('Manage filters', 'tainacan'),
'description' => __('Create/edit filters in this collection', 'tainacan'), 'description' => __('Create/edit filters in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_edit_filters',
]
], ],
'tnc_col_%d_delete_metadata' => [ 'tnc_col_%d_delete_metadata' => [
'display_name' => __('Delete metadata', 'tainacan'), 'display_name' => __('Delete metadata', 'tainacan'),
'description' => __('Delete metadata in this collection', 'tainacan'), 'description' => __('Delete metadata in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_delete_metadata',
]
], ],
'tnc_col_%d_delete_filters' => [ 'tnc_col_%d_delete_filters' => [
'display_name' => __('Delete filters', 'tainacan'), 'display_name' => __('Delete filters', 'tainacan'),
'description' => __('Delete filters in this collection', 'tainacan'), 'description' => __('Delete filters in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_delete_filters',
]
], ],
'tnc_col_%d_read_private_metadata' => [ 'tnc_col_%d_read_private_metadata' => [
'display_name' => __('View private metadata', 'tainacan'), 'display_name' => __('View private metadata', 'tainacan'),
'description' => __('Access private metadata in this collection', 'tainacan'), 'description' => __('Access private metadata in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_read_private_metadata',
]
], ],
'tnc_col_%d_read_private_filters' => [ 'tnc_col_%d_read_private_filters' => [
'display_name' => __('View private filters', 'tainacan'), 'display_name' => __('View private filters', 'tainacan'),
'description' => __('Access private filters in this collection', 'tainacan'), 'description' => __('Access private filters in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_read_private_filters',
]
], ],
'tnc_col_%d_read_private_items' => [ 'tnc_col_%d_read_private_items' => [
'display_name' => __('View private items', 'tainacan'), 'display_name' => __('View private items', 'tainacan'),
'description' => __('Access to view private items in this collection', 'tainacan'), 'description' => __('Access to view private items in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_read_private_items',
]
], ],
'tnc_col_%d_edit_items' => [ 'tnc_col_%d_edit_items' => [
'display_name' => __('Edit items', 'tainacan'), 'display_name' => __('Edit items', 'tainacan'),
@ -185,7 +292,13 @@ class Roles {
'dependencies' => [ 'dependencies' => [
'upload_files' 'upload_files'
], ],
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_edit_items',
]
], ],
'tnc_col_%d_publish_items' => [ 'tnc_col_%d_publish_items' => [
'display_name' => __('Publish items', 'tainacan'), 'display_name' => __('Publish items', 'tainacan'),
@ -193,7 +306,13 @@ class Roles {
'dependencies' => [ 'dependencies' => [
'upload_files' 'upload_files'
], ],
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_publish_items',
]
], ],
'tnc_col_%d_edit_others_items' => [ 'tnc_col_%d_edit_others_items' => [
'display_name' => __('Edit others items', 'tainacan'), 'display_name' => __('Edit others items', 'tainacan'),
@ -201,7 +320,13 @@ class Roles {
'dependencies' => [ 'dependencies' => [
'upload_files' 'upload_files'
], ],
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_edit_others_items',
]
], ],
'tnc_col_%d_edit_published_items' => [ 'tnc_col_%d_edit_published_items' => [
'display_name' => __('Edit published items', 'tainacan'), 'display_name' => __('Edit published items', 'tainacan'),
@ -209,22 +334,46 @@ class Roles {
'dependencies' => [ 'dependencies' => [
'upload_files' 'upload_files'
], ],
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_edit_published_items',
]
], ],
'tnc_col_%d_delete_items' => [ 'tnc_col_%d_delete_items' => [
'display_name' => __('Delete items', 'tainacan'), 'display_name' => __('Delete items', 'tainacan'),
'description' => __('Delete items in this collection', 'tainacan'), 'description' => __('Delete items in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_delete_items',
]
], ],
'tnc_col_%d_delete_others_items' => [ 'tnc_col_%d_delete_others_items' => [
'display_name' => __('Delete others items', 'tainacan'), 'display_name' => __('Delete others items', 'tainacan'),
'description' => __('Delete items created by other users in this collection', 'tainacan'), 'description' => __('Delete items created by other users in this collection', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_delete_others_items',
]
], ],
'tnc_col_%d_delete_published_items' => [ 'tnc_col_%d_delete_published_items' => [
'display_name' => __('Delete published items', 'tainacan'), 'display_name' => __('Delete published items', 'tainacan'),
'description' => __('Delete items in this collection after they are published', 'tainacan'), 'description' => __('Delete items in this collection after they are published', 'tainacan'),
'scope' => 'collection' 'scope' => 'collection',
'supercaps' => [
'manage_tainacan',
'manage_tainacan_collection_all',
'manage_tainacan_collection_%d',
'tnc_col_all_delete_published_items',
]
], ],