2016-06-07 72 views
0

我正在建立一個CMS,並根據用戶role他們將能夠編輯/更新/刪除/創建不同的區域,但過濾了他們的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'}}); 
    } 
}); 

問題 這是驗證用戶角色的正確方法?有更好的方法嗎?這有什麼最佳做法?

謝謝!

回答

2

你應該看看alanning:roles包。它被廣泛使用,甚至在Meteor Docs中提到。除了角色之外,它還支持組。

+1

這是Meteor的canonical _roles_包。 –

相關問題