Overview
TradeMaster Transactions uses CASL (Conditional Ability Language) for fine-grained, role-based access control (RBAC). This system allows you to define precise permissions for different user roles, controlling access to specific features, views, and actions throughout the platform.CASL Architecture
Core Components
AbilityContext
React context that provides ability instances to components throughout the app.
DefineAbilities
Function that defines permissions based on user account type.
PermissionGuard
Component that protects routes and UI elements based on permissions.
Ability Builder
CASL’s fluent API for defining what users can and cannot do.
Permission Structure
Ability Definition
Permissions are defined inguards/contexts/DefineAbilities.js:
Permission Syntax
Permissions follow the pattern:can(action, subject)
- Action: What operation can be performed (e.g., ‘create’, ‘read’, ‘edit’, ‘view’)
- Subject: What resource the action applies to (e.g., ‘events’, ‘contracts’, ‘usersStaff’)
Role-Based Permissions
Administrator
Administrators have full platform access:The
manage all permission grants unrestricted access to all platform features.Cliente (Client)
Clients have full access to manage their own events and resources:Coordinador (Coordinator)
Coordinators have extensive permissions for event management but limited administrative access:- Can Perform
- Cannot Perform
User Management
- Create and edit client users
- Create and edit collaborator users
- View staff details (cannot create/edit)
- Create and edit events
- Manage event pre-staging (pre-montaje)
- Create and read event tickets
- Manage event credentials
- View contract details
- Create contracts and addendums
- View addendum details
- Create and view event venues
- View and manage ticket offices
- View office sales data
- View customer details, tickets, and orders
Contador (Accountant)
Accountants have read-only access focused on financial data:Permitted Actions
Permitted Actions
- View client details
- Read contract and addendum details
- Access platform settings
- View event details
- Search and view tickets
- View client payouts
Restricted Actions
Restricted Actions
- Cannot create or modify users (staff, clients, collaborators)
- Cannot create or edit events
- Cannot create contracts or addendums
- Cannot manage event venues
- Cannot change event or ticket status
- No access to event configuration or ticket generation
Soporte (Support)
Support staff have limited access focused on customer assistance: Can Access:- View client and collaborator details
- View event details and configurations
- Search and view tickets
- View event credentials (read-only)
- View event venue details
- Access event pre-staging information
- Staff, client, or collaborator management
- Contract creation or viewing
- Platform settings
- Event or ticket status changes
- Payout information
- Event creation or credential generation
Implementation
Setting Up Abilities
Initialize the ability context in your app:App.jsx
Using Permission Guards
Protect routes and components with thePermissionGuard:
guards/authGuard/PermissionGuard.js
Protecting Routes
Conditional UI Rendering
Hide or show UI elements based on permissions:Permission Reference
Common Permission Subjects
| Subject | Description |
|---|---|
usersStaff | Staff user management |
usersClients | Client user management |
usersCollaborators | Collaborator user management |
events | Event creation and editing |
eventsTickets | Ticket generation and management |
eventsCredentials | Event credential management |
contracts | Contract creation |
addendum | Contract addendum creation |
EventVenue | Event venue management |
View Permissions
View permissions control access to specific pages:Custom Permission Logic
Adding New Roles
To add a new role with custom permissions:DefineAbilities.js
Security Best Practices
Backend Validation
Always enforce permissions server-side:Troubleshooting
Permission Denied Redirect Loop
Permission Denied Redirect Loop
Ensure the
/auth/permissions route itself doesn’t require permissions. This is the error page users are redirected to when they lack access.Permissions Not Updating After Role Change
Permissions Not Updating After Role Change
Permissions are calculated when abilities are defined. If a user’s role changes, they need to log out and back in, or you need to manually update the ability context.
User Has No Permissions
User Has No Permissions
Check that the user object is being passed correctly to
defineAbilitiesFor() and that user.account_type matches one of the defined roles exactly (case-sensitive).Next Steps
Authentication
Learn about authentication setup
Contracts
Manage contracts and addendums