mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Skiped 'all' validations for posts/tags endpoints
refs #10438 - Skipped validations that are now handled on JSON Schema level and would make sure error messages are consistent for these endpoints
This commit is contained in:
parent
40f359a238
commit
e305d5e9cb
4 changed files with 22 additions and 15 deletions
|
@ -118,10 +118,14 @@ module.exports = {
|
|||
add(apiConfig, frame) {
|
||||
debug('validate add');
|
||||
|
||||
if (_.isEmpty(frame.data) || _.isEmpty(frame.data[apiConfig.docName]) || _.isEmpty(frame.data[apiConfig.docName][0])) {
|
||||
return Promise.reject(new common.errors.BadRequestError({
|
||||
message: common.i18n.t('errors.api.utils.noRootKeyProvided', {docName: apiConfig.docName})
|
||||
}));
|
||||
// NOTE: this block should be removed completely once JSON Schema validations
|
||||
// are introduced for all of the endpoints
|
||||
if (!['posts', 'tags'].includes(apiConfig.docName)) {
|
||||
if (_.isEmpty(frame.data) || _.isEmpty(frame.data[apiConfig.docName]) || _.isEmpty(frame.data[apiConfig.docName][0])) {
|
||||
return Promise.reject(new common.errors.BadRequestError({
|
||||
message: common.i18n.t('errors.api.utils.noRootKeyProvided', {docName: apiConfig.docName})
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
const jsonpath = require('jsonpath');
|
||||
|
@ -166,11 +170,17 @@ module.exports = {
|
|||
return result;
|
||||
}
|
||||
|
||||
if (frame.options.id && frame.data[apiConfig.docName][0].id
|
||||
&& frame.options.id !== frame.data[apiConfig.docName][0].id) {
|
||||
return Promise.reject(new common.errors.BadRequestError({
|
||||
message: common.i18n.t('errors.api.utils.invalidIdProvided')
|
||||
}));
|
||||
// NOTE: this block should be removed completely once JSON Schema validations
|
||||
// are introduced for all of the endpoints. `id` property is currently
|
||||
// stripped from the request body and only the one provided in `options`
|
||||
// is used in later logic
|
||||
if (!['posts', 'tags'].includes(apiConfig.docName)) {
|
||||
if (frame.options.id && frame.data[apiConfig.docName][0].id
|
||||
&& frame.options.id !== frame.data[apiConfig.docName][0].id) {
|
||||
return Promise.reject(new common.errors.BadRequestError({
|
||||
message: common.i18n.t('errors.api.utils.invalidIdProvided')
|
||||
}));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -77,11 +77,6 @@ module.exports = {
|
|||
include: {
|
||||
values: ALLOWED_INCLUDES
|
||||
}
|
||||
},
|
||||
data: {
|
||||
name: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
},
|
||||
permissions: true,
|
||||
|
|
|
@ -20,6 +20,8 @@ const validate = (schema, definitions, data) => {
|
|||
|
||||
if (dataPath) {
|
||||
key = dataPath.split('.').pop();
|
||||
} else {
|
||||
key = schema.$id.split('.')[0];
|
||||
}
|
||||
|
||||
return Promise.reject(new common.errors.ValidationError({
|
||||
|
|
|
@ -379,7 +379,7 @@ describe('Unit: api/shared/validators/input/all', function () {
|
|||
describe('edit', function () {
|
||||
it('id mismatch', function () {
|
||||
const apiConfig = {
|
||||
docName: 'posts'
|
||||
docName: 'users'
|
||||
};
|
||||
|
||||
const frame = {
|
||||
|
|
Loading…
Add table
Reference in a new issue