Merge pull request #13705 from strapi/fix/cm-relations-permissions

CellContent: Fix relations, if a user does not have read permissions
This commit is contained in:
Gustav Hansen 2022-07-06 16:31:12 +02:00 committed by GitHub
commit e2a285cfa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -45,7 +45,7 @@ export default function hasContent(type, content, metadatas, fieldSchema) {
return !isEmpty(content);
}
return content.count > 0;
return content?.count > 0;
}
/*

View File

@ -227,20 +227,27 @@ describe('hasContent', () => {
});
describe('relations', () => {
it('extracts content from multiple relations with content', () => {
it('extracts content from multiple relations with count=1', () => {
const normalizedContent = hasContent('relation', { count: 1 }, undefined, {
relation: 'manyToMany',
});
expect(normalizedContent).toEqual(true);
});
it('extracts content from multiple relations without content', () => {
it('extracts content from multiple relations with count=0', () => {
const normalizedContent = hasContent('relation', { count: 0 }, undefined, {
relation: 'manyToMany',
});
expect(normalizedContent).toEqual(false);
});
it('extracts content from multiple relations without content', () => {
const normalizedContent = hasContent('relation', undefined, undefined, {
relation: 'manyToMany',
});
expect(normalizedContent).toEqual(false);
});
it('extracts content from single relations with content', () => {
const normalizedContent = hasContent('relation', { id: 1 }, undefined, {
relation: 'oneToOne',