我有一个删除了自动发布的Meteor应用程序。
在此应用程序中,我希望允许管理员添加任何用户,但其他用户只能更新自己的用户。使用简单的Meteor.users.allow,就不会调用更新函数(我可以告诉),但是如果我使用Meteor.users.deny并反转逻辑,它就可以正常工作。
我的应用程序中只有一个Meteor.users.allow函数。我可以拒绝使用,但是有人可以告诉我我在使用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代码放入服务器中?
在客户端而不是服务器代码中使用允许时,我遇到了同样的问题。