make comment's postId uneditable in schema (fix #1231)

This commit is contained in:
Sacha Greif 2016-02-06 11:09:10 +09:00
parent bb23d9b8b2
commit baa38bfa40
2 changed files with 9 additions and 4 deletions

View file

@ -143,7 +143,7 @@ Comments.schema = new SimpleSchema({
optional: true,
// regEx: SimpleSchema.RegEx.Id,
max: 500,
editableBy: ["member", "admin"], // TODO: should users be able to set postId, but not modify it?
// editableBy: ["member", "admin"], // TODO: should users be able to set postId, but not modify it?
autoform: {
omit: true // never show this
}

View file

@ -111,9 +111,14 @@ Meteor.methods({
// clear restricted properties
_.keys(comment).forEach(function (fieldName) {
var field = schema[fieldName];
if (!Users.can.submitField(user, field)) {
throw new Meteor.Error("disallowed_property", i18n.t('disallowed_property_detected') + ": " + fieldName);
// make an exception for postId, which should be setable but not modifiable
if (fieldName === "postId") {
// ok
} else {
var field = schema[fieldName];
if (!Users.can.submitField(user, field)) {
throw new Meteor.Error("disallowed_property", i18n.t('disallowed_property_detected') + ": " + fieldName);
}
}
});