【发布时间】:2014-10-04 14:44:14
【问题描述】:
我有一个包含一些拒绝更新规则的用户集合:
// The roles object
Schema.roles = new SimpleSchema({
maker: {
type: Boolean,
denyUpdate: true
},
admin: {
type: Boolean,
denyUpdate: true
}
});
这些数据在用户配置文件中。显然,我不希望随机用户能够修改profile.roles.admin。但是管理员用户应该可以。
它部分工作:用户不能修改这个布尔值。但是应该可以从下面的服务器端代码修改它。
Meteor.users.update({_id: targetID'}, {$set: {'profile.roles.admin': true}});
有没有办法告诉collection2 信任来自服务器的代码?
编辑:答案
感谢下面的回答,这是我现在用于架构的代码:
admin: {
type: Boolean,
autoValue: function() {
// If the code is not from the server (isFromTrustedCode)
// unset the update
if(!this.isFromTrustedCode)
this.unset();
}
}
isFromTrustedCode 布尔值告诉代码是否应该被信任。简单的。顺便说一句,autoValue 选项返回有关更新(或插入、设置或更新)操作的完整对象。以下是参数:
isSet: true
unset: [Function]
value: true
operator: '$set'
field: [Function]
siblingField: [Function]
isInsert: false
isUpdate: true
isUpsert: false
userId: null
isFromTrustedCode: true
因此可以对写作权限规则进行真正细粒度的管理。
【问题讨论】:
标签: collections meteor meteor-collection2