mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Replaced i18n.t w/ tpl helper in core/server/api/canary/* (#13521)
refs: #13380 - The i18n package is deprecated. It is being replaced with the tpl package.
This commit is contained in:
parent
311414ad48
commit
3bb7813613
10 changed files with 64 additions and 25 deletions
core/server/api/canary
|
@ -1,8 +1,12 @@
|
|||
const models = require('../../models');
|
||||
const i18n = require('../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const errors = require('@tryghost/errors');
|
||||
const allowedIncludes = ['tags', 'authors'];
|
||||
|
||||
const messages = {
|
||||
postNotFound: 'Post not found.'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
docName: 'posts',
|
||||
|
||||
|
@ -63,7 +67,7 @@ module.exports = {
|
|||
.then((model) => {
|
||||
if (!model) {
|
||||
throw new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.posts.postNotFound')
|
||||
message: tpl(messages.postNotFound)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,14 @@
|
|||
const errors = require('@tryghost/errors');
|
||||
const membersService = require('../../services/members');
|
||||
|
||||
const i18n = require('../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
|
||||
const allowedIncludes = ['stripe_prices', 'monthly_price', 'yearly_price', 'benefits'];
|
||||
|
||||
const messages = {
|
||||
productNotFound: 'Product not found.'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
docName: 'products',
|
||||
|
||||
|
@ -56,7 +60,7 @@ module.exports = {
|
|||
|
||||
if (!model) {
|
||||
throw new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.products.productNotFound')
|
||||
message: tpl(messages.productNotFound)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
const Promise = require('bluebird');
|
||||
const i18n = require('../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const errors = require('@tryghost/errors');
|
||||
const models = require('../../models');
|
||||
|
||||
const ALLOWED_INCLUDES = ['count.posts'];
|
||||
|
||||
const messages = {
|
||||
tagNotFound: 'Tag not found.'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
docName: 'tags',
|
||||
|
||||
|
@ -56,7 +60,7 @@ module.exports = {
|
|||
.then((model) => {
|
||||
if (!model) {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.tags.tagNotFound')
|
||||
message: tpl(messages.tagNotFound)
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const Promise = require('bluebird');
|
||||
const i18n = require('../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const errors = require('@tryghost/errors');
|
||||
const models = require('../../models');
|
||||
const permissionsService = require('../../services/permissions');
|
||||
|
@ -12,11 +12,16 @@ const userService = new UsersService({dbBackup, models, auth, apiMail, apiSettin
|
|||
const ALLOWED_INCLUDES = ['count.posts', 'permissions', 'roles', 'roles.permissions'];
|
||||
const UNSAFE_ATTRS = ['status', 'roles'];
|
||||
|
||||
const messages = {
|
||||
noPermissionToAction: 'You do not have permission to perform this action',
|
||||
userNotFound: 'User not found.'
|
||||
};
|
||||
|
||||
function permissionOnlySelf(frame) {
|
||||
const targetId = getTargetId(frame);
|
||||
const userId = frame.user.id;
|
||||
if (targetId !== userId) {
|
||||
return Promise.reject(new errors.NoPermissionError({message: i18n.t('errors.permissions.noPermissionToAction')}));
|
||||
return Promise.reject(new errors.NoPermissionError({message: tpl(messages.noPermissionToAction)}));
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
@ -88,7 +93,7 @@ module.exports = {
|
|||
.then((model) => {
|
||||
if (!model) {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.users.userNotFound')
|
||||
message: tpl(messages.userNotFound)
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -121,7 +126,7 @@ module.exports = {
|
|||
.then((model) => {
|
||||
if (!model) {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.users.userNotFound')
|
||||
message: tpl(messages.userNotFound)
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
const Promise = require('bluebird');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const errors = require('@tryghost/errors');
|
||||
const messages = {noUrlProvided: 'No url provided.'};
|
||||
|
||||
const messages = {
|
||||
noUrlProvided: 'No url provided.'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
read(apiConfig, frame) {
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
const Promise = require('bluebird');
|
||||
const validator = require('@tryghost/validator');
|
||||
const debug = require('@tryghost/debug')('api:canary:utils:validators:input:passwordreset');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const errors = require('@tryghost/errors');
|
||||
|
||||
const messages = {
|
||||
newPasswordsDoNotMatch: 'Your new passwords do not match',
|
||||
invalidEmailReceived: 'The server did not receive a valid email'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
resetPassword(apiConfig, frame) {
|
||||
debug('resetPassword');
|
||||
|
@ -12,7 +17,7 @@ module.exports = {
|
|||
|
||||
if (data.newPassword !== data.ne2Password) {
|
||||
return Promise.reject(new errors.ValidationError({
|
||||
message: i18n.t('errors.models.user.newPasswordsDoNotMatch')
|
||||
message: tpl(messages.newPasswordsDoNotMatch)
|
||||
}));
|
||||
}
|
||||
},
|
||||
|
@ -24,7 +29,7 @@ module.exports = {
|
|||
|
||||
if (typeof email !== 'string' || !validator.isEmail(email)) {
|
||||
throw new errors.BadRequestError({
|
||||
message: i18n.t('errors.api.authentication.invalidEmailReceived')
|
||||
message: tpl(messages.invalidEmailReceived)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
const Promise = require('bluebird');
|
||||
const _ = require('lodash');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const {NotFoundError, ValidationError, BadRequestError} = require('@tryghost/errors');
|
||||
const validator = require('@tryghost/validator');
|
||||
|
||||
const messages = {
|
||||
invalidEmailReceived: 'Please send a valid email',
|
||||
invalidEmailTypeReceived: 'Invalid email type received'
|
||||
invalidEmailTypeReceived: 'Invalid email type received',
|
||||
problemFindingSetting: 'Problem finding setting: {key}'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
@ -14,7 +15,7 @@ module.exports = {
|
|||
// @NOTE: was removed https://github.com/TryGhost/Ghost/issues/10373
|
||||
if (frame.options.key === 'ghost_head' || frame.options.key === 'ghost_foot') {
|
||||
return Promise.reject(new NotFoundError({
|
||||
message: i18n.t('errors.api.settings.problemFindingSetting', {
|
||||
message: tpl(messages.problemFindingSetting, {
|
||||
key: frame.options.key
|
||||
})
|
||||
}));
|
||||
|
@ -28,7 +29,7 @@ module.exports = {
|
|||
if (setting.key === 'ghost_head' || setting.key === 'ghost_foot') {
|
||||
// @NOTE: was removed https://github.com/TryGhost/Ghost/issues/10373
|
||||
errors.push(new NotFoundError({
|
||||
message: i18n.t('errors.api.settings.problemFindingSetting', {
|
||||
message: tpl(messages.problemFindingSetting, {
|
||||
key: setting.key
|
||||
})
|
||||
}));
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
const debug = require('@tryghost/debug')('api:canary:utils:validators:input:updateSetup');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const errors = require('@tryghost/errors');
|
||||
|
||||
const messages = {
|
||||
notTheBlogOwner: 'You are not the site owner.'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
updateSetup(apiConfig, frame) {
|
||||
debug('resetPassword');
|
||||
|
||||
if (!frame.options.context || !frame.options.context.user) {
|
||||
throw new errors.NoPermissionError({message: i18n.t('errors.api.authentication.notTheBlogOwner')});
|
||||
throw new errors.NoPermissionError({message: tpl(messages.notTheBlogOwner)});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
const Promise = require('bluebird');
|
||||
const debug = require('@tryghost/debug')('api:canary:utils:validators:input:users');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const errors = require('@tryghost/errors');
|
||||
|
||||
const messages = {
|
||||
newPasswordsDoNotMatch: 'Your new passwords do not match'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
changePassword(apiConfig, frame) {
|
||||
debug('changePassword');
|
||||
|
@ -11,7 +15,7 @@ module.exports = {
|
|||
|
||||
if (data.newPassword !== data.ne2Password) {
|
||||
return Promise.reject(new errors.ValidationError({
|
||||
message: i18n.t('errors.models.user.newPasswordsDoNotMatch')
|
||||
message: tpl(messages.newPasswordsDoNotMatch)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
const _ = require('lodash');
|
||||
const errors = require('@tryghost/errors');
|
||||
const i18n = require('../../../../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const jsonSchema = require('../utils/json-schema');
|
||||
|
||||
const messages = {
|
||||
schemaValidationFailed: 'Validation failed for \'{key}\'.',
|
||||
noIntegrationIdProvidedContext: 'You may only create webhooks with \'integration_id\' when using session authentication.'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
add(apiConfig, frame) {
|
||||
if (!_.get(frame, 'options.context.integration.id') && !_.get(frame.data, 'webhooks[0].integration_id')) {
|
||||
return Promise.reject(new errors.ValidationError({
|
||||
message: i18n.t('notices.data.validation.index.schemaValidationFailed', {
|
||||
message: tpl(messages.schemaValidationFailed, {
|
||||
key: 'integration_id'
|
||||
}),
|
||||
context: i18n.t('errors.api.webhooks.noIntegrationIdProvided.context'),
|
||||
context: tpl(messages.noIntegrationIdProvidedContext),
|
||||
property: 'integration_id'
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue