我有一个删除了自动发布的 Meteor 应用程序。
在此应用中,我希望允许管理员对任何用户进行 crud,但其他用户应该只能更新他们自己的用户。使用简单的 Meteor.users.allow,更新函数永远不会被调用(我可以告诉),但如果我使用 Meteor.users.deny 并反转逻辑,它工作正常。
我的应用程序中只有一个 Meteor.users.allow 函数。我可以忍受使用拒绝,但谁能告诉我我在使用允许时做错了什么?
我的 allow 函数,它从不记录任何内容:
console.log("Setting Meteor.users.allow");
Meteor.users.allow({
insert: function (userId, doc) {
// only admin can insert
var u = Meteor.users.findOne({_id:userId});
return (u && u.isAdmin);
},
update: function (userId, doc, fields, modifier) {
console.log("user "+userId+"wants to modify doc"+doc._id);
if (userId && doc._id === userId) {
console.log("user allowed to modify own account!");
// user can modify own
return true;
}
// admin can modify any
var u = Meteor.users.findOne({_id:userId});
return (u && u.isAdmin);
},
remove: function (userId, doc) {
// only admin can remove
var u = Meteor.users.findOne({_id:userId});
return (u && u.isAdmin);
}
});
我的拒绝功能,它记录并工作:
console.log("Setting Meteor.users.deny");
Meteor.users.deny({
insert: function (userId, doc) {
// only admin can insert
var u = Meteor.users.findOne({_id:userId});
return !(u && u.isAdmin);
},
update: function (userId, doc, fields, modifier) {
console.log("user "+userId+"wants to modify doc"+doc._id);
if (userId && doc._id === userId) {
console.log("user allowed to modify own account!");
// user can modify own
return false;
}
// admin can modify any
var u = Meteor.users.findOne({_id:userId});
return !(u && u.isAdmin);
},
remove: function (userId, doc) {
// only admin can remove
var u = Meteor.users.findOne({_id:userId});
return !(u && u.isAdmin);
}
});
最佳答案
您确定将您的 Meteor.users.allow 代码放入服务器吗?
我在客户端而不是服务器代码中使用允许时遇到了同样的问题。
关于javascript - Meteor.users.allow 永远不会触发,但 Meteor.users.deny 有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18840353/