Revert post.page->post.type handling

no issue
- the column addition/removal can be too slow for large sites
- will be added back in 3.0

---

Revert "Fixed canary api for page/type column"
This reverts commit a5a7e7e919.

Revert "Updated frontend canary url config for page/type"
This reverts commit 19100ec5e6.

Revert "Updated canary api to handle type column correctly (#11006)"
This reverts commit c3e8ba0523.

Revert "Ensured `page` filter works in routes.yaml"
This reverts commit 9037c19e50.

Revert "Replaced usage of mongo util with nql-map-key-values"
This reverts commit 8c5f1d0ef0.

Revert "Added shared nql-map-key-values module"
This reverts commit ef4fd4b8ef.

Revert "Ensured page prop is present on content api response"
This reverts commit cfa0a0862b.

Revert "Fixed failing regression tests"
This reverts commit 9c2bb3811f.

Revert "Updated xmlrpc and slack service to use type column"
This reverts commit 44a02c7d36.

Revert "Updated v0.1 posts api to work with type column"
This reverts commit 2c81d7c914.

Revert "Removed updates to v0.1 specific code"
This reverts commit 08d83c1f53.

Revert "Added missing context from ValidationError"
This reverts commit cd45ab4f54.

Revert "Renamed page->type in the page&posts serializers"
This reverts commit df99e724e3.

Revert "Added mongo helper to input serializers"
This reverts commit fb8eadb4a8.

Revert "Passed mongoTransformer through to NQL"
This reverts commit 0ae3f0fdfc.

Revert "Permitted mongoTransformer option for read methods"
This reverts commit a89376bf26.

Revert "Updated the count plugin to reference the type column"
This reverts commit a52f15d3d3.

Revert "Updated hashes for db integrity check"
This reverts commit bb6b337be3.

Revert "Remove page column and remaining references"
This reverts commit 9d7190d692.

Revert "Added type column to data generator"
This reverts commit e59806cb45.

Revert "Removed references to page column in rss tests"
This reverts commit 04d0f855de.

Revert "Removed page column references in validation tests"
This reverts commit f0afbc5cc0.

Revert "Updated the post model to use the `type` column"
This reverts commit 1189bc823a.

Revert "Updated url service to use type column"
This reverts commit 61612ba8fd.

Revert "Updated the v2 api to deal with type column"
This reverts commit 57afb2de2b.

Revert "Added type property to post model defaults"
This reverts commit dc3345b1c5.

Revert "Added type property to the default post fixtures"
This reverts commit 82d8c38033.

Revert "Added type column to posts table"
This reverts commit 9b85fc6a69.
This commit is contained in:
Kevin Ansfield 2019-08-16 17:46:00 +01:00
parent 3764e023fb
commit 80fbfd7a85
44 changed files with 176 additions and 463 deletions

View File

