mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 23:24:03 +00:00
Revert action/subject to action only
This commit is contained in:
parent
9aff190dc3
commit
7d40f78384
@ -30,26 +30,16 @@ module.exports = ({ strapi }) => ({
|
||||
},
|
||||
|
||||
/**
|
||||
* Transform a Users-Permissions' permission into a content API one
|
||||
*
|
||||
* @example
|
||||
* const upPermission = { action: 'api::foo.foo.find' };
|
||||
*
|
||||
* const permission = toContentAPIPermission(upPermission);
|
||||
* // ^? { action: 'find', subject: 'api::foo.foo' }
|
||||
* Transform a Users-Permissions' action into a content API one
|
||||
*
|
||||
* @param {object} permission
|
||||
* @param {string} permission.action
|
||||
*
|
||||
* @return {{ action: string, subject: string }}
|
||||
* @return {{ action: string }}
|
||||
*/
|
||||
toContentAPIPermission(permission) {
|
||||
const { action } = permission;
|
||||
const actionIndex = action.lastIndexOf('.');
|
||||
|
||||
return {
|
||||
action: action.slice(actionIndex + 1),
|
||||
subject: action.slice(0, actionIndex),
|
||||
};
|
||||
return { action };
|
||||
},
|
||||
});
|
||||
|
||||
@ -172,10 +172,7 @@ module.exports = ({ strapi }) => ({
|
||||
|
||||
// Register actions into the content API action provider
|
||||
// TODO: do this in the content API bootstrap phase instead
|
||||
allActions
|
||||
// 'api::foo.foo.find' => { action: 'find', subject: 'api.foo.foo' } => 'find';
|
||||
.map(action => getService('permission').toContentAPIPermission({ action }).action)
|
||||
.forEach(action => strapi.contentAPI.permissions.providers.action.register(action));
|
||||
allActions.forEach(action => strapi.contentAPI.permissions.providers.action.register(action));
|
||||
|
||||
await Promise.all(
|
||||
toDelete.map(action => {
|
||||
|
||||
@ -99,11 +99,7 @@ const verify = async (auth, config) => {
|
||||
// Make sure we're dealing with an array
|
||||
castArray,
|
||||
// Transform the scope array into an action array
|
||||
map(scope => ({ action: scope })),
|
||||
// Map the users-permissions permissions into content API permissions
|
||||
map(getService('permission').toContentAPIPermission),
|
||||
// Check that every required scope is allowed by the ability
|
||||
every(({ action, subject }) => ability.can(action, subject))
|
||||
every(scope => ability.can(scope))
|
||||
)(config.scope);
|
||||
|
||||
if (!isAllowed) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user