检查用户是否在流星中扮演角色的正确方法?
Right way to check if user has role in meteor?
我正在构建一个 CMS,根据用户 role
,他们将能够 edit/update/delete/create 不同的区域,但由他们的 role
过滤,例如,一个用户 role: 'basic role'
无法删除具有 role: 'superuser'
的用户可以删除的内容。
我现在的是这样的:
Collection.allow({
insert: function(userId, collection) {
return Meteor.users.findOne({_id: userId, profile: {role: 'admin'}});
},
update: function(userId, collection, fields, modifier) {
return Meteor.users.findOne({_id: userId, profile: {role: 'admin'}});
},
remove: function(userId, collection) {
return Meteor.users.findOne({_id: userId, profile: {role: 'admin'}});
}
});
问题
这是验证用户角色的正确方法吗?有更好的方法吗?这方面的最佳做法是什么?
谢谢!
你应该看看 alanning:roles 包。它被广泛使用,甚至在 Meteor 文档中也有提及。除了角色,它还支持群组。
我正在构建一个 CMS,根据用户 role
,他们将能够 edit/update/delete/create 不同的区域,但由他们的 role
过滤,例如,一个用户 role: 'basic role'
无法删除具有 role: 'superuser'
的用户可以删除的内容。
我现在的是这样的:
Collection.allow({
insert: function(userId, collection) {
return Meteor.users.findOne({_id: userId, profile: {role: 'admin'}});
},
update: function(userId, collection, fields, modifier) {
return Meteor.users.findOne({_id: userId, profile: {role: 'admin'}});
},
remove: function(userId, collection) {
return Meteor.users.findOne({_id: userId, profile: {role: 'admin'}});
}
});
问题 这是验证用户角色的正确方法吗?有更好的方法吗?这方面的最佳做法是什么?
谢谢!
你应该看看 alanning:roles 包。它被广泛使用,甚至在 Meteor 文档中也有提及。除了角色,它还支持群组。