javascript - 删除不安全后无法添加食谱并出现错误

标签 javascript meteor meteor-autoform

删除不安全后,我无法添加新配方并收到以下错误消息拒绝访问 [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
    });

架构.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'
            }
        }
    }
}));

最佳答案

从你的 repo 中得到这个工作,主要问题是当你允许插入到 RecipesImages FS 集合时你没有为 Recipes 集合做同样的事情所以当它试图通过简单的模式插入它可以做图像部分但不能做食谱文档的其余部分。

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

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

在未填充 ownerName 字段上弹出的模式也存在验证错误,所以我不得不将其设置为可选,尽管我猜你是否可以使用不安全的方式插入这只是一个错字:

ownerName: {
    type: String,
    optional: true
}

关于javascript - 删除不安全后无法添加食谱并出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35138295/

相关文章:

meteor Yaga 本 :Admin Filtering by Logged in User

javascript - 排队表单提交请求直到服务器返回

javascript - 在 HTML 中显示带有空格的 Javascript 数组

meteor - 如何对 minimongo 进行大量批量插入,而无需在每次插入时重新计算依赖查询

Meteor.call() 方法 - Meteor.js

javascript - 根据 meteor 中的选定值从集合中填充选择字段并进行过滤

javascript - 在 NodeJS 中实现阻塞控制流

javascript - Touch 上的全屏事件在 Chrome 上不起作用

javascript - 使用 Meteor session 切换模板

javascript - 将参数传递给每个 Meteor 模板实例的辅助函数