javascript - Meteor.users.allow 永远不会触发,但 Meteor.users.deny 有效

标签 javascript meteor

我有一个删除了自动发布的 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/

相关文章:

Meteor 中的 MongoDB 缺少 $max 运算符

javascript - 如何删除 ReactMeteorData 中的警告消息?

javascript - 从 Meteor 中的对象数组中插入文档到集合中

security - Meteor 帐户自动登录模式?

javascript - 调用 navigator.clipboard.readText() 时出现 DOMException

javascript - 使用变量更改样式

javascript - 如何使用 Polymer 打开另一个面板时关闭一个面板

javascript - CrossUI如何重用已经创建的对话框?

javascript - js中如何等待http调用结束?

javascript - jQuery .val ('' ) 不清除文本区域输入