2016-11-14 20:27:23 +01:00
|
|
|
import marked from 'marked';
|
2016-11-14 17:17:44 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
|
|
|
import Users from 'meteor/nova:users';
|
2016-12-13 11:40:24 +09:00
|
|
|
import { addCallback, Utils } from 'meteor/nova:core';
|
2016-11-14 17:17:44 +09:00
|
|
|
|
|
|
|
// ------------------------------------- comments.edit.validate -------------------------------- //
|
|
|
|
|
|
|
|
function CommentsEditSubmittedPropertiesCheck (modifier, comment, user) {
|
|
|
|
const schema = Posts.simpleSchema()._schema;
|
|
|
|
// go over each field and throw an error if it's not editable
|
|
|
|
// loop over each operation ($set, $unset, etc.)
|
|
|
|
_.each(modifier, function (operation) {
|
|
|
|
// loop over each property being operated on
|
|
|
|
_.keys(operation).forEach(function (fieldName) {
|
|
|
|
|
|
|
|
var field = schema[fieldName];
|
|
|
|
if (!Users.canEditField(user, field, comment)) {
|
|
|
|
throw new Meteor.Error("disallowed_property", 'disallowed_property_detected' + ": " + fieldName);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return modifier;
|
|
|
|
}
|
2016-12-13 11:40:24 +09:00
|
|
|
addCallback("comments.edit.validate", CommentsEditSubmittedPropertiesCheck);
|
2016-11-14 17:17:44 +09:00
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------- comments.edit.sync -------------------------------- //
|
|
|
|
|
|
|
|
function CommentsEditGenerateHTMLBody (modifier, comment, user) {
|
|
|
|
// if body is being modified, update htmlBody too
|
|
|
|
if (modifier.$set && modifier.$set.body) {
|
2016-12-12 11:34:28 +09:00
|
|
|
modifier.$set.htmlBody = Utils.sanitize(marked(modifier.$set.body));
|
2016-11-14 17:17:44 +09:00
|
|
|
}
|
|
|
|
return modifier;
|
|
|
|
}
|
2016-12-13 11:40:24 +09:00
|
|
|
addCallback("comments.edit.sync", CommentsEditGenerateHTMLBody);
|