mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 07:33:17 +00:00
UID is always localized in i18n
This commit is contained in:
parent
54b51d9d51
commit
f2cddb4c15
@ -114,6 +114,21 @@ describe('content-types service', () => {
|
||||
})
|
||||
).toEqual(['stars', 'price']);
|
||||
});
|
||||
|
||||
test('Consider uid to always be localized', () => {
|
||||
expect(
|
||||
getNonLocalizedAttributes({
|
||||
attributes: {
|
||||
price: {
|
||||
type: 'integer',
|
||||
},
|
||||
slug: {
|
||||
type: 'uid',
|
||||
},
|
||||
},
|
||||
})
|
||||
).toEqual(['price']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getValidLocale', () => {
|
||||
|
||||
@ -6,6 +6,7 @@ const {
|
||||
isRelationalAttribute,
|
||||
getVisibleAttributes,
|
||||
isMediaAttribute,
|
||||
isTypedAttribute,
|
||||
} = require('strapi-utils').contentTypes;
|
||||
const { getService } = require('../utils');
|
||||
|
||||
@ -82,7 +83,9 @@ const isLocalizedAttribute = (model, attributeName) => {
|
||||
const attribute = model.attributes[attributeName];
|
||||
|
||||
return (
|
||||
isLocalized(attribute) || (isRelationalAttribute(attribute) && !isMediaAttribute(attribute))
|
||||
isLocalized(attribute) ||
|
||||
(isRelationalAttribute(attribute) && !isMediaAttribute(attribute)) ||
|
||||
isTypedAttribute(attribute, 'uid')
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
const {
|
||||
isPrivateAttribute,
|
||||
isTypedAttribute,
|
||||
getPrivateAttributes,
|
||||
getVisibleAttributes,
|
||||
getNonWritableAttributes,
|
||||
@ -257,4 +258,18 @@ describe('Content types utils', () => {
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('isTypedAttribute', () => {
|
||||
test('Returns false if attribute does not have a type', () => {
|
||||
expect(isTypedAttribute({})).toBe(false);
|
||||
});
|
||||
|
||||
test('Returns true if attribute type matches passed type', () => {
|
||||
expect(isTypedAttribute({ type: 'test' }, 'test')).toBe(true);
|
||||
});
|
||||
|
||||
test('Returns false if type do not match', () => {
|
||||
expect(isTypedAttribute({ type: 'test' }, 'other-type')).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -191,6 +191,15 @@ const getGlobalId = (model, modelName, prefix) => {
|
||||
const isRelationalAttribute = attribute =>
|
||||
_.has(attribute, 'model') || _.has(attribute, 'collection');
|
||||
|
||||
/**
|
||||
* Checks if an attribute is of type `type`
|
||||
* @param {*} attribute
|
||||
* @param {*} type
|
||||
*/
|
||||
const isTypedAttribute = (attribute, type) => {
|
||||
return _.has(attribute, 'type') && attribute.type === type;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a route prefix for a contentType
|
||||
* @param {object} contentType
|
||||
@ -206,6 +215,7 @@ module.exports = {
|
||||
isScalarAttribute,
|
||||
isMediaAttribute,
|
||||
isRelationalAttribute,
|
||||
isTypedAttribute,
|
||||
getPrivateAttributes,
|
||||
getTimestampsAttributes,
|
||||
isPrivateAttribute,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user