@ -23,8 +23,6 @@ const _ = require('lodash'),
replacement: 'primary_author.slug' replacement: 'primary_author.slug'
}]; }];
const mapNQLKeyValues = require('../../../shared/nql-map-key-values');
/** /**
* The UrlGenerator class is responsible to generate urls based on a router's conditions. * The UrlGenerator class is responsible to generate urls based on a router's conditions.
* It is the component which sits between routers and resources and connects them together. * It is the component which sits between routers and resources and connects them together.
@ -46,22 +44,7 @@ class UrlGenerator {
// CASE: routers can define custom filters, but not required. // CASE: routers can define custom filters, but not required.
if (this.router.getFilter()) { if (this.router.getFilter()) {
this.filter = this.router.getFilter(); this.filter = this.router.getFilter();
this.nql = nql(this.filter, { this.nql = nql(this.filter, {expansions: EXPANSIONS});
expansions: EXPANSIONS,
transformer: mapNQLKeyValues({
key: {
from: 'page',
to: 'type'
},
values: [{
from: false,
to: 'post'
}, {
from: true,
to: 'page'
}]
})
});
debug('filter', this.filter); debug('filter', this.filter);
} }

View File

@ -8,7 +8,7 @@ module.exports = [
type: 'posts', type: 'posts',
modelOptions: { modelOptions: {
modelName: 'Post', modelName: 'Post',
filter: 'visibility:public+status:published+type:post', filter: 'visibility:public+status:published+page:false',
exclude: [ exclude: [
'title', 'title',
'mobiledoc', 'mobiledoc',
@ -79,7 +79,7 @@ module.exports = [
'primary_tag', 'primary_tag',
'primary_author' 'primary_author'
], ],
filter: 'visibility:public+status:published+type:page' filter: 'visibility:public+status:published+page:true'
}, },
events: { events: {
add: 'page.published', add: 'page.published',

View File

@ -8,7 +8,7 @@ module.exports = [
type: 'posts', type: 'posts',
modelOptions: { modelOptions: {
modelName: 'Post', modelName: 'Post',
filter: 'visibility:public+status:published+type:post', filter: 'visibility:public+status:published+page:false',
exclude: [ exclude: [
'title', 'title',
'mobiledoc', 'mobiledoc',
@ -73,7 +73,7 @@ module.exports = [
'primary_tag', 'primary_tag',
'primary_author' 'primary_author'
], ],
filter: 'visibility:public+status:published+type:page' filter: 'visibility:public+status:published+page:true'
}, },
events: { events: {
add: 'page.published', add: 'page.published',

View File

@ -8,7 +8,7 @@ module.exports = [
type: 'posts', type: 'posts',
modelOptions: { modelOptions: {
modelName: 'Post', modelName: 'Post',
filter: 'visibility:public+status:published+type:post', filter: 'visibility:public+status:published+page:false',
exclude: [ exclude: [
'title', 'title',
'mobiledoc', 'mobiledoc',
@ -79,7 +79,7 @@ module.exports = [
'primary_tag', 'primary_tag',
'primary_author' 'primary_author'
], ],
filter: 'visibility:public+status:published+type:page' filter: 'visibility:public+status:published+page:true'
}, },
events: { events: {
add: 'page.published', add: 'page.published',

View File

@ -1,24 +1,9 @@
const _ = require('lodash'); const _ = require('lodash');
const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:pages'); const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:pages');
const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values');
const converters = require('../../../../../lib/mobiledoc/converters'); const converters = require('../../../../../lib/mobiledoc/converters');
const url = require('./utils/url'); const url = require('./utils/url');
const localUtils = require('../../index'); const localUtils = require('../../index');
const replacePageWithType = mapNQLKeyValues({
key: {
from: 'page',
to: 'type'
},
values: [{
from: false,
to: 'post'
}, {
from: true,
to: 'page'
}]
});
function removeMobiledocFormat(frame) { function removeMobiledocFormat(frame) {
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) { if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
frame.options.formats = frame.options.formats.filter((format) => { frame.options.formats = frame.options.formats.filter((format) => {
@ -70,9 +55,9 @@ function defaultFormat(frame) {
*/ */
const forcePageFilter = (frame) => { const forcePageFilter = (frame) => {
if (frame.options.filter) { if (frame.options.filter) {
frame.options.filter = `(${frame.options.filter})+type:page`; frame.options.filter = `(${frame.options.filter})+page:true`;
} else { } else {
frame.options.filter = 'type:page'; frame.options.filter = 'page:true';
} }
}; };
@ -101,8 +86,6 @@ module.exports = {
defaultRelations(frame); defaultRelations(frame);
} }
frame.options.mongoTransformer = replacePageWithType;
debug(frame.options); debug(frame.options);
}, },
@ -140,7 +123,7 @@ module.exports = {
// @NOTE: force storing page // @NOTE: force storing page
if (options.add) { if (options.add) {
frame.data.pages[0].type = 'page'; frame.data.pages[0].page = true;
} }
// CASE: Transform short to long format // CASE: Transform short to long format
@ -180,7 +163,7 @@ module.exports = {
destroy(apiConfig, frame) { destroy(apiConfig, frame) {
frame.options.destroyBy = { frame.options.destroyBy = {
id: frame.options.id, id: frame.options.id,
type: 'page' page: true
}; };
defaultFormat(frame); defaultFormat(frame);

View File

@ -1,25 +1,10 @@
const _ = require('lodash'); const _ = require('lodash');
const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:posts'); const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:posts');
const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values');
const url = require('./utils/url'); const url = require('./utils/url');
const localUtils = require('../../index'); const localUtils = require('../../index');
const labs = require('../../../../../services/labs'); const labs = require('../../../../../services/labs');
const converters = require('../../../../../lib/mobiledoc/converters'); const converters = require('../../../../../lib/mobiledoc/converters');
const replacePageWithType = mapNQLKeyValues({
key: {
from: 'page',
to: 'type'
},
values: [{
from: false,
to: 'post'
}, {
from: true,
to: 'page'
}]
});
function removeMobiledocFormat(frame) { function removeMobiledocFormat(frame) {
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) { if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
frame.options.formats = frame.options.formats.filter((format) => { frame.options.formats = frame.options.formats.filter((format) => {
@ -79,9 +64,9 @@ function defaultFormat(frame) {
*/ */
const forcePageFilter = (frame) => { const forcePageFilter = (frame) => {
if (frame.options.filter) { if (frame.options.filter) {
frame.options.filter = `(${frame.options.filter})+type:post`; frame.options.filter = `(${frame.options.filter})+page:false`;
} else { } else {
frame.options.filter = 'type:post'; frame.options.filter = 'page:false';
} }
}; };
@ -123,8 +108,6 @@ module.exports = {
defaultRelations(frame); defaultRelations(frame);
} }
frame.options.mongoTransformer = replacePageWithType;
debug(frame.options); debug(frame.options);
}, },
@ -175,7 +158,7 @@ module.exports = {
// @NOTE: force adding post // @NOTE: force adding post
if (options.add) { if (options.add) {
frame.data.posts[0].type = 'post'; frame.data.posts[0].page = false;
} }
// CASE: Transform short to long format // CASE: Transform short to long format
@ -213,7 +196,7 @@ module.exports = {
destroy(apiConfig, frame) { destroy(apiConfig, frame) {
frame.options.destroyBy = { frame.options.destroyBy = {
id: frame.options.id, id: frame.options.id,
type: 'post' page: false
}; };
defaultFormat(frame); defaultFormat(frame);

View File

@ -35,10 +35,6 @@ const mapPost = (model, frame) => {
url.forPost(model.id, jsonModel, frame); url.forPost(model.id, jsonModel, frame);
if (utils.isContentAPI(frame)) { if (utils.isContentAPI(frame)) {
// Content api v2 still expects page prop
if (jsonModel.type === 'page') {
jsonModel.page = true;
}
date.forPost(jsonModel); date.forPost(jsonModel);
members.forPost(jsonModel, frame); members.forPost(jsonModel, frame);
} }
@ -61,8 +57,6 @@ const mapPost = (model, frame) => {
}); });
} }
delete jsonModel.type;
return jsonModel; return jsonModel;
}; };

View File

@ -16,49 +16,6 @@ const Promise = require('bluebird'),
], ],
unsafeAttrs = ['author_id', 'status', 'authors']; unsafeAttrs = ['author_id', 'status', 'authors'];
const mapNQLKeyValues = require('../../../shared/nql-map-key-values');
const replacePageWithType = mapNQLKeyValues({
key: {
from: 'page',
to: 'type'
},
values: [{
from: false,
to: 'post'
}, {
from: true,
to: 'page'
}]
});
function convertTypeToPage(model) {
// Respect include param
if (!Object.hasOwnProperty.call(model, 'type')) {
return model;
}
model.page = model.type === 'page';
delete model.type;
return model;
}
function convertPageToType(model) {
if (!Object.hasOwnProperty.call(model, 'page')) {
return model;
}
if (model.page === true) {
model.type = 'page';
} else if (model.page === false) {
model.type = 'post';
} else {
// This is to ensure that invalid page props generate a ValidationError
model.type = 'UNKNOWN_PAGE_OPTION';
}
delete model.page;
return model;
}
let posts; let posts;
/** /**
@ -101,12 +58,10 @@ posts = {
* @returns {Object} options * @returns {Object} options
*/ */
function modelQuery(options) { function modelQuery(options) {
options.mongoTransformer = replacePageWithType;
return models.Post.findPage(options) return models.Post.findPage(options)
.then(({data, meta}) => { .then(({data, meta}) => {
return { return {
posts: data.map(model => urlsForPost(model.id, model.toJSON(options), options)).map(convertTypeToPage), posts: data.map(model => urlsForPost(model.id, model.toJSON(options), options)),
meta: meta meta: meta
}; };
}); });
@ -146,8 +101,6 @@ posts = {
* @returns {Object} options * @returns {Object} options
*/ */
function modelQuery(options) { function modelQuery(options) {
options.mongoTransformer = replacePageWithType;
return models.Post.findOne(options.data, omit(options, ['data'])) return models.Post.findOne(options.data, omit(options, ['data']))
.then((model) => { .then((model) => {
if (!model) { if (!model) {
@ -157,7 +110,7 @@ posts = {
} }
return { return {
posts: [urlsForPost(model.id, model.toJSON(options), options)].map(convertTypeToPage) posts: [urlsForPost(model.id, model.toJSON(options), options)]
}; };
}); });
} }
@ -195,7 +148,7 @@ posts = {
* @returns {Object} options * @returns {Object} options
*/ */
function modelQuery(options) { function modelQuery(options) {
return models.Post.edit(options.data.posts.map(convertPageToType)[0], omit(options, ['data'])) return models.Post.edit(options.data.posts[0], omit(options, ['data']))
.then((model) => { .then((model) => {
if (!model) { if (!model) {
return Promise.reject(new common.errors.NotFoundError({ return Promise.reject(new common.errors.NotFoundError({
@ -213,7 +166,7 @@ posts = {
} }
return { return {
posts: [post].map(convertTypeToPage) posts: [post]
}; };
}); });
} }
@ -249,7 +202,7 @@ posts = {
* @returns {Object} options * @returns {Object} options
*/ */
function modelQuery(options) { function modelQuery(options) {
return models.Post.add(options.data.posts.map(convertPageToType)[0], omit(options, ['data'])) return models.Post.add(options.data.posts[0], omit(options, ['data']))
.then((model) => { .then((model) => {
const post = urlsForPost(model.id, model.toJSON(options), options); const post = urlsForPost(model.id, model.toJSON(options), options);
@ -258,9 +211,7 @@ posts = {
post.statusChanged = true; post.statusChanged = true;
} }
return { return {posts: [post]};
posts: [post].map(convertTypeToPage)
};
}); });
} }

View File

@ -1,24 +1,9 @@
const _ = require('lodash'); const _ = require('lodash');
const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values');
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:pages'); const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:pages');
const converters = require('../../../../../lib/mobiledoc/converters'); const converters = require('../../../../../lib/mobiledoc/converters');
const url = require('./utils/url'); const url = require('./utils/url');
const localUtils = require('../../index'); const localUtils = require('../../index');
const replacePageWithType = mapNQLKeyValues({
key: {
from: 'page',
to: 'type'
},
values: [{
from: false,
to: 'post'
}, {
from: true,
to: 'page'
}]
});
function removeMobiledocFormat(frame) { function removeMobiledocFormat(frame) {
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) { if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
frame.options.formats = frame.options.formats.filter((format) => { frame.options.formats = frame.options.formats.filter((format) => {
@ -70,9 +55,9 @@ function defaultFormat(frame) {
*/ */
const forcePageFilter = (frame) => { const forcePageFilter = (frame) => {
if (frame.options.filter) { if (frame.options.filter) {
frame.options.filter = `(${frame.options.filter})+type:page`; frame.options.filter = `(${frame.options.filter})+page:true`;
} else { } else {
frame.options.filter = 'type:page'; frame.options.filter = 'page:true';
} }
}; };
@ -101,8 +86,6 @@ module.exports = {
defaultRelations(frame); defaultRelations(frame);
} }
frame.options.mongoTransformer = replacePageWithType;
debug(frame.options); debug(frame.options);
}, },
@ -140,7 +123,7 @@ module.exports = {
// @NOTE: force storing page // @NOTE: force storing page
if (options.add) { if (options.add) {
frame.data.pages[0].type = 'page'; frame.data.pages[0].page = true;
} }
// CASE: Transform short to long format // CASE: Transform short to long format
@ -180,7 +163,7 @@ module.exports = {
destroy(apiConfig, frame) { destroy(apiConfig, frame) {
frame.options.destroyBy = { frame.options.destroyBy = {
id: frame.options.id, id: frame.options.id,
type: 'page' page: true
}; };
defaultFormat(frame); defaultFormat(frame);

View File

@ -1,25 +1,10 @@
const _ = require('lodash'); const _ = require('lodash');
const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values');
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:posts'); const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:posts');
const url = require('./utils/url'); const url = require('./utils/url');
const localUtils = require('../../index'); const localUtils = require('../../index');
const labs = require('../../../../../services/labs'); const labs = require('../../../../../services/labs');
const converters = require('../../../../../lib/mobiledoc/converters'); const converters = require('../../../../../lib/mobiledoc/converters');
const replacePageWithType = mapNQLKeyValues({
key: {
from: 'page',
to: 'type'
},
values: [{
from: false,
to: 'post'
}, {
from: true,
to: 'page'
}]
});
function removeMobiledocFormat(frame) { function removeMobiledocFormat(frame) {
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) { if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
frame.options.formats = frame.options.formats.filter((format) => { frame.options.formats = frame.options.formats.filter((format) => {
@ -79,9 +64,9 @@ function defaultFormat(frame) {
*/ */
const forcePageFilter = (frame) => { const forcePageFilter = (frame) => {
if (frame.options.filter) { if (frame.options.filter) {
frame.options.filter = `(${frame.options.filter})+type:post`; frame.options.filter = `(${frame.options.filter})+page:false`;
} else { } else {
frame.options.filter = 'type:post'; frame.options.filter = 'page:false';
} }
}; };
@ -123,8 +108,6 @@ module.exports = {
defaultRelations(frame); defaultRelations(frame);
} }
frame.options.mongoTransformer = replacePageWithType;
debug(frame.options); debug(frame.options);
}, },
@ -175,7 +158,7 @@ module.exports = {
// @NOTE: force adding post // @NOTE: force adding post
if (options.add) { if (options.add) {
frame.data.posts[0].type = 'post'; frame.data.posts[0].page = false;
} }
// CASE: Transform short to long format // CASE: Transform short to long format
@ -213,7 +196,7 @@ module.exports = {
destroy(apiConfig, frame) { destroy(apiConfig, frame) {
frame.options.destroyBy = { frame.options.destroyBy = {
id: frame.options.id, id: frame.options.id,
type: 'post' page: false
}; };
defaultFormat(frame); defaultFormat(frame);

View File

@ -35,10 +35,6 @@ const mapPost = (model, frame) => {
url.forPost(model.id, jsonModel, frame); url.forPost(model.id, jsonModel, frame);
if (utils.isContentAPI(frame)) { if (utils.isContentAPI(frame)) {
// Content api v2 still expects page prop
if (jsonModel.type === 'page') {
jsonModel.page = true;
}
date.forPost(jsonModel); date.forPost(jsonModel);
members.forPost(jsonModel, frame); members.forPost(jsonModel, frame);
} }
@ -61,8 +57,6 @@ const mapPost = (model, frame) => {
}); });
} }
delete jsonModel.type;
return jsonModel; return jsonModel;
}; };

View File

@ -21,16 +21,6 @@ class PostsImporter extends BaseImporter {
if (!validation.validator.isUUID(obj.uuid || '')) { if (!validation.validator.isUUID(obj.uuid || '')) {
obj.uuid = uuid.v4(); obj.uuid = uuid.v4();
} }
// we used to have post.page=true/false
// we now have post.type='page'/'post'
// give precedence to post.type if both are present
if (_.has(obj, 'page')) {
if (_.isEmpty(obj.type)) {
obj.type = obj.page ? 'page' : 'post';
}
delete obj.page;
}
}); });
} }
@ -162,6 +152,14 @@ class PostsImporter extends BaseImporter {
this.addNestedRelations(); this.addNestedRelations();
_.each(this.dataToImport, (model) => { _.each(this.dataToImport, (model) => {
// during 2.28.x we had `post.type` in place of `post.page`
// this needs normalising back to `post.page`
// TODO: switch back to `post.page->type` in v3
if (_.has(model, 'type')) {
model.page = model.type === 'post' ? false : true;
delete model.type;
}
// NOTE: we remember the original post id for disqus // NOTE: we remember the original post id for disqus
// (see https://github.com/TryGhost/Ghost/issues/8963) // (see https://github.com/TryGhost/Ghost/issues/8963)

File diff suppressed because one or more lines are too long

View File

@ -345,8 +345,7 @@ validate = function validate(value, key, validations, tableName) {
} }
validationErrors.push(new common.errors.ValidationError({ validationErrors.push(new common.errors.ValidationError({
message: translation, message: translation
context: `${tableName}.${key}`
})); }));
} }

View File

@ -668,11 +668,11 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
case 'edit': case 'edit':
return baseOptions.concat(extraOptions, ['id', 'require']); return baseOptions.concat(extraOptions, ['id', 'require']);
case 'findOne': case 'findOne':
return baseOptions.concat(extraOptions, ['columns', 'require', 'mongoTransformer']); return baseOptions.concat(extraOptions, ['columns', 'require']);
case 'findAll': case 'findAll':
return baseOptions.concat(extraOptions, ['columns', 'mongoTransformer']); return baseOptions.concat(extraOptions, ['columns']);
case 'findPage': case 'findPage':
return baseOptions.concat(extraOptions, ['filter', 'order', 'page', 'limit', 'columns', 'mongoTransformer']); return baseOptions.concat(extraOptions, ['filter', 'order', 'page', 'limit', 'columns']);
default: default:
return baseOptions.concat(extraOptions); return baseOptions.concat(extraOptions);
} }

View File

@ -61,7 +61,6 @@ const filter = function filter(Bookshelf) {
let extra = this.extraFilters(options); let extra = this.extraFilters(options);
let overrides = this.enforcedFilters(options); let overrides = this.enforcedFilters(options);
let defaults = this.defaultFilters(options); let defaults = this.defaultFilters(options);
let transformer = options.mongoTransformer;
debug('custom', custom); debug('custom', custom);
debug('extra', extra); debug('extra', extra);
@ -82,8 +81,7 @@ const filter = function filter(Bookshelf) {
relations: RELATIONS, relations: RELATIONS,
expansions: EXPANSIONS, expansions: EXPANSIONS,
overrides: overrides, overrides: overrides,
defaults: defaults, defaults: defaults
transformer: transformer
}).querySQL(qb); }).querySQL(qb);
}); });
} catch (err) { } catch (err) {

View File

@ -19,7 +19,7 @@ module.exports = function (Bookshelf) {
if (options.context && options.context.public) { if (options.context && options.context.public) {
// @TODO use the filter behavior for posts // @TODO use the filter behavior for posts
qb.andWhere('posts.type', '=', 'post'); qb.andWhere('posts.page', '=', false);
qb.andWhere('posts.status', '=', 'published'); qb.andWhere('posts.status', '=', 'published');
} }
}); });
@ -36,7 +36,7 @@ module.exports = function (Bookshelf) {
if (options.context && options.context.public) { if (options.context && options.context.public) {
// @TODO use the filter behavior for posts // @TODO use the filter behavior for posts
qb.andWhere('posts.type', '=', 'post'); qb.andWhere('posts.page', '=', false);
qb.andWhere('posts.status', '=', 'published'); qb.andWhere('posts.status', '=', 'published');
} }
}); });

View File

@ -44,7 +44,7 @@ Post = ghostBookshelf.Model.extend({
uuid: uuid.v4(), uuid: uuid.v4(),
status: 'draft', status: 'draft',
featured: false, featured: false,
type: 'post', page: false,
visibility: 'public' visibility: 'public'
}; };
}, },
@ -74,10 +74,10 @@ Post = ghostBookshelf.Model.extend({
emitChange: function emitChange(event, options = {}) { emitChange: function emitChange(event, options = {}) {
let eventToTrigger; let eventToTrigger;
let resourceType = this.get('type'); let resourceType = this.get('page') ? 'page' : 'post';
if (options.usePreviousAttribute) { if (options.usePreviousAttribute) {
resourceType = this.previous('type'); resourceType = this.previous('page') ? 'page' : 'post';
} }
eventToTrigger = resourceType + '.' + event; eventToTrigger = resourceType + '.' + event;
@ -118,7 +118,7 @@ Post = ghostBookshelf.Model.extend({
model.isScheduled = model.get('status') === 'scheduled'; model.isScheduled = model.get('status') === 'scheduled';
model.wasPublished = model.previous('status') === 'published'; model.wasPublished = model.previous('status') === 'published';
model.wasScheduled = model.previous('status') === 'scheduled'; model.wasScheduled = model.previous('status') === 'scheduled';
model.resourceTypeChanging = model.get('type') !== model.previous('type'); model.resourceTypeChanging = model.get('page') !== model.previous('page');
model.publishedAtHasChanged = model.hasDateChanged('published_at'); model.publishedAtHasChanged = model.hasDateChanged('published_at');
model.needsReschedule = model.publishedAtHasChanged && model.isScheduled; model.needsReschedule = model.publishedAtHasChanged && model.isScheduled;
@ -567,7 +567,7 @@ Post = ghostBookshelf.Model.extend({
return null; return null;
} }
return options.context && options.context.public ? 'type:post' : 'type:post+status:published'; return options.context && options.context.public ? 'page:false' : 'page:false+status:published';
}, },
/** /**
@ -588,7 +588,7 @@ Post = ghostBookshelf.Model.extend({
options.staticPages = _.includes(['true', '1'], options.staticPages); options.staticPages = _.includes(['true', '1'], options.staticPages);
} }
filter = `page:${options.staticPages ? 'true' : 'false'}`; filter = `page:${options.staticPages}`;
} else if (options.staticPages === 'all') { } else if (options.staticPages === 'all') {
filter = 'page:[true, false]'; filter = 'page:[true, false]';
} }
@ -750,12 +750,6 @@ Post = ghostBookshelf.Model.extend({
edit: function edit(data, unfilteredOptions) { edit: function edit(data, unfilteredOptions) {
let options = this.filterOptions(unfilteredOptions, 'edit', {extraAllowedProperties: ['id']}); let options = this.filterOptions(unfilteredOptions, 'edit', {extraAllowedProperties: ['id']});
// @TODO DELETE THIS (and the failing regression tests) when v0.1 is ded
if (Object.prototype.hasOwnProperty.call(data, 'page')) {
data.type = data.page ? 'page' : 'post';
delete data.page;
}
const editPost = () => { const editPost = () => {
options.forUpdate = true; options.forUpdate = true;

View File

@ -45,7 +45,7 @@ function ping(post) {
if (slackSettings && slackSettings.url && slackSettings.url !== '') { if (slackSettings && slackSettings.url && slackSettings.url !== '') {
slackSettings.username = slackSettings.username ? slackSettings.username : 'Ghost'; slackSettings.username = slackSettings.username ? slackSettings.username : 'Ghost';
// Only ping when not a page // Only ping when not a page
if (post.type === 'page') { if (post.page) {
return; return;
} }

View File

@ -27,7 +27,7 @@ function ping(post) {
title = post.title, title = post.title,
url = urlService.getUrlByResourceId(post.id, {absolute: true}); url = urlService.getUrlByResourceId(post.id, {absolute: true});
if (post.type === 'page' || config.isPrivacyDisabled('useRpcPing') || settingsCache.get('is_private')) { if (post.page || config.isPrivacyDisabled('useRpcPing') || settingsCache.get('is_private')) {
return; return;
} }

View File

@ -1,26 +0,0 @@
# nql-map-key-values
This utility returns a transformer which can be passed to the `@nexes/nql` library to transform queries
### Usage
```js
const nql = require('@nexes/nql');
const mapKeyValues = require('nql-map-key-values');
nql('good:true', {
transformer: mapKeyValues({
key: {
from: 'good',
to: 'bad'
},
values: [{
from: true,
to: false
}, {
from: false,
to: true
}]
});
}).toJSON(); // => {bad: false}
```

View File

@ -1,44 +0,0 @@
const _ = require('lodash');
const nql = require('@nexes/nql');
/*
* Returns the replacement value for input, or input if it doesn't exist
*/
function replaceValue(input, valueMappings) {
const replacer = valueMappings.find(({from}) => from === input);
return replacer && replacer.to || input;
}
function fmap(item, fn) {
return Array.isArray(item) ? item.map(fn) : fn(item);
}
function mapKeysAndValues(input, mapping) {
return nql.utils.mapQuery(input, function (value, key) {
// Ignore everything that has nothing to do with our mapping
if (key !== mapping.key.from) {
return {
[key]: value
};
}
// key: valueA
if (typeof value !== 'object') {
return {
[mapping.key.to]: replaceValue(value, mapping.values)
};
}
// key: { "$in": ['valueA', 'valueB'] }
// key: { "$ne": 'valueA' }
return {
[mapping.key.to]: _.reduce(value, (memo, objValue, objKey) => {
return Object.assign(memo, {
[objKey]: fmap(objValue, item => replaceValue(item, mapping.values))
});
}, {})
};
});
}
module.exports = mapping => input => mapKeysAndValues(input, mapping);

View File

@ -1,14 +0,0 @@
{
"name": "nql-map-key-values",
"version": "0.0.0",
"description": "Map keys and values for nql query objects",
"main": "index.js",
"repository": "https://github.com/TryGhost/Ghost/tree/master/core/shared/nql-map-key-values",
"author": "Ghost Foundation",
"license": "MIT",
"private": true,
"dependencies": {
"@nexes/nql": "0.3.0",
"lodash": "4.17.15"
}
}

View File

@ -83,7 +83,7 @@ describe('Pages API', function () {
.then((model) => { .then((model) => {
model.get('title').should.eql(page.title); model.get('title').should.eql(page.title);
model.get('status').should.eql(page.status); model.get('status').should.eql(page.status);
model.get('type').should.eql('page'); model.get('page').should.eql(true);
}); });
}); });
@ -116,7 +116,7 @@ describe('Pages API', function () {
}, testUtils.context.internal); }, testUtils.context.internal);
}) })
.then((model) => { .then((model) => {
model.get('type').should.eql('page'); model.get('page').should.eql(true);
}); });
}); });

