Meteor-Community-Packages/meteor-roles

Add isInRole to JS API as well

開放

#56 建立於 2014年9月19日

 (17 則留言) (0 個反應) (0 位負責人)JavaScript (161 個分叉)batch import
enhancementgood first issuehelp wanted

倉庫指標

星標
 (919 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Something you frequently do in the application, is check if the current user is allowed to access something. As there currently is no shorthand for this in the Javascript API, you have to do something like:

if ( Roles.userIsInRole( Meteor.userId(), 'permission' ) )
    // ...

I noticed the UI helper offers a beautiful shortand syntax for this, using the currently logged in user. I think it would make a lot of sense to add this to the API as well, so that one can simply do:

if ( Roles.isInRole( 'permission' ) )
    // ...

or even better:

if ( Roles.has( 'permission' ) )
    // ...

貢獻者指南