mirror of
https://github.com/strapi/strapi.git
synced 2025-07-23 09:00:19 +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>
121 lines
3.2 KiB
JavaScript
121 lines
3.2 KiB
JavaScript
'use strict';
|
|
|
|
const { createTestBuilder } = require('../../../test/helpers/builder');
|
|
const { createStrapiInstance } = require('../../../test/helpers/strapi');
|
|
const { createAuthRequest } = require('../../../test/helpers/request');
|
|
const modelsUtils = require('../../../test/helpers/models');
|
|
|
|
const builder = createTestBuilder();
|
|
let strapi;
|
|
let rq;
|
|
let data = {
|
|
dogs: [],
|
|
};
|
|
|
|
const dogModel = {
|
|
draftAndPublish: false,
|
|
attributes: {
|
|
name: {
|
|
type: 'string',
|
|
required: false,
|
|
},
|
|
},
|
|
connection: 'default',
|
|
name: 'dog',
|
|
description: '',
|
|
collectionName: '',
|
|
};
|
|
|
|
const dogs = [
|
|
{
|
|
name: null,
|
|
},
|
|
{
|
|
name: 'Atos',
|
|
},
|
|
];
|
|
|
|
const restart = async () => {
|
|
await strapi.destroy();
|
|
strapi = await createStrapiInstance();
|
|
rq = await createAuthRequest({ strapi });
|
|
};
|
|
|
|
describe('Migration - required attribute', () => {
|
|
beforeAll(async () => {
|
|
await builder
|
|
.addContentType(dogModel)
|
|
.addFixtures(dogModel.name, dogs)
|
|
.build();
|
|
|
|
strapi = await createStrapiInstance();
|
|
rq = await createAuthRequest({ strapi });
|
|
|
|
data.dogs = builder.sanitizedFixturesFor(dogModel.name, strapi);
|
|
}, 60000);
|
|
|
|
afterAll(async () => {
|
|
await strapi.destroy();
|
|
await builder.cleanup();
|
|
}, 60000);
|
|
|
|
describe('Required: false -> true', () => {
|
|
test('Can be null before migration', async () => {
|
|
let { body } = await rq({
|
|
method: 'GET',
|
|
url: '/content-manager/collection-types/application::dog.dog',
|
|
});
|
|
expect(body.results.length).toBe(2);
|
|
const dogWithNameNull = body.results.find(dog => dog.name === null);
|
|
expect(dogWithNameNull).toBeTruthy();
|
|
});
|
|
|
|
test('Cannot create an entry with null after migration', async () => {
|
|
// remove null values otherwise the migration would fail
|
|
|
|
const { body } = await rq({
|
|
method: 'PUT',
|
|
url: `/content-manager/collection-types/application::dog.dog/${data.dogs[0].id}`,
|
|
body: { name: 'Nelson' },
|
|
});
|
|
data.dogs[0] = body;
|
|
|
|
// migration
|
|
const schema = await modelsUtils.getContentTypeSchema(dogModel.name, { strapi });
|
|
schema.attributes.name.required = true;
|
|
|
|
await modelsUtils.modifyContentType(schema, { strapi });
|
|
await restart();
|
|
|
|
// Try to create an entry with null
|
|
const res = await rq({
|
|
method: 'POST',
|
|
url: '/content-manager/collection-types/application::dog.dog',
|
|
body: { name: null },
|
|
});
|
|
expect(res.body.message).toBe('ValidationError');
|
|
}, 60000);
|
|
});
|
|
|
|
describe('Required: true -> false', () => {
|
|
test('Can create an entry with null after migration', async () => {
|
|
// migration
|
|
const schema = await modelsUtils.getContentTypeSchema(dogModel.name, { strapi });
|
|
schema.attributes.name.required = false;
|
|
|
|
await modelsUtils.modifyContentType(schema, { strapi });
|
|
await restart();
|
|
|
|
// Try to create an entry with null
|
|
const res = await rq({
|
|
url: `/content-manager/collection-types/application::dog.dog`,
|
|
method: 'POST',
|
|
body: { name: null },
|
|
});
|
|
|
|
expect(res.body).toMatchObject({ name: null });
|
|
data.dogs.push(res.body);
|
|
}, 60000);
|
|
});
|
|
});
|