How roles, permissions, and hierarchies work
masterIn meteor-roles, roles, permissions, and scopes are all treated as simple tags assigned to users. You can use them for high-level roles (e.g., admin) or granular permissions (e.g., users.view).
Role Hierarchies
You can create a hierarchy where a parent role automatically includes the permissions of its children (subroles). This allows you to create "super roles" that aggregate multiple permissions. If a user is assigned a parent role, they are considered to have all descendant roles as well.
Example of creating a hierarchy:
import { Roles } from 'meteor/alanning:roles';
// Create the roles
await Roles.createRoleAsync('user');
await Roles.createRoleAsync('admin');
await Roles.createRoleAsync('USERS_VIEW');
await Roles.createRoleAsync('POST_EDIT');
// Define hierarchy: admin has USERS_VIEW and POST_EDIT; user only has POST_EDIT
await Roles.addRolesToParentAsync('USERS_VIEW', 'admin');
await Roles.addRolesToParentAsync('POST_EDIT', 'admin');
await Roles.addRolesToParentAsync('POST_EDIT', 'user');import { Roles } from 'meteor/alanning:roles';
await Roles.createRoleAsync('user');
await Roles.createRoleAsync('admin');
await Roles.createRoleAsync('USERS_VIEW');
await Roles.createRoleAsync('POST_EDIT');
await Roles.addRolesToParentAsync('USERS_VIEW', 'admin');
await Roles.addRolesToParentAsync('POST_EDIT', 'admin');
await Roles.addRolesToParentAsync('POST_EDIT', 'user');