mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 18:52:14 +03:00
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 commita5a7e7e919
. Revert "Updated frontend canary url config for page/type" This reverts commit19100ec5e6
. Revert "Updated canary api to handle type column correctly (#11006)" This reverts commitc3e8ba0523
. Revert "Ensured `page` filter works in routes.yaml" This reverts commit9037c19e50
. Revert "Replaced usage of mongo util with nql-map-key-values" This reverts commit8c5f1d0ef0
. Revert "Added shared nql-map-key-values module" This reverts commitef4fd4b8ef
. Revert "Ensured page prop is present on content api response" This reverts commitcfa0a0862b
. Revert "Fixed failing regression tests" This reverts commit9c2bb3811f
. Revert "Updated xmlrpc and slack service to use type column" This reverts commit44a02c7d36
. Revert "Updated v0.1 posts api to work with type column" This reverts commit2c81d7c914
. Revert "Removed updates to v0.1 specific code" This reverts commit08d83c1f53
. Revert "Added missing context from ValidationError" This reverts commitcd45ab4f54
. Revert "Renamed page->type in the page&posts serializers" This reverts commitdf99e724e3
. Revert "Added mongo helper to input serializers" This reverts commitfb8eadb4a8
. Revert "Passed mongoTransformer through to NQL" This reverts commit0ae3f0fdfc
. Revert "Permitted mongoTransformer option for read methods" This reverts commita89376bf26
. Revert "Updated the count plugin to reference the type column" This reverts commita52f15d3d3
. Revert "Updated hashes for db integrity check" This reverts commitbb6b337be3
. Revert "Remove page column and remaining references" This reverts commit9d7190d692
. Revert "Added type column to data generator" This reverts commite59806cb45
. Revert "Removed references to page column in rss tests" This reverts commit04d0f855de
. Revert "Removed page column references in validation tests" This reverts commitf0afbc5cc0
. Revert "Updated the post model to use the `type` column" This reverts commit1189bc823a
. Revert "Updated url service to use type column" This reverts commit61612ba8fd
. Revert "Updated the v2 api to deal with type column" This reverts commit57afb2de2b
. Revert "Added type property to post model defaults" This reverts commitdc3345b1c5
. Revert "Added type property to the default post fixtures" This reverts commit82d8c38033
. Revert "Added type column to posts table" This reverts commit9b85fc6a69
.
This commit is contained in:
parent
3764e023fb
commit
80fbfd7a85
@ -23,8 +23,6 @@ const _ = require('lodash'),
|
||||
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.
|
||||
* 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.
|
||||
if (this.router.getFilter()) {
|
||||
this.filter = this.router.getFilter();
|
||||
this.nql = nql(this.filter, {
|
||||
expansions: EXPANSIONS,
|
||||
transformer: mapNQLKeyValues({
|
||||
key: {
|
||||
from: 'page',
|
||||
to: 'type'
|
||||
},
|
||||
values: [{
|
||||
from: false,
|
||||
to: 'post'
|
||||
}, {
|
||||
from: true,
|
||||
to: 'page'
|
||||
}]
|
||||
})
|
||||
});
|
||||
this.nql = nql(this.filter, {expansions: EXPANSIONS});
|
||||
debug('filter', this.filter);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ module.exports = [
|
||||
type: 'posts',
|
||||
modelOptions: {
|
||||
modelName: 'Post',
|
||||
filter: 'visibility:public+status:published+type:post',
|
||||
filter: 'visibility:public+status:published+page:false',
|
||||
exclude: [
|
||||
'title',
|
||||
'mobiledoc',
|
||||
@ -79,7 +79,7 @@ module.exports = [
|
||||
'primary_tag',
|
||||
'primary_author'
|
||||
],
|
||||
filter: 'visibility:public+status:published+type:page'
|
||||
filter: 'visibility:public+status:published+page:true'
|
||||
},
|
||||
events: {
|
||||
add: 'page.published',
|
||||
|
@ -8,7 +8,7 @@ module.exports = [
|
||||
type: 'posts',
|
||||
modelOptions: {
|
||||
modelName: 'Post',
|
||||
filter: 'visibility:public+status:published+type:post',
|
||||
filter: 'visibility:public+status:published+page:false',
|
||||
exclude: [
|
||||
'title',
|
||||
'mobiledoc',
|
||||
@ -73,7 +73,7 @@ module.exports = [
|
||||
'primary_tag',
|
||||
'primary_author'
|
||||
],
|
||||
filter: 'visibility:public+status:published+type:page'
|
||||
filter: 'visibility:public+status:published+page:true'
|
||||
},
|
||||
events: {
|
||||
add: 'page.published',
|
||||
|
@ -8,7 +8,7 @@ module.exports = [
|
||||
type: 'posts',
|
||||
modelOptions: {
|
||||
modelName: 'Post',
|
||||
filter: 'visibility:public+status:published+type:post',
|
||||
filter: 'visibility:public+status:published+page:false',
|
||||
exclude: [
|
||||
'title',
|
||||
'mobiledoc',
|
||||
@ -79,7 +79,7 @@ module.exports = [
|
||||
'primary_tag',
|
||||
'primary_author'
|
||||
],
|
||||
filter: 'visibility:public+status:published+type:page'
|
||||
filter: 'visibility:public+status:published+page:true'
|
||||
},
|
||||
events: {
|
||||
add: 'page.published',
|
||||
|
@ -1,24 +1,9 @@
|
||||
const _ = require('lodash');
|
||||
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 url = require('./utils/url');
|
||||
const localUtils = require('../../index');
|
||||
|
||||
const replacePageWithType = mapNQLKeyValues({
|
||||
key: {
|
||||
from: 'page',
|
||||
to: 'type'
|
||||
},
|
||||
values: [{
|
||||
from: false,
|
||||
to: 'post'
|
||||
}, {
|
||||
from: true,
|
||||
to: 'page'
|
||||
}]
|
||||
});
|
||||
|
||||
function removeMobiledocFormat(frame) {
|
||||
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
|
||||
frame.options.formats = frame.options.formats.filter((format) => {
|
||||
@ -70,9 +55,9 @@ function defaultFormat(frame) {
|
||||
*/
|
||||
const forcePageFilter = (frame) => {
|
||||
if (frame.options.filter) {
|
||||
frame.options.filter = `(${frame.options.filter})+type:page`;
|
||||
frame.options.filter = `(${frame.options.filter})+page:true`;
|
||||
} else {
|
||||
frame.options.filter = 'type:page';
|
||||
frame.options.filter = 'page:true';
|
||||
}
|
||||
};
|
||||
|
||||
@ -101,8 +86,6 @@ module.exports = {
|
||||
defaultRelations(frame);
|
||||
}
|
||||
|
||||
frame.options.mongoTransformer = replacePageWithType;
|
||||
|
||||
debug(frame.options);
|
||||
},
|
||||
|
||||
@ -140,7 +123,7 @@ module.exports = {
|
||||
|
||||
// @NOTE: force storing page
|
||||
if (options.add) {
|
||||
frame.data.pages[0].type = 'page';
|
||||
frame.data.pages[0].page = true;
|
||||
}
|
||||
|
||||
// CASE: Transform short to long format
|
||||
@ -180,7 +163,7 @@ module.exports = {
|
||||
destroy(apiConfig, frame) {
|
||||
frame.options.destroyBy = {
|
||||
id: frame.options.id,
|
||||
type: 'page'
|
||||
page: true
|
||||
};
|
||||
|
||||
defaultFormat(frame);
|
||||
|
@ -1,25 +1,10 @@
|
||||
const _ = require('lodash');
|
||||
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 localUtils = require('../../index');
|
||||
const labs = require('../../../../../services/labs');
|
||||
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) {
|
||||
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
|
||||
frame.options.formats = frame.options.formats.filter((format) => {
|
||||
@ -79,9 +64,9 @@ function defaultFormat(frame) {
|
||||
*/
|
||||
const forcePageFilter = (frame) => {
|
||||
if (frame.options.filter) {
|
||||
frame.options.filter = `(${frame.options.filter})+type:post`;
|
||||
frame.options.filter = `(${frame.options.filter})+page:false`;
|
||||
} else {
|
||||
frame.options.filter = 'type:post';
|
||||
frame.options.filter = 'page:false';
|
||||
}
|
||||
};
|
||||
|
||||
@ -123,8 +108,6 @@ module.exports = {
|
||||
defaultRelations(frame);
|
||||
}
|
||||
|
||||
frame.options.mongoTransformer = replacePageWithType;
|
||||
|
||||
debug(frame.options);
|
||||
},
|
||||
|
||||
@ -175,7 +158,7 @@ module.exports = {
|
||||
|
||||
// @NOTE: force adding post
|
||||
if (options.add) {
|
||||
frame.data.posts[0].type = 'post';
|
||||
frame.data.posts[0].page = false;
|
||||
}
|
||||
|
||||
// CASE: Transform short to long format
|
||||
@ -213,7 +196,7 @@ module.exports = {
|
||||
destroy(apiConfig, frame) {
|
||||
frame.options.destroyBy = {
|
||||
id: frame.options.id,
|
||||
type: 'post'
|
||||
page: false
|
||||
};
|
||||
|
||||
defaultFormat(frame);
|
||||
|
@ -35,10 +35,6 @@ const mapPost = (model, frame) => {
|
||||
url.forPost(model.id, jsonModel, frame);
|
||||
|
||||
if (utils.isContentAPI(frame)) {
|
||||
// Content api v2 still expects page prop
|
||||
if (jsonModel.type === 'page') {
|
||||
jsonModel.page = true;
|
||||
}
|
||||
date.forPost(jsonModel);
|
||||
members.forPost(jsonModel, frame);
|
||||
}
|
||||
@ -61,8 +57,6 @@ const mapPost = (model, frame) => {
|
||||
});
|
||||
}
|
||||
|
||||
delete jsonModel.type;
|
||||
|
||||
return jsonModel;
|
||||
};
|
||||
|
||||
|
@ -16,49 +16,6 @@ const Promise = require('bluebird'),
|
||||
],
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -101,12 +58,10 @@ posts = {
|
||||
* @returns {Object} options
|
||||
*/
|
||||
function modelQuery(options) {
|
||||
options.mongoTransformer = replacePageWithType;
|
||||
|
||||
return models.Post.findPage(options)
|
||||
.then(({data, meta}) => {
|
||||
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
|
||||
};
|
||||
});
|
||||
@ -146,8 +101,6 @@ posts = {
|
||||
* @returns {Object} options
|
||||
*/
|
||||
function modelQuery(options) {
|
||||
options.mongoTransformer = replacePageWithType;
|
||||
|
||||
return models.Post.findOne(options.data, omit(options, ['data']))
|
||||
.then((model) => {
|
||||
if (!model) {
|
||||
@ -157,7 +110,7 @@ posts = {
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
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) => {
|
||||
if (!model) {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
@ -213,7 +166,7 @@ posts = {
|
||||
}
|
||||
|
||||
return {
|
||||
posts: [post].map(convertTypeToPage)
|
||||
posts: [post]
|
||||
};
|
||||
});
|
||||
}
|
||||
@ -249,7 +202,7 @@ posts = {
|
||||
* @returns {Object} 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) => {
|
||||
const post = urlsForPost(model.id, model.toJSON(options), options);
|
||||
|
||||
@ -258,9 +211,7 @@ posts = {
|
||||
post.statusChanged = true;
|
||||
}
|
||||
|
||||
return {
|
||||
posts: [post].map(convertTypeToPage)
|
||||
};
|
||||
return {posts: [post]};
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,9 @@
|
||||
const _ = require('lodash');
|
||||
const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values');
|
||||
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:pages');
|
||||
const converters = require('../../../../../lib/mobiledoc/converters');
|
||||
const url = require('./utils/url');
|
||||
const localUtils = require('../../index');
|
||||
|
||||
const replacePageWithType = mapNQLKeyValues({
|
||||
key: {
|
||||
from: 'page',
|
||||
to: 'type'
|
||||
},
|
||||
values: [{
|
||||
from: false,
|
||||
to: 'post'
|
||||
}, {
|
||||
from: true,
|
||||
to: 'page'
|
||||
}]
|
||||
});
|
||||
|
||||
function removeMobiledocFormat(frame) {
|
||||
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
|
||||
frame.options.formats = frame.options.formats.filter((format) => {
|
||||
@ -70,9 +55,9 @@ function defaultFormat(frame) {
|
||||
*/
|
||||
const forcePageFilter = (frame) => {
|
||||
if (frame.options.filter) {
|
||||
frame.options.filter = `(${frame.options.filter})+type:page`;
|
||||
frame.options.filter = `(${frame.options.filter})+page:true`;
|
||||
} else {
|
||||
frame.options.filter = 'type:page';
|
||||
frame.options.filter = 'page:true';
|
||||
}
|
||||
};
|
||||
|
||||
@ -101,8 +86,6 @@ module.exports = {
|
||||
defaultRelations(frame);
|
||||
}
|
||||
|
||||
frame.options.mongoTransformer = replacePageWithType;
|
||||
|
||||
debug(frame.options);
|
||||
},
|
||||
|
||||
@ -140,7 +123,7 @@ module.exports = {
|
||||
|
||||
// @NOTE: force storing page
|
||||
if (options.add) {
|
||||
frame.data.pages[0].type = 'page';
|
||||
frame.data.pages[0].page = true;
|
||||
}
|
||||
|
||||
// CASE: Transform short to long format
|
||||
@ -180,7 +163,7 @@ module.exports = {
|
||||
destroy(apiConfig, frame) {
|
||||
frame.options.destroyBy = {
|
||||
id: frame.options.id,
|
||||
type: 'page'
|
||||
page: true
|
||||
};
|
||||
|
||||
defaultFormat(frame);
|
||||
|
@ -1,25 +1,10 @@
|
||||
const _ = require('lodash');
|
||||
const mapNQLKeyValues = require('../../../../../../shared/nql-map-key-values');
|
||||
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:posts');
|
||||
const url = require('./utils/url');
|
||||
const localUtils = require('../../index');
|
||||
const labs = require('../../../../../services/labs');
|
||||
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) {
|
||||
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
|
||||
frame.options.formats = frame.options.formats.filter((format) => {
|
||||
@ -79,9 +64,9 @@ function defaultFormat(frame) {
|
||||
*/
|
||||
const forcePageFilter = (frame) => {
|
||||
if (frame.options.filter) {
|
||||
frame.options.filter = `(${frame.options.filter})+type:post`;
|
||||
frame.options.filter = `(${frame.options.filter})+page:false`;
|
||||
} else {
|
||||
frame.options.filter = 'type:post';
|
||||
frame.options.filter = 'page:false';
|
||||
}
|
||||
};
|
||||
|
||||
@ -123,8 +108,6 @@ module.exports = {
|
||||
defaultRelations(frame);
|
||||
}
|
||||
|
||||
frame.options.mongoTransformer = replacePageWithType;
|
||||
|
||||
debug(frame.options);
|
||||
},
|
||||
|
||||
@ -175,7 +158,7 @@ module.exports = {
|
||||
|
||||
// @NOTE: force adding post
|
||||
if (options.add) {
|
||||
frame.data.posts[0].type = 'post';
|
||||
frame.data.posts[0].page = false;
|
||||
}
|
||||
|
||||
// CASE: Transform short to long format
|
||||
@ -213,7 +196,7 @@ module.exports = {
|
||||
destroy(apiConfig, frame) {
|
||||
frame.options.destroyBy = {
|
||||
id: frame.options.id,
|
||||
type: 'post'
|
||||
page: false
|
||||
};
|
||||
|
||||
defaultFormat(frame);
|
||||
|
@ -35,10 +35,6 @@ const mapPost = (model, frame) => {
|
||||
url.forPost(model.id, jsonModel, frame);
|
||||
|
||||
if (utils.isContentAPI(frame)) {
|
||||
// Content api v2 still expects page prop
|
||||
if (jsonModel.type === 'page') {
|
||||
jsonModel.page = true;
|
||||
}
|
||||
date.forPost(jsonModel);
|
||||
members.forPost(jsonModel, frame);
|
||||
}
|
||||
@ -61,8 +57,6 @@ const mapPost = (model, frame) => {
|
||||
});
|
||||
}
|
||||
|
||||
delete jsonModel.type;
|
||||
|
||||
return jsonModel;
|
||||
};
|
||||
|
||||
|
@ -21,16 +21,6 @@ class PostsImporter extends BaseImporter {
|
||||
if (!validation.validator.isUUID(obj.uuid || '')) {
|
||||
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();
|
||||
|
||||
_.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
|
||||
// (see https://github.com/TryGhost/Ghost/issues/8963)
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -345,8 +345,7 @@ validate = function validate(value, key, validations, tableName) {
|
||||
}
|
||||
|
||||
validationErrors.push(new common.errors.ValidationError({
|
||||
message: translation,
|
||||
context: `${tableName}.${key}`
|
||||
message: translation
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -668,11 +668,11 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||
case 'edit':
|
||||
return baseOptions.concat(extraOptions, ['id', 'require']);
|
||||
case 'findOne':
|
||||
return baseOptions.concat(extraOptions, ['columns', 'require', 'mongoTransformer']);
|
||||
return baseOptions.concat(extraOptions, ['columns', 'require']);
|
||||
case 'findAll':
|
||||
return baseOptions.concat(extraOptions, ['columns', 'mongoTransformer']);
|
||||
return baseOptions.concat(extraOptions, ['columns']);
|
||||
case 'findPage':
|
||||
return baseOptions.concat(extraOptions, ['filter', 'order', 'page', 'limit', 'columns', 'mongoTransformer']);
|
||||
return baseOptions.concat(extraOptions, ['filter', 'order', 'page', 'limit', 'columns']);
|
||||
default:
|
||||
return baseOptions.concat(extraOptions);
|
||||
}
|
||||
|
@ -61,7 +61,6 @@ const filter = function filter(Bookshelf) {
|
||||
let extra = this.extraFilters(options);
|
||||
let overrides = this.enforcedFilters(options);
|
||||
let defaults = this.defaultFilters(options);
|
||||
let transformer = options.mongoTransformer;
|
||||
|
||||
debug('custom', custom);
|
||||
debug('extra', extra);
|
||||
@ -82,8 +81,7 @@ const filter = function filter(Bookshelf) {
|
||||
relations: RELATIONS,
|
||||
expansions: EXPANSIONS,
|
||||
overrides: overrides,
|
||||
defaults: defaults,
|
||||
transformer: transformer
|
||||
defaults: defaults
|
||||
}).querySQL(qb);
|
||||
});
|
||||
} catch (err) {
|
||||
|
@ -19,7 +19,7 @@ module.exports = function (Bookshelf) {
|
||||
|
||||
if (options.context && options.context.public) {
|
||||
// @TODO use the filter behavior for posts
|
||||
qb.andWhere('posts.type', '=', 'post');
|
||||
qb.andWhere('posts.page', '=', false);
|
||||
qb.andWhere('posts.status', '=', 'published');
|
||||
}
|
||||
});
|
||||
@ -36,7 +36,7 @@ module.exports = function (Bookshelf) {
|
||||
|
||||
if (options.context && options.context.public) {
|
||||
// @TODO use the filter behavior for posts
|
||||
qb.andWhere('posts.type', '=', 'post');
|
||||
qb.andWhere('posts.page', '=', false);
|
||||
qb.andWhere('posts.status', '=', 'published');
|
||||
}
|
||||
});
|
||||
|
@ -44,7 +44,7 @@ Post = ghostBookshelf.Model.extend({
|
||||
uuid: uuid.v4(),
|
||||
status: 'draft',
|
||||
featured: false,
|
||||
type: 'post',
|
||||
page: false,
|
||||
visibility: 'public'
|
||||
};
|
||||
},
|
||||
@ -74,10 +74,10 @@ Post = ghostBookshelf.Model.extend({
|
||||
|
||||
emitChange: function emitChange(event, options = {}) {
|
||||
let eventToTrigger;
|
||||
let resourceType = this.get('type');
|
||||
let resourceType = this.get('page') ? 'page' : 'post';
|
||||
|
||||
if (options.usePreviousAttribute) {
|
||||
resourceType = this.previous('type');
|
||||
resourceType = this.previous('page') ? 'page' : 'post';
|
||||
}
|
||||
|
||||
eventToTrigger = resourceType + '.' + event;
|
||||
@ -118,7 +118,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('type') !== model.previous('type');
|
||||
model.resourceTypeChanging = model.get('page') !== model.previous('page');
|
||||
model.publishedAtHasChanged = model.hasDateChanged('published_at');
|
||||
model.needsReschedule = model.publishedAtHasChanged && model.isScheduled;
|
||||
|
||||
@ -567,7 +567,7 @@ Post = ghostBookshelf.Model.extend({
|
||||
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);
|
||||
}
|
||||
|
||||
filter = `page:${options.staticPages ? 'true' : 'false'}`;
|
||||
filter = `page:${options.staticPages}`;
|
||||
} else if (options.staticPages === 'all') {
|
||||
filter = 'page:[true, false]';
|
||||
}
|
||||
@ -750,12 +750,6 @@ Post = ghostBookshelf.Model.extend({
|
||||
edit: function edit(data, unfilteredOptions) {
|
||||
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 = () => {
|
||||
options.forUpdate = true;
|
||||
|
||||
|
@ -45,7 +45,7 @@ function ping(post) {
|
||||
if (slackSettings && slackSettings.url && slackSettings.url !== '') {
|
||||
slackSettings.username = slackSettings.username ? slackSettings.username : 'Ghost';
|
||||
// Only ping when not a page
|
||||
if (post.type === 'page') {
|
||||
if (post.page) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ function ping(post) {
|
||||
title = post.title,
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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}
|
||||
```
|
@ -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);
|
@ -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"
|
||||
}
|
||||
}
|
@ -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('type').should.eql('page');
|
||||
model.get('page').should.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
@ -116,7 +116,7 @@ describe('Pages API', function () {
|
||||
}, testUtils.context.internal);
|
||||
})
|
||||
.then((model) => {
|
||||
model.get('type').should.eql('page');
|
||||
model.get('page').should.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -31,8 +31,6 @@ const expectedProperties = {
|
||||
.without('visibility')
|
||||
.without('locale')
|
||||
.without('page')
|
||||
// v2 API doesn't return new type field
|
||||
.without('type')
|
||||
// deprecated
|
||||
.without('author_id')
|
||||
// always returns computed properties
|
||||
@ -48,8 +46,6 @@ const expectedProperties = {
|
||||
.without('visibility')
|
||||
.without('locale')
|
||||
.without('page')
|
||||
// v2 API doesn't return new type field
|
||||
.without('type')
|
||||
// deprecated
|
||||
.without('author_id')
|
||||
// always returns computed properties
|
||||
|
@ -23,8 +23,6 @@ const expectedProperties = {
|
||||
.without('locale', 'visibility')
|
||||
// These fields aren't useful as they always have known values
|
||||
.without('status')
|
||||
// v2 API doesn't return new type field
|
||||
.without('type')
|
||||
// @TODO: https://github.com/TryGhost/Ghost/issues/10335
|
||||
// .without('page')
|
||||
// v2 returns a calculated excerpt field
|
||||
|
@ -80,7 +80,7 @@ describe('Schedules API', function () {
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fifth',
|
||||
type: 'page'
|
||||
page: true
|
||||
}));
|
||||
|
||||
return Promise.mapSeries(resources, function (post) {
|
||||
|
@ -25,7 +25,6 @@ const expectedProperties = {
|
||||
.without('status')
|
||||
// @TODO: https://github.com/TryGhost/Ghost/issues/10335
|
||||
// .without('page')
|
||||
.without('type')
|
||||
// canary returns a calculated excerpt field
|
||||
.concat('excerpt')
|
||||
,
|
||||
|
@ -20,8 +20,6 @@ const expectedProperties = {
|
||||
.keys()
|
||||
// by default we only return html
|
||||
.without('mobiledoc', 'plaintext')
|
||||
.without('type')
|
||||
.concat('page')
|
||||
// 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('canonical_url')
|
||||
|
@ -80,7 +80,7 @@ describe('Schedules API', function () {
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fifth',
|
||||
type: 'page'
|
||||
page: true
|
||||
}));
|
||||
|
||||
return Promise.mapSeries(resources, function (post) {
|
||||
|
@ -25,7 +25,6 @@ const expectedProperties = {
|
||||
.without('status')
|
||||
// @TODO: https://github.com/TryGhost/Ghost/issues/10335
|
||||
// .without('page')
|
||||
.without('type')
|
||||
// v2 returns a calculated excerpt field
|
||||
.concat('excerpt')
|
||||
,
|
||||
|
@ -532,7 +532,7 @@ describe('Post Model', function () {
|
||||
}).then(function (edited) {
|
||||
should.exist(edited);
|
||||
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);
|
||||
should.exist(eventsTriggered['post.deleted']);
|
||||
@ -542,7 +542,7 @@ describe('Post Model', function () {
|
||||
}).then(function (edited) {
|
||||
should.exist(edited);
|
||||
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);
|
||||
should.exist(eventsTriggered['post.deleted']);
|
||||
@ -569,7 +569,7 @@ describe('Post Model', function () {
|
||||
}).then(function (edited) {
|
||||
should.exist(edited);
|
||||
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);
|
||||
should.exist(eventsTriggered['post.deleted']);
|
||||
@ -580,7 +580,7 @@ describe('Post Model', function () {
|
||||
}).then(function (edited) {
|
||||
should.exist(edited);
|
||||
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);
|
||||
should.exist(eventsTriggered['page.unscheduled']);
|
||||
@ -606,7 +606,7 @@ describe('Post Model', function () {
|
||||
}).then(function (edited) {
|
||||
should.exist(edited);
|
||||
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);
|
||||
should.exist(eventsTriggered['post.unpublished']);
|
||||
@ -618,7 +618,7 @@ describe('Post Model', function () {
|
||||
}).then(function (edited) {
|
||||
should.exist(edited);
|
||||
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);
|
||||
should.exist(eventsTriggered['page.unpublished']);
|
||||
@ -644,7 +644,7 @@ describe('Post Model', function () {
|
||||
}).then(function (edited) {
|
||||
should.exist(edited);
|
||||
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);
|
||||
should.exist(eventsTriggered['post.deleted']);
|
||||
@ -657,7 +657,7 @@ describe('Post Model', function () {
|
||||
}).then(function (edited) {
|
||||
should.exist(edited);
|
||||
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);
|
||||
should.exist(eventsTriggered['page.unpublished']);
|
||||
@ -1175,7 +1175,7 @@ describe('Post Model', function () {
|
||||
page = results.toJSON();
|
||||
page.id.should.equal(firstItemData.id);
|
||||
page.status.should.equal('published');
|
||||
page.type.should.equal('page');
|
||||
page.page.should.be.true();
|
||||
|
||||
// Destroy the page
|
||||
return results.destroy(firstItemData);
|
||||
|
@ -1915,7 +1915,7 @@ describe('Integration - Web - Site', function () {
|
||||
response.statusCode.should.eql(200);
|
||||
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.limit.should.eql(2);
|
||||
});
|
||||
@ -3659,7 +3659,7 @@ describe('Integration - Web - Site', function () {
|
||||
response.statusCode.should.eql(200);
|
||||
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.limit.should.eql(2);
|
||||
});
|
||||
|
@ -13,7 +13,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
serializers.input.pages.browse(apiConfig, frame);
|
||||
frame.options.filter.should.eql('type:page');
|
||||
frame.options.filter.should.eql('page:true');
|
||||
});
|
||||
|
||||
it('combine filters', function () {
|
||||
@ -27,7 +27,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -41,7 +41,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -55,7 +55,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -87,7 +87,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -107,7 +107,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -127,7 +127,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -142,7 +142,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -163,7 +163,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
|
@ -21,7 +21,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -36,7 +36,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -56,7 +56,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -76,7 +76,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -96,7 +96,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -116,7 +116,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -137,7 +137,7 @@ describe('Unit: canary/utils/serializers/input/posts', 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 frame = {
|
||||
apiType: 'content',
|
||||
@ -146,24 +146,24 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 frame = {
|
||||
apiType: 'content',
|
||||
options: {
|
||||
filter: 'type:page'
|
||||
filter: 'page:true'
|
||||
},
|
||||
data: {}
|
||||
};
|
||||
|
||||
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 frame = {
|
||||
apiType: 'admin',
|
||||
@ -179,10 +179,10 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 frame = {
|
||||
apiType: 'admin',
|
||||
@ -199,7 +199,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
|
@ -13,7 +13,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
serializers.input.pages.browse(apiConfig, frame);
|
||||
frame.options.filter.should.eql('type:page');
|
||||
frame.options.filter.should.eql('page:true');
|
||||
});
|
||||
|
||||
it('combine filters', function () {
|
||||
@ -27,7 +27,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -41,7 +41,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -55,7 +55,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -87,7 +87,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -107,7 +107,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -127,7 +127,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -142,7 +142,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -163,7 +163,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
|
@ -21,7 +21,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -36,7 +36,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -56,7 +56,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -76,7 +76,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -96,7 +96,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -116,7 +116,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
@ -137,7 +137,7 @@ describe('Unit: v2/utils/serializers/input/posts', 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 frame = {
|
||||
apiType: 'content',
|
||||
@ -146,24 +146,24 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 frame = {
|
||||
apiType: 'content',
|
||||
options: {
|
||||
filter: 'type:page'
|
||||
filter: 'page:true'
|
||||
},
|
||||
data: {}
|
||||
};
|
||||
|
||||
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 frame = {
|
||||
apiType: 'admin',
|
||||
@ -179,10 +179,10 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 frame = {
|
||||
apiType: 'admin',
|
||||
@ -199,7 +199,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
||||
};
|
||||
|
||||
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 () {
|
||||
|
@ -4,7 +4,7 @@ const PostsImporter = require('../../../../../../server/data/importer/importers/
|
||||
|
||||
describe('PostsImporter', function () {
|
||||
describe('#beforeImport', function () {
|
||||
it('converts post.page to post.type', function () {
|
||||
it('converts post.type to post.page', function () {
|
||||
const fakePosts = [{
|
||||
slug: 'page-false',
|
||||
page: false
|
||||
@ -25,67 +25,27 @@ describe('PostsImporter', function () {
|
||||
|
||||
const pageFalse = find(importer.dataToImport, {slug: 'page-false'});
|
||||
should.exist(pageFalse);
|
||||
should.not.exist(pageFalse.page, 'pageFalse.page should not exist');
|
||||
should.exist(pageFalse.type, 'pageFalse.type should exist');
|
||||
pageFalse.type.should.equal('post');
|
||||
should.exist(pageFalse.page, 'pageFalse.page should exist');
|
||||
should.not.exist(pageFalse.type, 'pageFalse.type should not exist');
|
||||
pageFalse.page.should.equal(false);
|
||||
|
||||
const pageTrue = find(importer.dataToImport, {slug: 'page-true'});
|
||||
should.exist(pageTrue);
|
||||
should.not.exist(pageTrue.page, 'pageTrue.page should not exist');
|
||||
should.exist(pageTrue.type, 'pageTrue.type should exist');
|
||||
pageTrue.type.should.equal('page');
|
||||
should.exist(pageTrue.page, 'pageTrue.page should exist');
|
||||
should.not.exist(pageTrue.type, 'pageTrue.type should not exist');
|
||||
pageTrue.page.should.equal(true);
|
||||
|
||||
const typePost = find(importer.dataToImport, {slug: 'type-post'});
|
||||
should.exist(typePost);
|
||||
should.not.exist(typePost.page, 'typePost.page should not exist');
|
||||
should.exist(typePost.type, 'typePost.type should exist');
|
||||
typePost.type.should.equal('post');
|
||||
should.exist(typePost.page, 'typePost.page should exist');
|
||||
should.not.exist(typePost.type, 'typePost.type should not exist');
|
||||
typePost.page.should.equal(false);
|
||||
|
||||
const typePage = find(importer.dataToImport, {slug: 'type-page'});
|
||||
should.exist(typePage);
|
||||
should.not.exist(typePage.page, 'typePage.page should not exist');
|
||||
should.exist(typePage.type, 'typePage.type should exist');
|
||||
typePage.type.should.equal('page');
|
||||
});
|
||||
|
||||
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');
|
||||
should.exist(typePage.page, 'typePage.page should exist');
|
||||
should.not.exist(typePage.type, 'typePage.type should not exist');
|
||||
typePage.page.should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -19,8 +19,8 @@ var should = require('should'),
|
||||
*/
|
||||
describe('DB version integrity', function () {
|
||||
// Only these variables should need updating
|
||||
const currentSchemaHash = '6b747746e8bcaa9532b69a2f72d0d577';
|
||||
const currentFixturesHash = 'd8e9f2d22a7c0714b301ad26bb735729';
|
||||
const currentSchemaHash = 'fda0398e93a74b2dc435cb4c026679ba';
|
||||
const currentFixturesHash = 'c7b485fe2f16517295bd35c761129729';
|
||||
|
||||
// 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
|
||||
|
@ -81,22 +81,26 @@ describe('Validation', 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('page').should.eql(1);
|
||||
|
||||
return validation.validateSchema('posts', post, {method: 'insert'})
|
||||
.then(function () {
|
||||
post.get('featured').should.eql(false);
|
||||
post.get('page').should.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
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('page').should.eql(false);
|
||||
|
||||
return validation.validateSchema('posts', post, {method: 'insert'})
|
||||
.then(function () {
|
||||
post.get('featured').should.eql(true);
|
||||
post.get('page').should.eql(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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`.`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([
|
||||
testUtils.filterData.data.posts[3].id,
|
||||
'photo',
|
||||
'video',
|
||||
'post',
|
||||
false,
|
||||
'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([
|
||||
testUtils.filterData.data.posts[3].id,
|
||||
'photo',
|
||||
'video',
|
||||
'post',
|
||||
false,
|
||||
'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`.`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([
|
||||
'hash-audio',
|
||||
'leslie',
|
||||
'pat',
|
||||
'post',
|
||||
false,
|
||||
'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([
|
||||
'hash-audio',
|
||||
'leslie',
|
||||
'pat',
|
||||
'post',
|
||||
false,
|
||||
'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`.`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([
|
||||
'2015-07-20',
|
||||
'post',
|
||||
false,
|
||||
'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([
|
||||
'2015-07-20',
|
||||
'post',
|
||||
false,
|
||||
'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`.`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([
|
||||
'photo',
|
||||
'public',
|
||||
'post',
|
||||
false,
|
||||
'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([
|
||||
'photo',
|
||||
'public',
|
||||
'post',
|
||||
false,
|
||||
'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`.`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([
|
||||
'leslie',
|
||||
'public',
|
||||
'post',
|
||||
false,
|
||||
'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([
|
||||
'leslie',
|
||||
'public',
|
||||
'post',
|
||||
false,
|
||||
'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`.`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([
|
||||
'published',
|
||||
'draft',
|
||||
'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([
|
||||
'published',
|
||||
'draft',
|
||||
'published',
|
||||
'post'
|
||||
false
|
||||
]);
|
||||
});
|
||||
});
|
||||
@ -322,7 +322,7 @@ describe('Unit: models/post', function () {
|
||||
should(filter).equal(null);
|
||||
});
|
||||
|
||||
it('returns type:post filter for public context', function () {
|
||||
it('returns page:false 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('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 = {
|
||||
context: 'user'
|
||||
};
|
||||
|
||||
const filter = defaultFilters({}, options);
|
||||
|
||||
filter.should.equal('type:post+status:published');
|
||||
filter.should.equal('page:false+status:published');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -16,7 +16,7 @@ describe('RSS: Generate Feed', function () {
|
||||
posts = _.cloneDeep(testUtils.DataGenerator.forKnex.posts);
|
||||
|
||||
posts = _.filter(posts, function filter(post) {
|
||||
return post.status === 'published' && post.type === 'post';
|
||||
return post.status === 'published' && post.page === false;
|
||||
});
|
||||
|
||||
_.each(posts, function (post) {
|
||||
|
@ -192,7 +192,7 @@ describe('Slack', 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);
|
||||
settingsCacheStub.withArgs('slack').returns(slackObjWithUrl);
|
||||
|
||||
|
@ -74,14 +74,14 @@ DataGenerator.Content = {
|
||||
title: 'This is a static page',
|
||||
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>'),
|
||||
type: 'page'
|
||||
page: true
|
||||
},
|
||||
{
|
||||
id: ObjectId.generate(),
|
||||
title: 'This is a draft static page',
|
||||
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>'),
|
||||
type: 'page',
|
||||
page: true,
|
||||
status: 'draft'
|
||||
},
|
||||
{
|
||||
@ -468,7 +468,7 @@ DataGenerator.forKnex = (function () {
|
||||
status: 'published',
|
||||
feature_image: null,
|
||||
featured: false,
|
||||
type: 'post',
|
||||
page: false,
|
||||
slug: 'slug',
|
||||
author_id: DataGenerator.Content.users[0].id,
|
||||
updated_at: new Date(),
|
||||
|
Loading…
Reference in New Issue
Block a user