mirror of
https://github.com/strapi/strapi.git
synced 2025-11-09 14:51:29 +00:00
Fix sanitizeEntity
This commit is contained in:
parent
87d79388c1
commit
c1369c7960
@ -9,10 +9,12 @@ const createRouteScopeGenerator = namespace => route => {
|
|||||||
if (typeof route.handler === 'string') {
|
if (typeof route.handler === 'string') {
|
||||||
const [controller, action] = route.handler.split('.');
|
const [controller, action] = route.handler.split('.');
|
||||||
|
|
||||||
_.defaultsDeep(route.config, {
|
_.defaultsDeep(route, {
|
||||||
|
config: {
|
||||||
auth: {
|
auth: {
|
||||||
scope: `${prefix}${controller}.${toLower(action)}`,
|
scope: `${prefix}${controller}.${toLower(action)}`,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -60,7 +60,9 @@ describe('Sanitize Entity', () => {
|
|||||||
attributes: {
|
attributes: {
|
||||||
...userModel.attributes,
|
...userModel.attributes,
|
||||||
article: {
|
article: {
|
||||||
collection: 'article',
|
type: 'relation',
|
||||||
|
relation: 'oneToOne',
|
||||||
|
target: 'article',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -48,8 +48,10 @@ const sanitizeEntity = (dataSource, options) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Relations
|
// Relations
|
||||||
const relation = attribute && (attribute.model || attribute.collection || attribute.component);
|
const isRelation = attribute && attribute.type === 'relation';
|
||||||
if (relation) {
|
if (isRelation) {
|
||||||
|
const relation = attribute && attribute.target;
|
||||||
|
|
||||||
if (_.isNil(value)) {
|
if (_.isNil(value)) {
|
||||||
return { ...acc, [key]: value };
|
return { ...acc, [key]: value };
|
||||||
}
|
}
|
||||||
@ -69,23 +71,18 @@ const sanitizeEntity = (dataSource, options) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let sanitizeFn;
|
let sanitizeFn;
|
||||||
if (relation === '*') {
|
if (attribute.relation && attribute.relation.toLowerCase().includes('morph')) {
|
||||||
sanitizeFn = entity => {
|
sanitizeFn = entity => {
|
||||||
if (_.isNil(entity) || !_.has(entity, '__contentType')) {
|
if (_.isNil(entity) || !_.has(entity, '__type')) {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sanitizeEntity(entity, {
|
return sanitizeEntity(entity, { model: strapi.getModel(entity.__type), ...baseOptions });
|
||||||
model: strapi.getModel(entity.__contentType),
|
|
||||||
...baseOptions,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
sanitizeFn = entity =>
|
sanitizeFn = entity => {
|
||||||
sanitizeEntity(entity, {
|
return sanitizeEntity(entity, { model: strapi.getModel(relation), ...baseOptions });
|
||||||
model: strapi.getModel(relation, attribute.plugin),
|
};
|
||||||
...baseOptions,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextVal = Array.isArray(value) ? value.map(sanitizeFn) : sanitizeFn(value);
|
const nextVal = Array.isArray(value) ? value.map(sanitizeFn) : sanitizeFn(value);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user