【问题标题】:Meteor JS - allow/deny rulesMeteor JS - 允许/拒绝规则
【发布时间】:2013-01-27 13:38:05
【问题描述】:

在示例应用“派对”中,有一组用于收集派对的允许/拒绝规则。 insert 的规则如下所示:

Parties.allow({
  insert: function (userId, party) {
    return false; // no cowboy inserts -- use createParty method
  },...

同时方法 createParty 实现了 Party.insert({....}),它在某种程度上不受应用于 Party 集合的规则的影响。

.....
return Parties.insert({
      owner: this.userId,
      x: options.x,
      y: options.y,
      title: options.title,
      description: options.description,
      public: !! options.public,
      invited: [],
      rsvps: []
    });
.....

有人能解释一下为什么 createParty 方法不受规则影响吗?

谢谢。

【问题讨论】:

    标签: meteor


    【解决方案1】:

    createPartyMeteor.methods 中,通过从客户端调用Meteor.call('createParties') 在服务器和客户端上运行。在客户端它不会插入任何数据,但在服务器上运行的方法会插入该方。

    Meteors allowdeny 规则直接控制来自客户端的内容,不申请任何运行在服务器端的内容。

    【讨论】:

    • 快速尝试证明关于 Meteor.methods 的 Akshat 声明仅在服务器上运行。好像是真的:
    • 并非总是如此。如果客户端可以使用某个方法(例如,未包含在 Meteor.isServer 中),则客户端和服务器都将执行该方法调用。您只需在 createParty 方法的顶部添加 console.log 即可看到这一点。
    • 更新了答案以包含它,我不知道它也在客户端上运行,然后我意识到我总是将它们放在 Meteor.isServer 块中
    • 进一步说明:Meteor 只需要一个allow 就可以说是。如果你有多个allows,并不是所有的都会生效。如果要确保拒绝恶意插入,请改用deny。另外如果你使用deny,你必须至少有一个allow(即使是return true;
    猜你喜欢
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 2014-09-03
    相关资源
    最近更新 更多