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