mirror of
https://github.com/strapi/strapi.git
synced 2025-08-05 23:40:04 +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>
67 lines
1.6 KiB
JavaScript
67 lines
1.6 KiB
JavaScript
'use strict';
|
|
const debug = require('debug')('strapi-database:migration');
|
|
const { isFunction, get } = require('lodash/fp');
|
|
|
|
class MigrationManager {
|
|
constructor(db) {
|
|
debug('Initialize migration manager');
|
|
this.db = db;
|
|
this.migrations = [];
|
|
}
|
|
|
|
register(migration) {
|
|
debug('Register migration');
|
|
this.migrations.push(migration);
|
|
}
|
|
|
|
async run(fn, options, context = {}) {
|
|
debug('Run migration');
|
|
await this.runBefore(options, context);
|
|
await fn(options, context);
|
|
await this.runAfter(options, context);
|
|
}
|
|
|
|
async shouldRun({ migration, step, options, context }) {
|
|
const method = migration[step];
|
|
const shouldRunMethod = get(`shouldRun.${step}`, migration, null);
|
|
|
|
if (!isFunction(method)) {
|
|
return false;
|
|
}
|
|
|
|
if (!isFunction(shouldRunMethod)) {
|
|
return true;
|
|
}
|
|
|
|
return shouldRunMethod(options, context);
|
|
}
|
|
|
|
async runBefore(options, context) {
|
|
debug('Run before migrations');
|
|
|
|
for (const migration of this.migrations) {
|
|
const willRunStep = await this.shouldRun({ migration, step: 'before', options, context });
|
|
|
|
if (willRunStep) {
|
|
await migration.before(options, context);
|
|
}
|
|
}
|
|
}
|
|
|
|
async runAfter(options, context) {
|
|
debug('Run after migrations');
|
|
|
|
for (const migration of this.migrations.slice(0).reverse()) {
|
|
const willRunStep = await this.shouldRun({ migration, step: 'after', options, context });
|
|
|
|
if (willRunStep) {
|
|
await migration.after(options, context);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = strapi => {
|
|
return new MigrationManager(strapi);
|
|
};
|