Reimplements register checks / Clear the maps on admin destroy

Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
Convly 2020-11-26 12:22:11 +01:00
parent 2f7615092a
commit c8a3d29e9c
5 changed files with 29 additions and 7 deletions

View File

@ -25,6 +25,7 @@ module.exports = async () => {
await strapi.admin.services.user.displayWarningIfUsersDontHaveRole();
strapi.admin.destroy = async () => {
strapi.admin.services.permission.conditionProvider.clear();
strapi.admin.services.permission.actionProvider.clear();
};
};

View File

@ -1,5 +1,6 @@
'use strict';
const { yup } = require('strapi-utils');
const { validateRegisterProviderAction } = require('../../validation/action-provider');
const { getActionId, createAction } = require('../../domain/action');
@ -54,6 +55,11 @@ const createActionProvider = () => {
validateRegisterProviderAction(newActions);
newActions.forEach(newAction => {
const actionId = getActionId(newAction);
if (actions.has(actionId)) {
throw new yup.ValidationError(
`Duplicated action id: ${actionId}. You may want to change the actions name.`
);
}
actions.set(actionId, createAction(newAction));

View File

@ -19,6 +19,10 @@ module.exports = () => {
throw new Error(`You can't register new conditions outside of the bootstrap function.`);
}
if (this.has(condition.name, condition.plugin)) {
throw new Error(`Duplicated condition id: ${getConditionId(condition)}.`);
}
registry.set(conditionId, createCondition(condition));
return this;
},
@ -77,5 +81,12 @@ module.exports = () => {
getAllIds() {
return Array.from(registry.keys());
},
/**
* Clear the actions map
*/
clear() {
registry.clear();
},
};
};

View File

@ -70,9 +70,11 @@ describe('Admin User CRUD (e2e)', () => {
// Cleanup actions
afterAll(async () => {
if (edition === 'EE') {
await utils.deleteRolesById([testData.role.id]);
}
await strapi.destroy();
});
}, 60000);
test('1. Creates a user (wrong body)', async () => {
const body = {

View File

@ -34,15 +34,17 @@ describe('Content Type Builder - Content types', () => {
'ct-with-dp',
];
await modelsUtils.cleanupModels(modelsName);
await modelsUtils.deleteContentTypes(modelsName);
await modelsUtils.cleanupModels(modelsName, { strapi });
await modelsUtils.deleteContentTypes(modelsName, { strapi });
await strapi.destroy();
}, 60000);
describe('Collection Types', () => {
const testCollectionTypeUID = 'application::test-collection-type.test-collection-type';
const ctWithDpUID = 'application::ct-with-dp.ct-with-dp';
test('Successfull creation of a collection type', async () => {
test('Successful creation of a collection type', async () => {
const res = await rq({
method: 'POST',
url: '/content-type-builder/content-types',
@ -66,7 +68,7 @@ describe('Content Type Builder - Content types', () => {
});
});
test('Get collection type returns full schema and informations', async () => {
test('Get collection type returns full schema and information', async () => {
const res = await rq({
method: 'GET',
url: `/content-type-builder/content-types/${testCollectionTypeUID}`,
@ -115,7 +117,7 @@ describe('Content Type Builder - Content types', () => {
describe('Single Types', () => {
const singleTypeUID = 'application::test-single-type.test-single-type';
test('Successfull creation of a single type', async () => {
test('Successfusl creation of a single type', async () => {
const res = await rq({
method: 'POST',
url: '/content-type-builder/content-types',