View File

@ -31,8 +31,6 @@ const expectedProperties = {
.without('visibility') .without('visibility')
.without('locale') .without('locale')
.without('page') .without('page')
// v2 API doesn't return new type field
.without('type')
// deprecated // deprecated
.without('author_id') .without('author_id')
// always returns computed properties // always returns computed properties
@ -48,8 +46,6 @@ const expectedProperties = {
.without('visibility') .without('visibility')
.without('locale') .without('locale')
.without('page') .without('page')
// v2 API doesn't return new type field
.without('type')
// deprecated // deprecated
.without('author_id') .without('author_id')
// always returns computed properties // always returns computed properties

View File

@ -23,8 +23,6 @@ const expectedProperties = {
.without('locale', 'visibility') .without('locale', 'visibility')
// These fields aren't useful as they always have known values // These fields aren't useful as they always have known values
.without('status') .without('status')
// v2 API doesn't return new type field
.without('type')
// @TODO: https://github.com/TryGhost/Ghost/issues/10335 // @TODO: https://github.com/TryGhost/Ghost/issues/10335
// .without('page') // .without('page')
// v2 returns a calculated excerpt field // v2 returns a calculated excerpt field

View File

@ -80,7 +80,7 @@ describe('Schedules API', function () {
published_at: moment().add(30, 'seconds').toDate(), published_at: moment().add(30, 'seconds').toDate(),
status: 'scheduled', status: 'scheduled',
slug: 'fifth', slug: 'fifth',
type: 'page' page: true
})); }));
return Promise.mapSeries(resources, function (post) { return Promise.mapSeries(resources, function (post) {

View File

@ -25,7 +25,6 @@ const expectedProperties = {
.without('status') .without('status')
// @TODO: https://github.com/TryGhost/Ghost/issues/10335 // @TODO: https://github.com/TryGhost/Ghost/issues/10335
// .without('page') // .without('page')
.without('type')
// canary returns a calculated excerpt field // canary returns a calculated excerpt field
.concat('excerpt') .concat('excerpt')
, ,

View File

@ -20,8 +20,6 @@ const expectedProperties = {
.keys() .keys()
// by default we only return html // by default we only return html
.without('mobiledoc', 'plaintext') .without('mobiledoc', 'plaintext')
.without('type')
.concat('page')
// swaps author_id to author, and always returns computed properties: url, comment_id, primary_tag, primary_author // swaps author_id to author, and always returns computed properties: url, comment_id, primary_tag, primary_author
.without('author_id').concat('author', 'url', 'primary_tag', 'primary_author') .without('author_id').concat('author', 'url', 'primary_tag', 'primary_author')
.without('canonical_url') .without('canonical_url')

View File

@ -80,7 +80,7 @@ describe('Schedules API', function () {
published_at: moment().add(30, 'seconds').toDate(), published_at: moment().add(30, 'seconds').toDate(),
status: 'scheduled', status: 'scheduled',
slug: 'fifth', slug: 'fifth',
type: 'page' page: true
})); }));
return Promise.mapSeries(resources, function (post) { return Promise.mapSeries(resources, function (post) {

View File

@ -25,7 +25,6 @@ const expectedProperties = {
.without('status') .without('status')
// @TODO: https://github.com/TryGhost/Ghost/issues/10335 // @TODO: https://github.com/TryGhost/Ghost/issues/10335
// .without('page') // .without('page')
.without('type')
// v2 returns a calculated excerpt field // v2 returns a calculated excerpt field
.concat('excerpt') .concat('excerpt')
, ,

View File

@ -532,7 +532,7 @@ describe('Post Model', function () {
}).then(function (edited) { }).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.status.should.equal('draft'); edited.attributes.status.should.equal('draft');
edited.attributes.type.should.equal('page'); edited.attributes.page.should.equal(true);
Object.keys(eventsTriggered).length.should.eql(2); Object.keys(eventsTriggered).length.should.eql(2);
should.exist(eventsTriggered['post.deleted']); should.exist(eventsTriggered['post.deleted']);
@ -542,7 +542,7 @@ describe('Post Model', function () {
}).then(function (edited) { }).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.status.should.equal('draft'); edited.attributes.status.should.equal('draft');
edited.attributes.type.should.equal('post'); edited.attributes.page.should.equal(false);
Object.keys(eventsTriggered).length.should.eql(4); Object.keys(eventsTriggered).length.should.eql(4);
should.exist(eventsTriggered['post.deleted']); should.exist(eventsTriggered['post.deleted']);
@ -569,7 +569,7 @@ describe('Post Model', function () {
}).then(function (edited) { }).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.status.should.equal('scheduled'); edited.attributes.status.should.equal('scheduled');
edited.attributes.type.should.equal('page'); edited.attributes.page.should.equal(true);
Object.keys(eventsTriggered).length.should.eql(3); Object.keys(eventsTriggered).length.should.eql(3);
should.exist(eventsTriggered['post.deleted']); should.exist(eventsTriggered['post.deleted']);
@ -580,7 +580,7 @@ describe('Post Model', function () {
}).then(function (edited) { }).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.status.should.equal('scheduled'); edited.attributes.status.should.equal('scheduled');
edited.attributes.type.should.equal('post'); edited.attributes.page.should.equal(false);
Object.keys(eventsTriggered).length.should.eql(7); Object.keys(eventsTriggered).length.should.eql(7);
should.exist(eventsTriggered['page.unscheduled']); should.exist(eventsTriggered['page.unscheduled']);
@ -606,7 +606,7 @@ describe('Post Model', function () {
}).then(function (edited) { }).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.status.should.equal('published'); edited.attributes.status.should.equal('published');
edited.attributes.type.should.equal('page'); edited.attributes.page.should.equal(true);
Object.keys(eventsTriggered).length.should.eql(4); Object.keys(eventsTriggered).length.should.eql(4);
should.exist(eventsTriggered['post.unpublished']); should.exist(eventsTriggered['post.unpublished']);
@ -618,7 +618,7 @@ describe('Post Model', function () {
}).then(function (edited) { }).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.status.should.equal('published'); edited.attributes.status.should.equal('published');
edited.attributes.type.should.equal('post'); edited.attributes.page.should.equal(false);
Object.keys(eventsTriggered).length.should.eql(8); Object.keys(eventsTriggered).length.should.eql(8);
should.exist(eventsTriggered['page.unpublished']); should.exist(eventsTriggered['page.unpublished']);
@ -644,7 +644,7 @@ describe('Post Model', function () {
}).then(function (edited) { }).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.status.should.equal('published'); edited.attributes.status.should.equal('published');
edited.attributes.type.should.equal('page'); edited.attributes.page.should.equal(true);
Object.keys(eventsTriggered).length.should.eql(5); Object.keys(eventsTriggered).length.should.eql(5);
should.exist(eventsTriggered['post.deleted']); should.exist(eventsTriggered['post.deleted']);
@ -657,7 +657,7 @@ describe('Post Model', function () {
}).then(function (edited) { }).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.status.should.equal('draft'); edited.attributes.status.should.equal('draft');
edited.attributes.type.should.equal('post'); edited.attributes.page.should.equal(false);
Object.keys(eventsTriggered).length.should.eql(8); Object.keys(eventsTriggered).length.should.eql(8);
should.exist(eventsTriggered['page.unpublished']); should.exist(eventsTriggered['page.unpublished']);
@ -1175,7 +1175,7 @@ describe('Post Model', function () {
page = results.toJSON(); page = results.toJSON();
page.id.should.equal(firstItemData.id); page.id.should.equal(firstItemData.id);
page.status.should.equal('published'); page.status.should.equal('published');
page.type.should.equal('page'); page.page.should.be.true();
// Destroy the page // Destroy the page
return results.destroy(firstItemData); return results.destroy(firstItemData);

View File

@ -1915,7 +1915,7 @@ describe('Integration - Web - Site', function () {
response.statusCode.should.eql(200); response.statusCode.should.eql(200);
response.template.should.eql('tag'); response.template.should.eql('tag');
postSpy.args[0][0].options.filter.should.eql('(tags:\'bacon\'+tags.visibility:public)+type:post'); postSpy.args[0][0].options.filter.should.eql('(tags:\'bacon\'+tags.visibility:public)+page:false');
postSpy.args[0][0].options.page.should.eql(1); postSpy.args[0][0].options.page.should.eql(1);
postSpy.args[0][0].options.limit.should.eql(2); postSpy.args[0][0].options.limit.should.eql(2);
}); });
@ -3659,7 +3659,7 @@ describe('Integration - Web - Site', function () {
response.statusCode.should.eql(200); response.statusCode.should.eql(200);
response.template.should.eql('tag'); response.template.should.eql('tag');
postSpy.args[0][0].options.filter.should.eql('(tags:\'bacon\'+tags.visibility:public)+type:post'); postSpy.args[0][0].options.filter.should.eql('(tags:\'bacon\'+tags.visibility:public)+page:false');
postSpy.args[0][0].options.page.should.eql(1); postSpy.args[0][0].options.page.should.eql(1);
postSpy.args[0][0].options.limit.should.eql(2); postSpy.args[0][0].options.limit.should.eql(2);
}); });

View File

@ -13,7 +13,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.browse(apiConfig, frame); serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('type:page'); frame.options.filter.should.eql('page:true');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -27,7 +27,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.browse(apiConfig, frame); serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(status:published+tag:eins)+type:page'); frame.options.filter.should.eql('(status:published+tag:eins)+page:true');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -41,7 +41,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.browse(apiConfig, frame); serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false+tag:eins)+type:page'); frame.options.filter.should.eql('(page:false+tag:eins)+page:true');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -55,7 +55,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.browse(apiConfig, frame); serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+type:page'); frame.options.filter.should.eql('(page:false)+page:true');
}); });
it('remove mobiledoc option from formats', function () { it('remove mobiledoc option from formats', function () {
@ -87,7 +87,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('type:page'); frame.options.filter.should.eql('page:true');
}); });
it('content api default', function () { it('content api default', function () {
@ -107,7 +107,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('type:page'); frame.options.filter.should.eql('page:true');
}); });
it('admin api default', function () { it('admin api default', function () {
@ -127,7 +127,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(type:page)+status:[draft,published,scheduled]'); frame.options.filter.should.eql('(page:true)+status:[draft,published,scheduled]');
}); });
it('custom page filter', function () { it('custom page filter', function () {
@ -142,7 +142,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+type:page'); frame.options.filter.should.eql('(page:false)+page:true');
}); });
it('custom status filter', function () { it('custom status filter', function () {
@ -163,7 +163,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(status:draft)+type:page'); frame.options.filter.should.eql('(status:draft)+page:true');
}); });
it('remove mobiledoc option from formats', function () { it('remove mobiledoc option from formats', function () {

View File

@ -21,7 +21,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('type:post'); frame.options.filter.should.eql('page:false');
}); });
it('should not work for non public context', function () { it('should not work for non public context', function () {
@ -36,7 +36,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
should.equal(frame.options.filter, '(type:post)+status:[draft,published,scheduled]'); should.equal(frame.options.filter, '(page:false)+status:[draft,published,scheduled]');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -56,7 +56,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(status:published+tag:eins)+type:post'); frame.options.filter.should.eql('(status:published+tag:eins)+page:false');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -76,7 +76,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:true+tag:eins)+type:post'); frame.options.filter.should.eql('(page:true+tag:eins)+page:false');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -96,7 +96,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:true)+type:post'); frame.options.filter.should.eql('(page:true)+page:false');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -116,7 +116,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('((page:true,page:false))+type:post'); frame.options.filter.should.eql('((page:true,page:false))+page:false');
}); });
it('remove mobiledoc option from formats', function () { it('remove mobiledoc option from formats', function () {
@ -137,7 +137,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}); });
describe('read', function () { describe('read', function () {
it('with apiType of "content" it forces type filter', function () { it('with apiType of "content" it forces page filter', function () {
const apiConfig = {}; const apiConfig = {};
const frame = { const frame = {
apiType: 'content', apiType: 'content',
@ -146,24 +146,24 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.read(apiConfig, frame); serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('type:post'); frame.options.filter.should.eql('page:false');
}); });
it('with apiType of "content" it forces type:post filter', function () { it('with apiType of "content" it forces page false filter', function () {
const apiConfig = {}; const apiConfig = {};
const frame = { const frame = {
apiType: 'content', apiType: 'content',
options: { options: {
filter: 'type:page' filter: 'page:true'
}, },
data: {} data: {}
}; };
serializers.input.posts.read(apiConfig, frame); serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('(type:page)+type:post'); frame.options.filter.should.eql('(page:true)+page:false');
}); });
it('with apiType of "admin" it forces type & status false filter', function () { it('with apiType of "admin" it forces page & status false filter', function () {
const apiConfig = {}; const apiConfig = {};
const frame = { const frame = {
apiType: 'admin', apiType: 'admin',
@ -179,10 +179,10 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.read(apiConfig, frame); serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('(type:post)+status:[draft,published,scheduled]'); frame.options.filter.should.eql('(page:false)+status:[draft,published,scheduled]');
}); });
it('with apiType of "admin" it forces type:post filter & respects custom status filter', function () { it('with apiType of "admin" it forces page filter & respects custom status filter', function () {
const apiConfig = {}; const apiConfig = {};
const frame = { const frame = {
apiType: 'admin', apiType: 'admin',
@ -199,7 +199,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.read(apiConfig, frame); serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('(status:draft)+type:post'); frame.options.filter.should.eql('(status:draft)+page:false');
}); });
it('remove mobiledoc option from formats', function () { it('remove mobiledoc option from formats', function () {

View File

@ -13,7 +13,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.browse(apiConfig, frame); serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('type:page'); frame.options.filter.should.eql('page:true');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -27,7 +27,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.browse(apiConfig, frame); serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(status:published+tag:eins)+type:page'); frame.options.filter.should.eql('(status:published+tag:eins)+page:true');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -41,7 +41,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.browse(apiConfig, frame); serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false+tag:eins)+type:page'); frame.options.filter.should.eql('(page:false+tag:eins)+page:true');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -55,7 +55,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.browse(apiConfig, frame); serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+type:page'); frame.options.filter.should.eql('(page:false)+page:true');
}); });
it('remove mobiledoc option from formats', function () { it('remove mobiledoc option from formats', function () {
@ -87,7 +87,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('type:page'); frame.options.filter.should.eql('page:true');
}); });
it('content api default', function () { it('content api default', function () {
@ -107,7 +107,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('type:page'); frame.options.filter.should.eql('page:true');
}); });
it('admin api default', function () { it('admin api default', function () {
@ -127,7 +127,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(type:page)+status:[draft,published,scheduled]'); frame.options.filter.should.eql('(page:true)+status:[draft,published,scheduled]');
}); });
it('custom page filter', function () { it('custom page filter', function () {
@ -142,7 +142,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+type:page'); frame.options.filter.should.eql('(page:false)+page:true');
}); });
it('custom status filter', function () { it('custom status filter', function () {
@ -163,7 +163,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
}; };
serializers.input.pages.read(apiConfig, frame); serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(status:draft)+type:page'); frame.options.filter.should.eql('(status:draft)+page:true');
}); });
it('remove mobiledoc option from formats', function () { it('remove mobiledoc option from formats', function () {

View File

@ -21,7 +21,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('type:post'); frame.options.filter.should.eql('page:false');
}); });
it('should not work for non public context', function () { it('should not work for non public context', function () {
@ -36,7 +36,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
should.equal(frame.options.filter, '(type:post)+status:[draft,published,scheduled]'); should.equal(frame.options.filter, '(page:false)+status:[draft,published,scheduled]');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -56,7 +56,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(status:published+tag:eins)+type:post'); frame.options.filter.should.eql('(status:published+tag:eins)+page:false');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -76,7 +76,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:true+tag:eins)+type:post'); frame.options.filter.should.eql('(page:true+tag:eins)+page:false');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -96,7 +96,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:true)+type:post'); frame.options.filter.should.eql('(page:true)+page:false');
}); });
it('combine filters', function () { it('combine filters', function () {
@ -116,7 +116,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.browse(apiConfig, frame); serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('((page:true,page:false))+type:post'); frame.options.filter.should.eql('((page:true,page:false))+page:false');
}); });
it('remove mobiledoc option from formats', function () { it('remove mobiledoc option from formats', function () {
@ -137,7 +137,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}); });
describe('read', function () { describe('read', function () {
it('with apiType of "content" it forces type filter', function () { it('with apiType of "content" it forces page filter', function () {
const apiConfig = {}; const apiConfig = {};
const frame = { const frame = {
apiType: 'content', apiType: 'content',
@ -146,24 +146,24 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.read(apiConfig, frame); serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('type:post'); frame.options.filter.should.eql('page:false');
}); });
it('with apiType of "content" it forces type:post filter', function () { it('with apiType of "content" it forces page false filter', function () {
const apiConfig = {}; const apiConfig = {};
const frame = { const frame = {
apiType: 'content', apiType: 'content',
options: { options: {
filter: 'type:page' filter: 'page:true'
}, },
data: {} data: {}
}; };
serializers.input.posts.read(apiConfig, frame); serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('(type:page)+type:post'); frame.options.filter.should.eql('(page:true)+page:false');
}); });
it('with apiType of "admin" it forces type & status false filter', function () { it('with apiType of "admin" it forces page & status false filter', function () {
const apiConfig = {}; const apiConfig = {};
const frame = { const frame = {
apiType: 'admin', apiType: 'admin',
@ -179,10 +179,10 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.read(apiConfig, frame); serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('(type:post)+status:[draft,published,scheduled]'); frame.options.filter.should.eql('(page:false)+status:[draft,published,scheduled]');
}); });
it('with apiType of "admin" it forces type:post filter & respects custom status filter', function () { it('with apiType of "admin" it forces page filter & respects custom status filter', function () {
const apiConfig = {}; const apiConfig = {};
const frame = { const frame = {
apiType: 'admin', apiType: 'admin',
@ -199,7 +199,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
}; };
serializers.input.posts.read(apiConfig, frame); serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('(status:draft)+type:post'); frame.options.filter.should.eql('(status:draft)+page:false');
}); });
it('remove mobiledoc option from formats', function () { it('remove mobiledoc option from formats', function () {

View File

@ -4,7 +4,7 @@ const PostsImporter = require('../../../../../../server/data/importer/importers/
describe('PostsImporter', function () { describe('PostsImporter', function () {
describe('#beforeImport', function () { describe('#beforeImport', function () {
it('converts post.page to post.type', function () { it('converts post.type to post.page', function () {
const fakePosts = [{ const fakePosts = [{
slug: 'page-false', slug: 'page-false',
page: false page: false
@ -25,67 +25,27 @@ describe('PostsImporter', function () {
const pageFalse = find(importer.dataToImport, {slug: 'page-false'}); const pageFalse = find(importer.dataToImport, {slug: 'page-false'});
should.exist(pageFalse); should.exist(pageFalse);
should.not.exist(pageFalse.page, 'pageFalse.page should not exist'); should.exist(pageFalse.page, 'pageFalse.page should exist');
should.exist(pageFalse.type, 'pageFalse.type should exist'); should.not.exist(pageFalse.type, 'pageFalse.type should not exist');
pageFalse.type.should.equal('post'); pageFalse.page.should.equal(false);
const pageTrue = find(importer.dataToImport, {slug: 'page-true'}); const pageTrue = find(importer.dataToImport, {slug: 'page-true'});
should.exist(pageTrue); should.exist(pageTrue);
should.not.exist(pageTrue.page, 'pageTrue.page should not exist'); should.exist(pageTrue.page, 'pageTrue.page should exist');
should.exist(pageTrue.type, 'pageTrue.type should exist'); should.not.exist(pageTrue.type, 'pageTrue.type should not exist');
pageTrue.type.should.equal('page'); pageTrue.page.should.equal(true);
const typePost = find(importer.dataToImport, {slug: 'type-post'}); const typePost = find(importer.dataToImport, {slug: 'type-post'});
should.exist(typePost); should.exist(typePost);
should.not.exist(typePost.page, 'typePost.page should not exist'); should.exist(typePost.page, 'typePost.page should exist');
should.exist(typePost.type, 'typePost.type should exist'); should.not.exist(typePost.type, 'typePost.type should not exist');
typePost.type.should.equal('post'); typePost.page.should.equal(false);
const typePage = find(importer.dataToImport, {slug: 'type-page'}); const typePage = find(importer.dataToImport, {slug: 'type-page'});
should.exist(typePage); should.exist(typePage);
should.not.exist(typePage.page, 'typePage.page should not exist'); should.exist(typePage.page, 'typePage.page should exist');
should.exist(typePage.type, 'typePage.type should exist'); should.not.exist(typePage.type, 'typePage.type should not exist');
typePage.type.should.equal('page'); typePage.page.should.equal(true);
});
it('gives precedence to post.type when post.page is also present', function () {
const fakePosts = [{
slug: 'page-false-type-page',
page: false,
type: 'page'
}, {
slug: 'page-true-type-page',
page: true,
type: 'page'
}, {
slug: 'page-false-type-post',
page: false,
type: 'post'
}, {
slug: 'page-true-type-post',
page: true,
type: 'post'
}];
const importer = new PostsImporter({posts: fakePosts});
importer.beforeImport();
const pageFalseTypePage = find(importer.dataToImport, {slug: 'page-false-type-page'});
should.exist(pageFalseTypePage);
pageFalseTypePage.type.should.equal('page', 'pageFalseTypePage.type');
const pageTrueTypePage = find(importer.dataToImport, {slug: 'page-true-type-page'});
should.exist(pageTrueTypePage);
pageTrueTypePage.type.should.equal('page', 'pageTrueTypePage.type');
const pageFalseTypePost = find(importer.dataToImport, {slug: 'page-false-type-post'});
should.exist(pageFalseTypePost);
pageFalseTypePost.type.should.equal('post', 'pageFalseTypePost.type');
const pageTrueTypePost = find(importer.dataToImport, {slug: 'page-true-type-post'});
should.exist(pageTrueTypePost);
pageTrueTypePost.type.should.equal('post', 'pageTrueTypePost.type');
}); });
}); });
}); });

View File

@ -19,8 +19,8 @@ var should = require('should'),
*/ */
describe('DB version integrity', function () { describe('DB version integrity', function () {
// Only these variables should need updating // Only these variables should need updating
const currentSchemaHash = '6b747746e8bcaa9532b69a2f72d0d577'; const currentSchemaHash = 'fda0398e93a74b2dc435cb4c026679ba';
const currentFixturesHash = 'd8e9f2d22a7c0714b301ad26bb735729'; const currentFixturesHash = 'c7b485fe2f16517295bd35c761129729';
// If this test is failing, then it is likely a change has been made that requires a DB version bump, // If this test is failing, then it is likely a change has been made that requires a DB version bump,
// and the values above will need updating as confirmation // and the values above will need updating as confirmation

View File

@ -81,22 +81,26 @@ describe('Validation', function () {
}); });
it('transforms 0 and 1', function () { it('transforms 0 and 1', function () {
const post = models.Post.forge(testUtils.DataGenerator.forKnex.createPost({slug: 'test', featured: 0})); const post = models.Post.forge(testUtils.DataGenerator.forKnex.createPost({slug: 'test', featured: 0, page: 1}));
post.get('featured').should.eql(0); post.get('featured').should.eql(0);
post.get('page').should.eql(1);
return validation.validateSchema('posts', post, {method: 'insert'}) return validation.validateSchema('posts', post, {method: 'insert'})
.then(function () { .then(function () {
post.get('featured').should.eql(false); post.get('featured').should.eql(false);
post.get('page').should.eql(true);
}); });
}); });
it('keeps true or false', function () { it('keeps true or false', function () {
const post = models.Post.forge(testUtils.DataGenerator.forKnex.createPost({slug: 'test', featured: true})); const post = models.Post.forge(testUtils.DataGenerator.forKnex.createPost({slug: 'test', featured: true, page: false}));
post.get('featured').should.eql(true); post.get('featured').should.eql(true);
post.get('page').should.eql(false);
return validation.validateSchema('posts', post, {method: 'insert'}) return validation.validateSchema('posts', post, {method: 'insert'})
.then(function () { .then(function () {
post.get('featured').should.eql(true); post.get('featured').should.eql(true);
post.get('page').should.eql(false);
}); });
}); });
}); });

View File

@ -45,21 +45,21 @@ describe('Unit: models/post', function () {
withRelated: ['tags'] withRelated: ['tags']
}).then(() => { }).then(() => {
queries.length.should.eql(2); 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`.`type` = ? 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`.`page` = ? and `posts`.`status` = ?))');
queries[0].bindings.should.eql([ queries[0].bindings.should.eql([
testUtils.filterData.data.posts[3].id, testUtils.filterData.data.posts[3].id,
'photo', 'photo',
'video', 'video',
'post', false,
'published' '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`.`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].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].bindings.should.eql([ queries[1].bindings.should.eql([
testUtils.filterData.data.posts[3].id, testUtils.filterData.data.posts[3].id,
'photo', 'photo',
'video', 'video',
'post', false,
'published', 'published',
3 3
]); ]);
@ -80,21 +80,21 @@ describe('Unit: models/post', function () {
withRelated: ['authors', 'tags'] withRelated: ['authors', 'tags']
}).then(() => { }).then(() => {
queries.length.should.eql(2); 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`.`type` = ? 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`.`page` = ? and `posts`.`status` = ?))');
queries[0].bindings.should.eql([ queries[0].bindings.should.eql([
'hash-audio', 'hash-audio',
'leslie', 'leslie',
'pat', 'pat',
'post', false,
'published' '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`.`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].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].bindings.should.eql([ queries[1].bindings.should.eql([
'hash-audio', 'hash-audio',
'leslie', 'leslie',
'pat', 'pat',
'post', false,
'published', 'published',
15 15
]); ]);
@ -116,17 +116,17 @@ describe('Unit: models/post', function () {
withRelated: ['tags'] withRelated: ['tags']
}).then(() => { }).then(() => {
queries.length.should.eql(2); 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`.`type` = ? and `posts`.`status` = ?))'); 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].bindings.should.eql([ queries[0].bindings.should.eql([
'2015-07-20', '2015-07-20',
'post', false,
'published' 'published'
]); ]);
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].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].bindings.should.eql([ queries[1].bindings.should.eql([
'2015-07-20', '2015-07-20',
'post', false,
'published', 'published',
5 5
]); ]);
@ -148,19 +148,19 @@ describe('Unit: models/post', function () {
withRelated: ['tags'] withRelated: ['tags']
}).then(() => { }).then(() => {
queries.length.should.eql(2); 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`.`type` = ? 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`.`page` = ? and `posts`.`status` = ?))');
queries[0].bindings.should.eql([ queries[0].bindings.should.eql([
'photo', 'photo',
'public', 'public',
'post', false,
'published' '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`.`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].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].bindings.should.eql([ queries[1].bindings.should.eql([
'photo', 'photo',
'public', 'public',
'post', false,
'published', 'published',
15 15
]); ]);
@ -181,19 +181,19 @@ describe('Unit: models/post', function () {
withRelated: ['authors'] withRelated: ['authors']
}).then(() => { }).then(() => {
queries.length.should.eql(2); 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`.`type` = ? 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`.`page` = ? and `posts`.`status` = ?))');
queries[0].bindings.should.eql([ queries[0].bindings.should.eql([
'leslie', 'leslie',
'public', 'public',
'post', false,
'published' '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`.`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].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].bindings.should.eql([ queries[1].bindings.should.eql([
'leslie', 'leslie',
'public', 'public',
'post', false,
'published', 'published',
15 15
]); ]);
@ -224,20 +224,20 @@ describe('Unit: models/post', function () {
} }
}).then(() => { }).then(() => {
queries.length.should.eql(2); 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`.`type` = ?))'); 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].bindings.should.eql([ queries[0].bindings.should.eql([
'published', 'published',
'draft', 'draft',
'published', 'published',
'post' false
]); ]);
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].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].bindings.should.eql([ queries[1].bindings.should.eql([
'published', 'published',
'draft', 'draft',
'published', 'published',
'post' false
]); ]);
}); });
}); });
@ -322,7 +322,7 @@ describe('Unit: models/post', function () {
should(filter).equal(null); should(filter).equal(null);
}); });
it('returns type:post filter for public context', function () { it('returns page:false filter for public context', function () {
const options = { const options = {
context: { context: {
public: true public: true
@ -331,17 +331,17 @@ describe('Unit: models/post', function () {
const filter = defaultFilters({}, options); const filter = defaultFilters({}, options);
filter.should.equal('type:post'); filter.should.equal('page:false');
}); });
it('returns type:post+status:published filter for non public context', function () { it('returns page:false+status:published filter for non public context', function () {
const options = { const options = {
context: 'user' context: 'user'
}; };
const filter = defaultFilters({}, options); const filter = defaultFilters({}, options);
filter.should.equal('type:post+status:published'); filter.should.equal('page:false+status:published');
}); });
}); });
}); });

View File

@ -16,7 +16,7 @@ describe('RSS: Generate Feed', function () {
posts = _.cloneDeep(testUtils.DataGenerator.forKnex.posts); posts = _.cloneDeep(testUtils.DataGenerator.forKnex.posts);
posts = _.filter(posts, function filter(post) { posts = _.filter(posts, function filter(post) {
return post.status === 'published' && post.type === 'post'; return post.status === 'published' && post.page === false;
}); });
_.each(posts, function (post) { _.each(posts, function (post) {

View File

@ -192,7 +192,7 @@ describe('Slack', function () {
}); });
it('does not make a request if post is a page', function () { it('does not make a request if post is a page', function () {
const post = testUtils.DataGenerator.forKnex.createPost({type: 'page'}); const post = testUtils.DataGenerator.forKnex.createPost({page: true});
isPostStub.returns(true); isPostStub.returns(true);
settingsCacheStub.withArgs('slack').returns(slackObjWithUrl); settingsCacheStub.withArgs('slack').returns(slackObjWithUrl);

View File

@ -74,14 +74,14 @@ DataGenerator.Content = {
title: 'This is a static page', title: 'This is a static page',
slug: 'static-page-test', slug: 'static-page-test',
mobiledoc: DataGenerator.markdownToMobiledoc('<h1>Static page test is what this is for.</h1><p>Hopefully you don\'t find it a bore.</p>'), mobiledoc: DataGenerator.markdownToMobiledoc('<h1>Static page test is what this is for.</h1><p>Hopefully you don\'t find it a bore.</p>'),
type: 'page' page: true
}, },
{ {
id: ObjectId.generate(), id: ObjectId.generate(),
title: 'This is a draft static page', title: 'This is a draft static page',
slug: 'static-page-draft', slug: 'static-page-draft',
mobiledoc: DataGenerator.markdownToMobiledoc('<h1>Static page test is what this is for.</h1><p>Hopefully you don\'t find it a bore.</p>'), mobiledoc: DataGenerator.markdownToMobiledoc('<h1>Static page test is what this is for.</h1><p>Hopefully you don\'t find it a bore.</p>'),
type: 'page', page: true,
status: 'draft' status: 'draft'
}, },
{ {
@ -468,7 +468,7 @@ DataGenerator.forKnex = (function () {
status: 'published', status: 'published',
feature_image: null, feature_image: null,
featured: false, featured: false,
type: 'post', page: false,
slug: 'slug', slug: 'slug',
author_id: DataGenerator.Content.users[0].id, author_id: DataGenerator.Content.users[0].id,
updated_at: new Date(), updated_at: new Date(),