mirror of
https://github.com/strapi/strapi.git
synced 2025-11-12 00:03:40 +00:00
don't copy published_at as a non-localized-field (#9761)
This commit is contained in:
parent
2c3bf778a3
commit
ddd4b37fb2
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const { PUBLISHED_AT_ATTRIBUTE } = require('strapi-utils').contentTypes.constants;
|
||||||
|
|
||||||
const { getService } = require('../../utils');
|
const { getService } = require('../../utils');
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ module.exports = () => {
|
|||||||
configurable: false,
|
configurable: false,
|
||||||
visible: false,
|
visible: false,
|
||||||
collection: modelName,
|
collection: modelName,
|
||||||
populate: ['id', 'locale', 'published_at'],
|
populate: ['id', 'locale', PUBLISHED_AT_ATTRIBUTE],
|
||||||
});
|
});
|
||||||
|
|
||||||
_.set(attributes, 'locale', {
|
_.set(attributes, 'locale', {
|
||||||
|
|||||||
@ -76,6 +76,42 @@ describe('content-types service', () => {
|
|||||||
})
|
})
|
||||||
).toEqual(['stars', 'price']);
|
).toEqual(['stars', 'price']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Consider locale, localizations & published_at as localized', () => {
|
||||||
|
expect(
|
||||||
|
getNonLocalizedAttributes({
|
||||||
|
uid: 'test-model',
|
||||||
|
attributes: {
|
||||||
|
title: {
|
||||||
|
type: 'string',
|
||||||
|
pluginOptions: {
|
||||||
|
i18n: {
|
||||||
|
localized: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
stars: {
|
||||||
|
type: 'integer',
|
||||||
|
},
|
||||||
|
price: {
|
||||||
|
type: 'integer',
|
||||||
|
},
|
||||||
|
locale: {
|
||||||
|
type: 'string',
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
|
localizations: {
|
||||||
|
collection: 'test-model',
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
|
published_at: {
|
||||||
|
type: 'datetime',
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
).toEqual(['stars', 'price']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getValidLocale', () => {
|
describe('getValidLocale', () => {
|
||||||
@ -329,7 +365,7 @@ describe('content-types service', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('copyNonLocalizedAttributes', () => {
|
describe('copyNonLocalizedAttributes', () => {
|
||||||
test('Does not copy locale & localizations', () => {
|
test('Does not copy locale, localizations & published_at', () => {
|
||||||
const model = {
|
const model = {
|
||||||
attributes: {
|
attributes: {
|
||||||
title: {
|
title: {
|
||||||
@ -349,9 +385,15 @@ describe('content-types service', () => {
|
|||||||
},
|
},
|
||||||
locale: {
|
locale: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
visible: false,
|
||||||
},
|
},
|
||||||
localizations: {
|
localizations: {
|
||||||
collection: 'test-model',
|
collection: 'test-model',
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
|
published_at: {
|
||||||
|
type: 'datetime',
|
||||||
|
visible: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -364,6 +406,7 @@ describe('content-types service', () => {
|
|||||||
description: 'My super description',
|
description: 'My super description',
|
||||||
locale: 'en',
|
locale: 'en',
|
||||||
localizations: [1, 2, 3],
|
localizations: [1, 2, 3],
|
||||||
|
published_at: '2021-03-18T09:47:37.557Z',
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = copyNonLocalizedAttributes(model, input);
|
const result = copyNonLocalizedAttributes(model, input);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const { has, prop, isNil } = require('lodash/fp');
|
const { has, prop, isNil } = require('lodash/fp');
|
||||||
const { cloneDeepWith, pick, pipe } = require('lodash/fp');
|
const { cloneDeepWith, pick, pipe } = require('lodash/fp');
|
||||||
const { isRelationalAttribute } = require('strapi-utils').contentTypes;
|
const { isRelationalAttribute, getVisibleAttributes } = require('strapi-utils').contentTypes;
|
||||||
const { getService } = require('../utils');
|
const { getService } = require('../utils');
|
||||||
|
|
||||||
const isLocalized = modelOrAttribute => {
|
const isLocalized = modelOrAttribute => {
|
||||||
@ -72,9 +72,9 @@ const isLocalizedAttribute = (model, attributeName) => {
|
|||||||
* @returns {string[]}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
const getNonLocalizedAttributes = model => {
|
const getNonLocalizedAttributes = model => {
|
||||||
return Object.keys(model.attributes)
|
return getVisibleAttributes(model).filter(
|
||||||
.filter(attributeName => !['locale', 'localizations'].includes(attributeName))
|
attributeName => !isLocalizedAttribute(model, attributeName)
|
||||||
.filter(attributeName => !isLocalizedAttribute(model, attributeName));
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeIds = cloneDeepWith(value => {
|
const removeIds = cloneDeepWith(value => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user