@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
30 lines (29 loc) • 1.05 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ALLOWED_RESOURCE_ACTIONS = void 0;
exports.getUserPermissionCacheKey = getUserPermissionCacheKey;
exports.getUserPermissionsFromAllowHeader = getUserPermissionsFromAllowHeader;
const ALLOWED_RESOURCE_ACTIONS = exports.ALLOWED_RESOURCE_ACTIONS = ['create', 'read', 'update', 'delete'];
function getUserPermissionsFromAllowHeader(allowedMethods) {
const permissions = {};
if (!allowedMethods) {
return permissions;
}
const methods = {
create: 'POST',
read: 'GET',
update: 'PUT',
delete: 'DELETE'
};
for (const [actionName, methodName] of Object.entries(methods)) {
permissions[actionName] = allowedMethods.includes(methodName);
}
return permissions;
}
function getUserPermissionCacheKey(action, resource, id) {
const key = (typeof resource === 'object' ? [action, resource.kind, resource.name, resource.id] : [action, resource, id]).filter(Boolean).join('/');
return key;
}
//# sourceMappingURL=user-permissions.js.map
;