diff --git a/core/server/models/post.js b/core/server/models/post.js index 7bf4864194..206c864d01 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -75,10 +75,10 @@ Post = ghostBookshelf.Model.extend({ emitChange: function emitChange(event, options = {}) { let eventToTrigger; - let resourceType = this.get('page') ? 'page' : 'post'; + let resourceType = this.get('type'); if (options.usePreviousAttribute) { - resourceType = this.previous('page') ? 'page' : 'post'; + resourceType = this.previous('type'); } eventToTrigger = resourceType + '.' + event; @@ -119,7 +119,7 @@ Post = ghostBookshelf.Model.extend({ model.isScheduled = model.get('status') === 'scheduled'; model.wasPublished = model.previous('status') === 'published'; model.wasScheduled = model.previous('status') === 'scheduled'; - model.resourceTypeChanging = model.get('page') !== model.previous('page'); + model.resourceTypeChanging = model.get('type') !== model.previous('type'); model.publishedAtHasChanged = model.hasDateChanged('published_at'); model.needsReschedule = model.publishedAtHasChanged && model.isScheduled; @@ -600,7 +600,7 @@ Post = ghostBookshelf.Model.extend({ return null; } - return options.context && options.context.public ? 'page:false' : 'page:false+status:published'; + return options.context && options.context.public ? 'type:post' : 'type:post+status:published'; }, /** @@ -621,9 +621,9 @@ Post = ghostBookshelf.Model.extend({ options.staticPages = _.includes(['true', '1'], options.staticPages); } - filter = `page:${options.staticPages}`; + filter = `type:${options.staticPages ? 'page' : 'post'}`; } else if (options.staticPages === 'all') { - filter = 'page:[true, false]'; + filter = 'type:[post, page]'; } // CASE: "status" is passed, combine filters diff --git a/core/test/acceptance/old/admin/pages_spec.js b/core/test/acceptance/old/admin/pages_spec.js index fa783e37f0..fd4aae77df 100644 --- a/core/test/acceptance/old/admin/pages_spec.js +++ b/core/test/acceptance/old/admin/pages_spec.js @@ -83,7 +83,7 @@ describe('Pages API', function () { .then((model) => { model.get('title').should.eql(page.title); model.get('status').should.eql(page.status); - model.get('page').should.eql(true); + model.get('type').should.eql('page'); }); }); @@ -116,7 +116,7 @@ describe('Pages API', function () { }, testUtils.context.internal); }) .then((model) => { - model.get('page').should.eql(true); + model.get('type').should.eql('page'); }); }); diff --git a/core/test/unit/models/post_spec.js b/core/test/unit/models/post_spec.js index 46c14a9a15..946b92a65a 100644 --- a/core/test/unit/models/post_spec.js +++ b/core/test/unit/models/post_spec.js @@ -45,21 +45,21 @@ describe('Unit: models/post', function () { withRelated: ['tags'] }).then(() => { queries.length.should.eql(2); - queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where ((`posts`.`id` != ? and `posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`slug` in (?, ?))) and (`posts`.`page` = ? and `posts`.`status` = ?))'); + queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where ((`posts`.`id` != ? and `posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`slug` in (?, ?))) and (`posts`.`type` = ? and `posts`.`status` = ?))'); queries[0].bindings.should.eql([ testUtils.filterData.data.posts[3].id, 'photo', 'video', - false, + 'post', 'published' ]); - queries[1].sql.should.eql('select `posts`.* from `posts` where ((`posts`.`id` != ? and `posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`slug` in (?, ?))) and (`posts`.`page` = ? and `posts`.`status` = ?)) order by (SELECT count(*) FROM posts_tags WHERE post_id = posts.id) DESC, CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); + queries[1].sql.should.eql('select `posts`.* from `posts` where ((`posts`.`id` != ? and `posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`slug` in (?, ?))) and (`posts`.`type` = ? and `posts`.`status` = ?)) order by (SELECT count(*) FROM posts_tags WHERE post_id = posts.id) DESC, CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); queries[1].bindings.should.eql([ testUtils.filterData.data.posts[3].id, 'photo', 'video', - false, + 'post', 'published', 3 ]); @@ -80,21 +80,21 @@ describe('Unit: models/post', function () { withRelated: ['authors', 'tags'] }).then(() => { queries.length.should.eql(2); - queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where (((`posts`.`feature_image` is not null or `posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`slug` = ?)) and `posts`.`id` in (select `posts_authors`.`post_id` from `posts_authors` inner join `users` as `authors` on `authors`.`id` = `posts_authors`.`author_id` where `authors`.`slug` in (?, ?))) and (`posts`.`page` = ? and `posts`.`status` = ?))'); + queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where (((`posts`.`feature_image` is not null or `posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`slug` = ?)) and `posts`.`id` in (select `posts_authors`.`post_id` from `posts_authors` inner join `users` as `authors` on `authors`.`id` = `posts_authors`.`author_id` where `authors`.`slug` in (?, ?))) and (`posts`.`type` = ? and `posts`.`status` = ?))'); queries[0].bindings.should.eql([ 'hash-audio', 'leslie', 'pat', - false, + 'post', 'published' ]); - queries[1].sql.should.eql('select `posts`.* from `posts` where (((`posts`.`feature_image` is not null or `posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`slug` = ?)) and `posts`.`id` in (select `posts_authors`.`post_id` from `posts_authors` inner join `users` as `authors` on `authors`.`id` = `posts_authors`.`author_id` where `authors`.`slug` in (?, ?))) and (`posts`.`page` = ? and `posts`.`status` = ?)) order by (SELECT count(*) FROM posts_authors WHERE post_id = posts.id) DESC, CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); + queries[1].sql.should.eql('select `posts`.* from `posts` where (((`posts`.`feature_image` is not null or `posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`slug` = ?)) and `posts`.`id` in (select `posts_authors`.`post_id` from `posts_authors` inner join `users` as `authors` on `authors`.`id` = `posts_authors`.`author_id` where `authors`.`slug` in (?, ?))) and (`posts`.`type` = ? and `posts`.`status` = ?)) order by (SELECT count(*) FROM posts_authors WHERE post_id = posts.id) DESC, CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); queries[1].bindings.should.eql([ 'hash-audio', 'leslie', 'pat', - false, + 'post', 'published', 15 ]); @@ -116,17 +116,17 @@ describe('Unit: models/post', function () { withRelated: ['tags'] }).then(() => { queries.length.should.eql(2); - queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where (`posts`.`published_at` > ? and (`posts`.`page` = ? and `posts`.`status` = ?))'); + queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where (`posts`.`published_at` > ? and (`posts`.`type` = ? and `posts`.`status` = ?))'); queries[0].bindings.should.eql([ '2015-07-20', - false, + 'post', 'published' ]); - queries[1].sql.should.eql('select `posts`.* from `posts` where (`posts`.`published_at` > ? and (`posts`.`page` = ? and `posts`.`status` = ?)) order by CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); + queries[1].sql.should.eql('select `posts`.* from `posts` where (`posts`.`published_at` > ? and (`posts`.`type` = ? and `posts`.`status` = ?)) order by CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); queries[1].bindings.should.eql([ '2015-07-20', - false, + 'post', 'published', 5 ]); @@ -148,19 +148,19 @@ describe('Unit: models/post', function () { withRelated: ['tags'] }).then(() => { queries.length.should.eql(2); - queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where ((`posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` and `posts_tags`.`sort_order` = 0 where `tags`.`slug` = ? and `tags`.`visibility` = ?)) and (`posts`.`page` = ? and `posts`.`status` = ?))'); + queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where ((`posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` and `posts_tags`.`sort_order` = 0 where `tags`.`slug` = ? and `tags`.`visibility` = ?)) and (`posts`.`type` = ? and `posts`.`status` = ?))'); queries[0].bindings.should.eql([ 'photo', 'public', - false, + 'post', 'published' ]); - queries[1].sql.should.eql('select `posts`.* from `posts` where ((`posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` and `posts_tags`.`sort_order` = 0 where `tags`.`slug` = ? and `tags`.`visibility` = ?)) and (`posts`.`page` = ? and `posts`.`status` = ?)) order by CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); + queries[1].sql.should.eql('select `posts`.* from `posts` where ((`posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` and `posts_tags`.`sort_order` = 0 where `tags`.`slug` = ? and `tags`.`visibility` = ?)) and (`posts`.`type` = ? and `posts`.`status` = ?)) order by CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); queries[1].bindings.should.eql([ 'photo', 'public', - false, + 'post', 'published', 15 ]); @@ -181,19 +181,19 @@ describe('Unit: models/post', function () { withRelated: ['authors'] }).then(() => { queries.length.should.eql(2); - queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where ((`posts`.`id` in (select `posts_authors`.`post_id` from `posts_authors` inner join `users` as `authors` on `authors`.`id` = `posts_authors`.`author_id` and `posts_authors`.`sort_order` = 0 where `authors`.`slug` = ? and `authors`.`visibility` = ?)) and (`posts`.`page` = ? and `posts`.`status` = ?))'); + queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where ((`posts`.`id` in (select `posts_authors`.`post_id` from `posts_authors` inner join `users` as `authors` on `authors`.`id` = `posts_authors`.`author_id` and `posts_authors`.`sort_order` = 0 where `authors`.`slug` = ? and `authors`.`visibility` = ?)) and (`posts`.`type` = ? and `posts`.`status` = ?))'); queries[0].bindings.should.eql([ 'leslie', 'public', - false, + 'post', 'published' ]); - queries[1].sql.should.eql('select `posts`.* from `posts` where ((`posts`.`id` in (select `posts_authors`.`post_id` from `posts_authors` inner join `users` as `authors` on `authors`.`id` = `posts_authors`.`author_id` and `posts_authors`.`sort_order` = 0 where `authors`.`slug` = ? and `authors`.`visibility` = ?)) and (`posts`.`page` = ? and `posts`.`status` = ?)) order by CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); + queries[1].sql.should.eql('select `posts`.* from `posts` where ((`posts`.`id` in (select `posts_authors`.`post_id` from `posts_authors` inner join `users` as `authors` on `authors`.`id` = `posts_authors`.`author_id` and `posts_authors`.`sort_order` = 0 where `authors`.`slug` = ? and `authors`.`visibility` = ?)) and (`posts`.`type` = ? and `posts`.`status` = ?)) order by CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC limit ?'); queries[1].bindings.should.eql([ 'leslie', 'public', - false, + 'post', 'published', 15 ]); @@ -224,20 +224,20 @@ describe('Unit: models/post', function () { } }).then(() => { queries.length.should.eql(2); - queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where ((`posts`.`status` in (?, ?) and `posts`.`status` = ?) and (`posts`.`page` = ?))'); + queries[0].sql.should.eql('select count(distinct posts.id) as aggregate from `posts` where ((`posts`.`status` in (?, ?) and `posts`.`status` = ?) and (`posts`.`type` = ?))'); queries[0].bindings.should.eql([ 'published', 'draft', 'published', - false + 'post' ]); - queries[1].sql.should.eql('select `posts`.* from `posts` where ((`posts`.`status` in (?, ?) and `posts`.`status` = ?) and (`posts`.`page` = ?)) order by CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC'); + queries[1].sql.should.eql('select `posts`.* from `posts` where ((`posts`.`status` in (?, ?) and `posts`.`status` = ?) and (`posts`.`type` = ?)) order by CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != \'draft\' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC'); queries[1].bindings.should.eql([ 'published', 'draft', 'published', - false + 'post' ]); }); }); @@ -322,7 +322,7 @@ describe('Unit: models/post', function () { should(filter).equal(null); }); - it('returns page:false filter for public context', function () { + it('returns type:post filter for public context', function () { const options = { context: { public: true @@ -331,17 +331,17 @@ describe('Unit: models/post', function () { const filter = defaultFilters({}, options); - filter.should.equal('page:false'); + filter.should.equal('type:post'); }); - it('returns page:false+status:published filter for non public context', function () { + it('returns type:post+status:published filter for non public context', function () { const options = { context: 'user' }; const filter = defaultFilters({}, options); - filter.should.equal('page:false+status:published'); + filter.should.equal('type:post+status:published'); }); }); });