4

我正在尝试将“评级”属性添加到集合中,并希望使任何用户(不仅仅是所有者)能够向集合中的评级集添加评级。我的问题是我设置了允许/拒绝规则,以便只有所有者才能对他们拥有的集合执行更新。有没有办法允许任何用户仅在更新特定属性(“评级”集)时才更新集合,如果他们试图更新任何其他属性,则拒绝他们更新访问。

我在服务器上的允许/拒绝规则如下...

Playlists.allow({
  insert: function(userId, doc) {
    return (userId && doc.owner === userId);
  },
  update: function (userId, docs, fields, modifier) {
    return _.all(docs, function(doc) {
      return doc.owner === userId;
    });
  },
  remove: function (userId, docs) {
    return _.all(docs, function(doc) {
      return doc.owner === userId;
    });
  }
});

Playlists.deny({
  update: function (userId, docs, fields, modifier) {
    return _.contains(fields, 'owner');
  },
  remove: function (userId, docs) {
    return _.any(docs, function (doc) {
      return doc.locked;
    });
  },
  fetch: ['locked']
});
4

2 回答 2

3

Playlists.deny.update中,您可以更改逻辑,使其首先检查是否有人试图修改评级属性(例如,使用$addToSet),return false如果是的话。所以你最终会得到这样的代码:

 Playlists.deny({
    update: function(userId, docs, fields, modifier) {
      if (fields.ratings && modifier["$addToSet"] && modifier["$addToSet"].ratings) {
        return false; // don't deny this
      }
      else {
        return _.contains(fields, 'owner');
      }
    }
  });
于 2013-03-18T10:00:09.997 回答
-2

创建一个 Meteor.methods({updateRatePlaylist:myUpdateRatePlaylistFunction})

于 2013-03-18T10:02:57.503 回答