Validate post's categories on server.

This commit is contained in:
Delgermurun 2015-03-21 08:15:01 +08:00
parent fc01ed887e
commit a4e5908d2d
2 changed files with 39 additions and 12 deletions

View file

@ -0,0 +1,24 @@
var checkCategories = function(post) {
if (!post.categories || post.categories.length === 0) {
return;
}
var categoryCount = Categories.find({_id: {$in: post.categories}}).count();
if (post.categories.length !== categoryCount) {
throw new Meteor.Error('invalid_category', i18n.t('invalid_category'));
}
};
postSubmitMethodCallbacks.push(function (post) {
checkCategories(post);
return post;
});
postEditMethodCallbacks.push(function (updateObject) {
var post = updateObject.$set;
checkCategories(post);
return updateObject;
});

View file

@ -3,8 +3,8 @@ Package.describe({summary: "Telescope tags package"});
Package.onUse(function (api) {
api.use([
'telescope-lib',
'telescope-base',
'telescope-lib',
'telescope-base',
'aldeed:simple-schema',
'aldeed:autoform',
'tap:i18n',
@ -19,14 +19,14 @@ Package.onUse(function (api) {
'templating'
], 'client');
api.add_files([
api.addFiles([
'lib/categories.js',
'lib/custom_fields.js',
'lib/hooks.js',
'package-tap.i18n'
], ['client', 'server']);
api.add_files([
api.addFiles([
'lib/client/routes.js',
'lib/client/scss/categories.scss',
'lib/client/templates/categories.html',
@ -41,9 +41,12 @@ Package.onUse(function (api) {
'lib/client/templates/post_categories.js'
], ['client']);
api.add_files(['lib/server/publications.js'], ['server']);
api.addFiles([
'lib/server/publications.js',
'lib/server/hooks.js',
], ['server']);
api.add_files([
api.addFiles([
"i18n/bg.i18n.json",
"i18n/de.i18n.json",
"i18n/en.i18n.json",
@ -52,13 +55,13 @@ Package.onUse(function (api) {
"i18n/it.i18n.json",
"i18n/zh-CN.i18n.json",
], ["client", "server"]);
api.export([
'preloadSubscriptions',
'adminMenu',
'Categories',
'addToPostSchema',
'primaryNav',
'preloadSubscriptions',
'adminMenu',
'Categories',
'addToPostSchema',
'primaryNav',
'postModules',
'getPostCategories'
]);