【问题标题】:After removing insecure unable to add recipes and getting error删除不安全后无法添加食谱并出现错误
【发布时间】:2016-02-02 05:52:03
【问题描述】:

删除不安全后,我无法添加新配方并收到以下错误消息 访问被拒绝 [403] cfs_base-package.js:108 但是,如果我再次添加不安全的消息,我可以再次添加食谱。你能帮我解决这个问题吗 完整源码Github

collections.js

Recipes = new Mongo.Collection('recipes');
Reviews = new Mongo.Collection('reviews');
RecipesImages = new FS.Collection("recipesImages", {
    stores: [new FS.Store.GridFS("recipesImages")]
});

server/permissions.js

   RecipesImages.allow({
        insert: function(userId, doc) {
            return true;
        },
        update: function(userId, doc, fieldNames, modifier) {
            return true;
        },
        remove: function(userId, doc) {
            return false;
        },
        download: function(userId,doc) {
            return true;
        },
        fetch: null
    });

schemas.js

Recipes.attachSchema(new SimpleSchema({
    ownerId: {
        type: String
    },
    ownerName: {
        type: String

    },
    voters:{
        type:Array,
        optional:true
    },
    'voters.$':{
        type:String
    },
    name: {
        type: String,
        label: "Recipe Name",
        max: 100
    },

    ingredients: {
        type: [Object],
        minCount: 1
    },

    "ingredients.$.name":{
        type: String
    },
    "ingredients.$.amount": {
        type: String
    },
    description: {
        type: String,
        label: "How to prepare ",
    },
    time: {
        type: Number,
        label: "Time (Minutes)",
        min:0
    },
    likes:{
        type:Number,
        optional:true
    },
    image: {
        type: String,
        autoform: {
            afFieldInput: {
                type: "cfs-file",
                collection: 'recipesImages',
                label: 'Recipe Picture'
            }
        }
    }
}));

【问题讨论】:

    标签: javascript meteor meteor-autoform


    【解决方案1】:

    从您的存储库中得到了这个工作,主要问题是,当您允许插入到 RecipesImages FS 集合时,您对 Recipes 集合没有做同样的事情,所以当它尝试通过简单模式插入时它可以做图像部分,但不是配方文档的其余部分。

    当然,为了安全起见,您可能希望加强这一点,但以下应该可以工作:

        Recipes.allow({
          insert: function(userId, doc) {
              return true;
          }
        });
    

    在没有填充 ownerName 字段时弹出的架构上还有一个验证错误,所以我不得不将其设置为可选,尽管我猜你是否可以插入不安全的内容,这只是一个错字:

    ownerName: {
        type: String,
        optional: true
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-10
      • 2013-02-18
      • 1970-01-01
      相关资源
      最近更新 更多