mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
remove editRelations from configuration routes
This commit is contained in:
parent
db1bf34f2a
commit
176acfef4c
@ -3,7 +3,6 @@
|
||||
const { yup } = require('@strapi/utils');
|
||||
const {
|
||||
isListable,
|
||||
hasRelationAttribute,
|
||||
hasEditableAttribute,
|
||||
} = require('../../services/utils/configuration/attributes');
|
||||
/**
|
||||
@ -106,10 +105,6 @@ const createLayoutsSchema = (schema, opts = {}) => {
|
||||
hasEditableAttribute(schema, key)
|
||||
);
|
||||
|
||||
const relationAttributes = Object.keys(schema.attributes).filter(key =>
|
||||
hasRelationAttribute(schema, key)
|
||||
);
|
||||
|
||||
return yup.object().shape({
|
||||
edit: yup
|
||||
.array()
|
||||
@ -136,9 +131,5 @@ const createLayoutsSchema = (schema, opts = {}) => {
|
||||
.array()
|
||||
.of(yup.string().oneOf(validAttributes))
|
||||
.test(createArrayTest(opts)),
|
||||
editRelations: yup
|
||||
.array()
|
||||
.of(yup.string().oneOf(relationAttributes))
|
||||
.test(createArrayTest(opts)),
|
||||
});
|
||||
};
|
||||
|
||||
@ -0,0 +1,151 @@
|
||||
'use strict';
|
||||
|
||||
// Helpers.
|
||||
const { createTestBuilder } = require('../../../../../../test/helpers/builder');
|
||||
const { createStrapiInstance } = require('../../../../../../test/helpers/strapi');
|
||||
const form = require('../../../../../../test/helpers/generators');
|
||||
const { createAuthRequest } = require('../../../../../../test/helpers/request');
|
||||
|
||||
const builder = createTestBuilder();
|
||||
let strapi;
|
||||
let rq;
|
||||
|
||||
const restart = async () => {
|
||||
await strapi.destroy();
|
||||
strapi = await createStrapiInstance();
|
||||
rq = await createAuthRequest({ strapi });
|
||||
};
|
||||
|
||||
describe('Content Manager - Configuration', () => {
|
||||
beforeAll(async () => {
|
||||
await builder.addContentTypes([form.article]).build();
|
||||
|
||||
strapi = await createStrapiInstance();
|
||||
rq = await createAuthRequest({ strapi });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await strapi.destroy();
|
||||
await builder.cleanup();
|
||||
});
|
||||
|
||||
test('List and edit layout cannot be empty', async () => {
|
||||
await rq({
|
||||
url: '/content-manager/content-types/api::article.article/configuration',
|
||||
method: 'PUT',
|
||||
body: {
|
||||
layouts: {
|
||||
edit: [],
|
||||
list: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await restart();
|
||||
|
||||
const { body } = await rq({
|
||||
url: '/content-manager/content-types/api::article.article/configuration',
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
expect(body.data.contentType.layouts.edit).toStrictEqual([
|
||||
[
|
||||
{
|
||||
name: 'title',
|
||||
size: 6,
|
||||
},
|
||||
{
|
||||
name: 'date',
|
||||
size: 4,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'jsonField',
|
||||
size: 12,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'content',
|
||||
size: 12,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'author',
|
||||
size: 6,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(body.data.contentType.layouts.list).toStrictEqual(['id', 'title', 'date', 'author']);
|
||||
});
|
||||
|
||||
test('Update list and edit layout (with relation)', async () => {
|
||||
await rq({
|
||||
url: '/content-manager/content-types/api::article.article/configuration',
|
||||
method: 'PUT',
|
||||
body: {
|
||||
layouts: {
|
||||
edit: [
|
||||
[
|
||||
{
|
||||
name: 'title',
|
||||
size: 6,
|
||||
},
|
||||
{
|
||||
name: 'date',
|
||||
size: 4,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'jsonField',
|
||||
size: 12,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'author',
|
||||
size: 6,
|
||||
},
|
||||
],
|
||||
],
|
||||
list: ['id', 'title', 'author'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await restart();
|
||||
|
||||
const { body } = await rq({
|
||||
url: '/content-manager/content-types/api::article.article/configuration',
|
||||
method: 'GET',
|
||||
});
|
||||
expect(body.data.contentType.layouts.edit).toStrictEqual([
|
||||
[
|
||||
{
|
||||
name: 'title',
|
||||
size: 6,
|
||||
},
|
||||
{
|
||||
name: 'date',
|
||||
size: 4,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'jsonField',
|
||||
size: 12,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'author',
|
||||
size: 6,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(body.data.contentType.layouts.list).toStrictEqual(['id', 'title', 'author']);
|
||||
});
|
||||
});
|
||||
@ -87,7 +87,6 @@ describe('Content Manager - Update Layout', () => {
|
||||
body: {
|
||||
layouts: {
|
||||
edit: payload,
|
||||
editRelations: [],
|
||||
list: [],
|
||||
},
|
||||
},
|
||||
@ -132,7 +131,6 @@ describe('Content Manager - Update Layout', () => {
|
||||
body: {
|
||||
layouts: {
|
||||
edit: payload,
|
||||
editRelations: [],
|
||||
list: [],
|
||||
},
|
||||
},
|
||||
@ -198,7 +196,6 @@ describe('Content Manager - Update Layout', () => {
|
||||
body: {
|
||||
layouts: {
|
||||
edit: payload,
|
||||
editRelations: [],
|
||||
list: [],
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,75 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
// Helpers.
|
||||
const { createTestBuilder } = require('../../../../../../test/helpers/builder');
|
||||
const { createStrapiInstance } = require('../../../../../../test/helpers/strapi');
|
||||
const form = require('../../../../../../test/helpers/generators');
|
||||
const { createAuthRequest } = require('../../../../../../test/helpers/request');
|
||||
|
||||
const builder = createTestBuilder();
|
||||
let strapi;
|
||||
let rq;
|
||||
|
||||
const restart = async () => {
|
||||
await strapi.destroy();
|
||||
strapi = await createStrapiInstance();
|
||||
rq = await createAuthRequest({ strapi });
|
||||
};
|
||||
|
||||
describe('Content Manager - Hide relations', () => {
|
||||
beforeAll(async () => {
|
||||
await builder.addContentTypes([form.article]).build();
|
||||
|
||||
strapi = await createStrapiInstance();
|
||||
rq = await createAuthRequest({ strapi });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await strapi.destroy();
|
||||
await builder.cleanup();
|
||||
});
|
||||
|
||||
test('Hide relations', async () => {
|
||||
await rq({
|
||||
url: '/content-manager/content-types/api::article.article/configuration',
|
||||
method: 'PUT',
|
||||
body: {
|
||||
layouts: {
|
||||
edit: [],
|
||||
editRelations: [],
|
||||
list: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { body } = await rq({
|
||||
url: '/content-manager/content-types/api::article.article/configuration',
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
expect(body.data.contentType.layouts.editRelations).toStrictEqual([]);
|
||||
});
|
||||
|
||||
test('Hide relations after server restart', async () => {
|
||||
await rq({
|
||||
url: '/content-manager/content-types/api::article.article/configuration',
|
||||
method: 'PUT',
|
||||
body: {
|
||||
layouts: {
|
||||
edit: [],
|
||||
editRelations: [],
|
||||
list: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await restart();
|
||||
|
||||
const { body } = await rq({
|
||||
url: '/content-manager/content-types/api::article.article/configuration',
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
expect(body.data.contentType.layouts.editRelations).toStrictEqual([]);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user