mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-01 02:41:39 -05:00
Updated visibility validator for page/posts
refs https://github.com/TryGhost/Team/issues/849 Custom post visibility (behind alpha flag) is added to the API using new `visibility_filter` attribute that stores the custom filter. This change - - updates validator for visibility to check new `visibility_filter` property - cleans usage of i18n in favor of tpl
This commit is contained in:
parent
6988dadb1e
commit
d413b3d654
6 changed files with 54 additions and 24 deletions
|
@ -1,7 +1,11 @@
|
|||
const jsonSchema = require('../utils/json-schema');
|
||||
const models = require('../../../../../models');
|
||||
const {ValidationError} = require('@tryghost/errors');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
|
||||
const messages = {
|
||||
invalidVisibilityFilter: 'Invalid filter in visibility_filter property'
|
||||
};
|
||||
|
||||
const validateVisibility = async function (frame) {
|
||||
if (!frame.data.pages || !frame.data.pages[0]) {
|
||||
|
@ -10,16 +14,17 @@ const validateVisibility = async function (frame) {
|
|||
|
||||
// validate visibility - not done at schema level because this can be an NQL query so needs model access
|
||||
const visibility = frame.data.pages[0].visibility;
|
||||
const visibilityFilter = frame.data.pages[0].visibility_filter;
|
||||
if (visibility) {
|
||||
if (!['public', 'members', 'paid'].includes(visibility)) {
|
||||
// check filter is valid
|
||||
try {
|
||||
await models.Member.findPage({filter: visibility, limit: 1});
|
||||
await models.Member.findPage({filter: visibilityFilter, limit: 1});
|
||||
return Promise.resolve();
|
||||
} catch (err) {
|
||||
return Promise.reject(new ValidationError({
|
||||
message: i18n.t('errors.api.pages.invalidVisibilityFilter'),
|
||||
property: 'visibility'
|
||||
message: tpl(messages.invalidVisibilityFilter),
|
||||
property: 'visibility_filter'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
const jsonSchema = require('../utils/json-schema');
|
||||
const models = require('../../../../../models');
|
||||
const {ValidationError} = require('@tryghost/errors');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
|
||||
const messages = {
|
||||
invalidVisibilityFilter: 'Invalid filter in visibility_filter property'
|
||||
};
|
||||
|
||||
const validateVisibility = async function (frame) {
|
||||
if (!frame.data.posts || !frame.data.posts[0]) {
|
||||
|
@ -10,16 +14,17 @@ const validateVisibility = async function (frame) {
|
|||
|
||||
// validate visibility - not done at schema level because this can be an NQL query so needs model access
|
||||
const visibility = frame.data.posts[0].visibility;
|
||||
const visibilityFilter = frame.data.posts[0].visibility_filter;
|
||||
if (visibility) {
|
||||
if (!['public', 'members', 'paid'].includes(visibility)) {
|
||||
// check filter is valid
|
||||
try {
|
||||
await models.Member.findPage({filter: visibility, limit: 1});
|
||||
await models.Member.findPage({filter: visibilityFilter, limit: 1});
|
||||
return Promise.resolve();
|
||||
} catch (err) {
|
||||
return Promise.reject(new ValidationError({
|
||||
message: i18n.t('errors.api.posts.invalidVisibilityFilter'),
|
||||
property: 'visibility'
|
||||
message: tpl(messages.invalidVisibilityFilter),
|
||||
property: 'visibility_filter'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
const jsonSchema = require('../utils/json-schema');
|
||||
const models = require('../../../../../models');
|
||||
const {ValidationError} = require('@tryghost/errors');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
|
||||
const messages = {
|
||||
invalidVisibilityFilter: 'Invalid filter in visibility_filter property'
|
||||
};
|
||||
|
||||
const validateVisibility = async function (frame) {
|
||||
if (!frame.data.pages || !frame.data.pages[0]) {
|
||||
|
@ -10,16 +14,17 @@ const validateVisibility = async function (frame) {
|
|||
|
||||
// validate visibility - not done at schema level because this can be an NQL query so needs model access
|
||||
const visibility = frame.data.pages[0].visibility;
|
||||
const visibilityFilter = frame.data.pages[0].visibility_filter;
|
||||
if (visibility) {
|
||||
if (!['public', 'members', 'paid'].includes(visibility)) {
|
||||
// check filter is valid
|
||||
try {
|
||||
await models.Member.findPage({filter: visibility, limit: 1});
|
||||
await models.Member.findPage({filter: visibilityFilter, limit: 1});
|
||||
return Promise.resolve();
|
||||
} catch (err) {
|
||||
return Promise.reject(new ValidationError({
|
||||
message: i18n.t('errors.api.pages.invalidVisibilityFilter'),
|
||||
property: 'visibility'
|
||||
message: tpl(messages.invalidVisibilityFilter),
|
||||
property: 'visibility_filter'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
const jsonSchema = require('../utils/json-schema');
|
||||
const models = require('../../../../../models');
|
||||
const {ValidationError} = require('@tryghost/errors');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
|
||||
const messages = {
|
||||
invalidVisibilityFilter: 'Invalid filter in visibility_filter property'
|
||||
};
|
||||
|
||||
const validateVisibility = async function (frame) {
|
||||
if (!frame.data.posts || !frame.data.posts[0]) {
|
||||
|
@ -10,16 +14,17 @@ const validateVisibility = async function (frame) {
|
|||
|
||||
// validate visibility - not done at schema level because this can be an NQL query so needs model access
|
||||
const visibility = frame.data.posts[0].visibility;
|
||||
const visibilityFilter = frame.data.posts[0].visibility_filter;
|
||||
if (visibility) {
|
||||
if (!['public', 'members', 'paid'].includes(visibility)) {
|
||||
// check filter is valid
|
||||
try {
|
||||
await models.Member.findPage({filter: visibility, limit: 1});
|
||||
await models.Member.findPage({filter: visibilityFilter, limit: 1});
|
||||
return Promise.resolve();
|
||||
} catch (err) {
|
||||
return Promise.reject(new ValidationError({
|
||||
message: i18n.t('errors.api.posts.invalidVisibilityFilter'),
|
||||
property: 'visibility'
|
||||
message: tpl(messages.invalidVisibilityFilter),
|
||||
property: 'visibility_filter'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
const jsonSchema = require('../utils/json-schema');
|
||||
const models = require('../../../../../models');
|
||||
const {ValidationError} = require('@tryghost/errors');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
|
||||
const messages = {
|
||||
invalidVisibilityFilter: 'Invalid filter in visibility_filter property'
|
||||
};
|
||||
|
||||
const validateVisibility = async function (frame) {
|
||||
if (!frame.data.pages || !frame.data.pages[0]) {
|
||||
|
@ -10,16 +14,17 @@ const validateVisibility = async function (frame) {
|
|||
|
||||
// validate visibility - not done at schema level because this can be an NQL query so needs model access
|
||||
const visibility = frame.data.pages[0].visibility;
|
||||
const visibilityFilter = frame.data.pages[0].visibility_filter;
|
||||
if (visibility) {
|
||||
if (!['public', 'members', 'paid'].includes(visibility)) {
|
||||
// check filter is valid
|
||||
try {
|
||||
await models.Member.findPage({filter: visibility, limit: 1});
|
||||
await models.Member.findPage({filter: visibilityFilter, limit: 1});
|
||||
return Promise.resolve();
|
||||
} catch (err) {
|
||||
return Promise.reject(new ValidationError({
|
||||
message: i18n.t('errors.api.pages.invalidVisibilityFilter'),
|
||||
property: 'visibility'
|
||||
message: tpl(messages.invalidVisibilityFilter),
|
||||
property: 'visibility_filter'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
const jsonSchema = require('../utils/json-schema');
|
||||
const models = require('../../../../../models');
|
||||
const {ValidationError} = require('@tryghost/errors');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
|
||||
const messages = {
|
||||
invalidVisibilityFilter: 'Invalid filter in visibility_filter property'
|
||||
};
|
||||
|
||||
const validateVisibility = async function (frame) {
|
||||
if (!frame.data.posts || !frame.data.posts[0]) {
|
||||
|
@ -10,16 +14,17 @@ const validateVisibility = async function (frame) {
|
|||
|
||||
// validate visibility - not done at schema level because this can be an NQL query so needs model access
|
||||
const visibility = frame.data.posts[0].visibility;
|
||||
const visibilityFilter = frame.data.posts[0].visibility_filter;
|
||||
if (visibility) {
|
||||
if (!['public', 'members', 'paid'].includes(visibility)) {
|
||||
// check filter is valid
|
||||
try {
|
||||
await models.Member.findPage({filter: visibility, limit: 1});
|
||||
await models.Member.findPage({filter: visibilityFilter, limit: 1});
|
||||
return Promise.resolve();
|
||||
} catch (err) {
|
||||
return Promise.reject(new ValidationError({
|
||||
message: i18n.t('errors.api.posts.invalidVisibilityFilter'),
|
||||
property: 'visibility'
|
||||
message: tpl(messages.invalidVisibilityFilter),
|
||||
property: 'visibility_filter'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue