mirror of
https://github.com/vale981/Vulcan
synced 2025-03-08 19:11:38 -05:00
Validate post's categories on server.
This commit is contained in:
parent
fc01ed887e
commit
a4e5908d2d
2 changed files with 39 additions and 12 deletions
24
packages/telescope-tags/lib/server/hooks.js
Normal file
24
packages/telescope-tags/lib/server/hooks.js
Normal 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;
|
||||||
|
});
|
|
@ -3,8 +3,8 @@ Package.describe({summary: "Telescope tags package"});
|
||||||
Package.onUse(function (api) {
|
Package.onUse(function (api) {
|
||||||
|
|
||||||
api.use([
|
api.use([
|
||||||
'telescope-lib',
|
'telescope-lib',
|
||||||
'telescope-base',
|
'telescope-base',
|
||||||
'aldeed:simple-schema',
|
'aldeed:simple-schema',
|
||||||
'aldeed:autoform',
|
'aldeed:autoform',
|
||||||
'tap:i18n',
|
'tap:i18n',
|
||||||
|
@ -19,14 +19,14 @@ Package.onUse(function (api) {
|
||||||
'templating'
|
'templating'
|
||||||
], 'client');
|
], 'client');
|
||||||
|
|
||||||
api.add_files([
|
api.addFiles([
|
||||||
'lib/categories.js',
|
'lib/categories.js',
|
||||||
'lib/custom_fields.js',
|
'lib/custom_fields.js',
|
||||||
'lib/hooks.js',
|
'lib/hooks.js',
|
||||||
'package-tap.i18n'
|
'package-tap.i18n'
|
||||||
], ['client', 'server']);
|
], ['client', 'server']);
|
||||||
|
|
||||||
api.add_files([
|
api.addFiles([
|
||||||
'lib/client/routes.js',
|
'lib/client/routes.js',
|
||||||
'lib/client/scss/categories.scss',
|
'lib/client/scss/categories.scss',
|
||||||
'lib/client/templates/categories.html',
|
'lib/client/templates/categories.html',
|
||||||
|
@ -41,9 +41,12 @@ Package.onUse(function (api) {
|
||||||
'lib/client/templates/post_categories.js'
|
'lib/client/templates/post_categories.js'
|
||||||
], ['client']);
|
], ['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/bg.i18n.json",
|
||||||
"i18n/de.i18n.json",
|
"i18n/de.i18n.json",
|
||||||
"i18n/en.i18n.json",
|
"i18n/en.i18n.json",
|
||||||
|
@ -52,13 +55,13 @@ Package.onUse(function (api) {
|
||||||
"i18n/it.i18n.json",
|
"i18n/it.i18n.json",
|
||||||
"i18n/zh-CN.i18n.json",
|
"i18n/zh-CN.i18n.json",
|
||||||
], ["client", "server"]);
|
], ["client", "server"]);
|
||||||
|
|
||||||
api.export([
|
api.export([
|
||||||
'preloadSubscriptions',
|
'preloadSubscriptions',
|
||||||
'adminMenu',
|
'adminMenu',
|
||||||
'Categories',
|
'Categories',
|
||||||
'addToPostSchema',
|
'addToPostSchema',
|
||||||
'primaryNav',
|
'primaryNav',
|
||||||
'postModules',
|
'postModules',
|
||||||
'getPostCategories'
|
'getPostCategories'
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue