0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Allowed for index collection to have empty filter

refs https://github.com/TryGhost/Arch/issues/25

- The built in index (soon -> "latest") collection does not require any filtering so that it could contain an index of all posts in the system. All other automatic collections should have a filter defined.
This commit is contained in:
Naz 2023-07-10 12:33:16 +08:00 committed by naz
parent 6f5f608bcd
commit cb8e009c14
2 changed files with 19 additions and 2 deletions

View file

@ -69,7 +69,7 @@ export class Collection {
}
public async edit(data: Partial<Collection>, uniqueChecker: UniqueChecker) {
if (this.type === 'automatic' && (data.filter === null || data.filter === '')) {
if (this.type === 'automatic' && this.slug !== 'index' && (data.filter === null || data.filter === '')) {
throw new ValidationError({
message: tpl(messages.invalidFilterProvided.message),
context: tpl(messages.invalidFilterProvided.context)
@ -201,7 +201,7 @@ export class Collection {
});
}
if (data.type === 'automatic' && !data.filter) {
if (data.type === 'automatic' && (data.slug !== 'index') && !data.filter) {
// @NOTE: add filter validation here
throw new ValidationError({
message: tpl(messages.invalidFilterProvided.message),

View file

@ -209,6 +209,23 @@ describe('Collection', function () {
return true;
});
});
it('Does not throw when collection filter is empty for automatic "index" collection', async function (){
const collection = await Collection.create({
title: 'Index',
slug: 'index',
type: 'automatic',
filter: ''
});
const editedCollection = await collection.edit({
title: 'Edited index',
filter: ''
}, uniqueChecker);
assert.equal(editedCollection.title, 'Edited index');
assert.equal(editedCollection.filter, '');
});
});
it('Can add posts to different positions', async function () {