Meteor-Community-Packages / meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
http://meteor-community-packages.github.io/meteor-roles/
MIT License
921 stars 168 forks source link

How to check if is Roles.GLOBAL_GROUP #221

Closed tomscholz closed 7 years ago

tomscholz commented 7 years ago

What I am trying to do, is to grant an Admin access to every page. What I have done so far is to create an admin user (Roles.addUsersToRoles(userId, 'admin', Roles.GLOBAL_GROUP) ) when the database with users is empty. Also when a new user registers it is getting assigned to a normal-user "group" / "scope". When I check in a template if the user has permission to view the content via:

{{#if isInRole 'editOffer, viewOffer' 'normal-user'}}
    {{>showContent}}
    {{else}}
    {{>noaccess}}
  {{/if}}

I can access the page with an account that is in the normal-user "group" / "scope" with the permission to view and edit an "Offer", but with the admin account I get the noaccess template. What should I do or what am I doing wrong?

I found this:

    Roles.addUsersToRoles(userId, 'super-admin', Roles.GLOBAL_GROUP)
    if (Roles.userIsInRole(userId, ['manage-team', 'super-admin'], 'real-madrid.com')) {
        console.log('Hell Yeah');

        // True!  Even though Joe doesn't manage Real Madrid, he is 'super-admin' in
        // the Global Group so this check succeeds.

    }
Frazer commented 7 years ago

it looks like your admin used doesn't have 'editOffer, viewOffer' 'normal-user'

either add admin to `{{#if isInRole 'admin', 'editOffer, viewOffer' 'normal-user'}}

or add 'editOffer, viewOffer' 'normal-user' to your admin user.