【发布时间】:2015-03-03 00:27:00
【问题描述】:
我很好奇我是否在这个集合上正确设置了允许语句。我正在使用aldeed:autoform 和aldeed:collection2。
下面是来自玩具项目的 issue-collection.js 的快照。
这是设置允许检查的正确方法吗?这些是否在客户端(对于 minimongo)和服务器上运行?具体来说,在大多数update 调用中,return !!userId && (doc.userId == userId); 是否足以确保用户已登录并且已登录的用户是文档的所有者?
澄清和实际问题:allow 和deny 方法是否在BOTH 服务器和客户端上运行?还是它们只在客户端上运行?
问题 = new Mongo.Collection("问题");
if (Meteor.isClient){
Meteor.subscribe("issues");
}
if(Meteor.isServer){
Meteor.publish('issues', function () {
return Issues.find({}, {limit: ServerSettings.maxSubscribe});
});
}
Issues.attachSchema(new SimpleSchema({
issue: {
type: String,
label: "Describe the issue you noticed",
max:256
}
}));
//SECURITY - Allow Callbacks for posting
Issues.allow({
insert: function(userId, doc) {
/* Throw in some defaults. */
doc.userId = userId;
doc.sumbitDate = new Date();
doc.date = new Date();
// only allow posting if you are logged in
return !! userId;
},
update: function(userId, doc) {
// only allow updating if you are logged in
return !!userId && (doc.userId == userId);
},
remove: function(userID, doc) {
//only allow deleting if you are owner
return doc.submittedById === Meteor.userId();
}
});
【问题讨论】:
标签: meteor