如何允许不同的更新 - Meteor collection.allow [英] How to allow different updates - Meteor collection.allow

查看:139
本文介绍了如何允许不同的更新 - Meteor collection.allow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许用户以多种方式更新集合。

I want to allow users to update a collection in more than one way.

允许用户更新并进行不同检查的最佳方法是什么?

What is the best way to allow users to update and have different checks?

像这样:

Articles.allow({
  update: function (userId, doc, fields, modifier) {
    if (modifier.$push.savedBy === Meteor.userId()) {
      console.log('User is saving an article.');
      return true;
    }
    if (Meteor.userId() && Math.abs(modifier.$inc.score) === 1) {
      console.log('User ALLOWED to vote on the article' + doc.title);
      return true;
    } else {
      console.log('User DISALLOWED from updating the article' + doc.title);
      return false;
    }
  }
});

除了编写方法之外还有其他方法吗?

Is there another way other than writing methods?

推荐答案

我不确定如果我回答你的问题,但你可以让多个允许 deny 回调同一集合:

I'm uncertain if I'm answering your question, but you can make multiple allow and deny callbacks for the same collection:

Articles.allow({
  update: function(userId, doc, fields, modifier) {
    return (modifier.$push != null) && modifier.$push.savedBy === userId;
  }
});

Articles.allow({
  update: function(userId, doc, fields, modifier) {
    return (userId != null) && (modifier.$inc != null) && (Math.abs(modifier.$inc.score) === 1);
  }
});

逻辑的工作原理如下:如果 c>允许拒绝中的回呼返回 true none c> callbacks return true ,则操作将成功。

The logic works as follows: If any of the allow callbacks return true, and none of the deny callbacks return true, then the operation will succeed.

这篇关于如何允许不同的更新 - Meteor collection.allow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