mirror of
https://github.com/strapi/strapi.git
synced 2025-08-06 15:53:11 +00:00

* Add a domain layer for the permission, rework the engine handling of the permissions Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Add permissions-fields-to-properties migration for the admin Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Removes useless console.log Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Remove debug logLevel from provider-login.test.e2e.js Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Adds the new layout for the GET permissions, allow to subscribe to actionRegistered events, adds i18n handlers Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Fix typo Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Update permissions validators Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Update unit tests Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Update integrations test + fix some validation issues Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Change plugins & settings section format for the permissions layout * only return locales property to localized subjects for the permission's layout * Do not send the locales property to the permission's layout when there is no locales created * Add the 'locales' property to publish & delete routes * Fix unwanted mutation of the sections builder states on multiple builds * Fix units tests with (new engine) * Fix admin-role e2e test - Add locales property to the update payload * fix e2e testsé * Update e2e snapshots * Fix unit test for i18n bootstrap * Add mocks for i18n/bootstrap test * Fix has-locale condition & updatePermission validator * Avoid mutation in migration, always authorize super admin for has-locales condition * Rework rbac domain objects, add a hook module and a provider factory * Remove old providers * Update the admin services & tests for the new rbac domain & providers * Fix tests, bootstrap functions & services following rbac domain rework * Update migration runner * PR comments Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Remove useless console.log * Fix sanitizeCondition bug * Section builder rework * Add test for the section-builder section & add jsdoc for the permission domain * pr comments (without the migrations) * fix fields-to-properties migration * Add jsdoc for the sections-builder * Moves createBoundAbstractDomain from permission domain to the engine service * Remove debug logLevel for admin role test (e2e) * Fix core-store * Fix hooks & move business logic from i18n bootstrap to dedicated services * add route get-non-localized-fields * use write and read permission * refacto * add input validator * add route doc * handle ST Co-authored-by: Pierre Noël <petersg83@gmail.com> Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
100 lines
2.1 KiB
JavaScript
100 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
const { eq, remove, cloneDeep } = require('lodash/fp');
|
|
|
|
/**
|
|
* @typedef Hook
|
|
* @property {Array<Function>} _handlers - A registry of handler used by the hook
|
|
* @property {function(Function):Hook} register - Register a new handler into the hook's registry
|
|
* @property {function(Function):Hook} delete- Delete the given handler from the hook's registry
|
|
* @property {Function} call - Not implemented by default, can be replaced by any implementation.
|
|
*/
|
|
|
|
/**
|
|
* Create a default Strapi hook
|
|
* @return {Hook}
|
|
*/
|
|
const createHook = () => {
|
|
const state = {
|
|
handlers: [],
|
|
};
|
|
|
|
return {
|
|
get handlers() {
|
|
return state.handlers;
|
|
},
|
|
|
|
register: handler => {
|
|
state.handlers.push(handler);
|
|
},
|
|
|
|
delete: handler => {
|
|
state.handlers = remove(eq(handler), state.handlers);
|
|
},
|
|
|
|
call() {
|
|
throw new Error('Method not implemented');
|
|
},
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Create an async series hook.
|
|
* Upon execution, it will execute every handler in order with the same context
|
|
* @return {Hook}
|
|
*/
|
|
const createAsyncSeriesHook = () => ({
|
|
...createHook(),
|
|
|
|
async call(context) {
|
|
for (const handler of this.handlers) {
|
|
await handler(context);
|
|
}
|
|
},
|
|
});
|
|
|
|
/**
|
|
* Create an async series waterfall hook.
|
|
* Upon execution, it will execute every handler in order and pass the return value of the last handler to the next one
|
|
* @return {Hook}
|
|
*/
|
|
const createAsyncSeriesWaterfallHook = () => ({
|
|
...createHook(),
|
|
|
|
async call(param) {
|
|
let res = param;
|
|
|
|
for (const handler of this.handlers) {
|
|
res = await handler(res);
|
|
}
|
|
|
|
return res;
|
|
},
|
|
});
|
|
|
|
/**
|
|
* Create an async parallel hook.
|
|
* Upon execution, it will execute every registered handler in band.
|
|
* @return {Hook}
|
|
*/
|
|
const createAsyncParallelHook = () => ({
|
|
...createHook(),
|
|
|
|
call(context) {
|
|
const promises = this.handlers.map(handler => handler(cloneDeep(context)));
|
|
|
|
return Promise.all(promises);
|
|
},
|
|
});
|
|
|
|
module.exports = {
|
|
// Internal utils
|
|
internals: {
|
|
createHook,
|
|
},
|
|
// Hooks
|
|
createAsyncSeriesHook,
|
|
createAsyncSeriesWaterfallHook,
|
|
createAsyncParallelHook,
|
|
};
|