Overview
The Transport Logistics platform uses a role-based access control (RBAC) system with two distinct roles: Admin and User. Each role has different permissions and capabilities within the system.Roles are assigned during user creation and can be changed by administrators at any time.
Role Types
Admin
Full access to all features, resources, and settings. Can manage users, configure the system, and access all data.
User
Limited access to assigned resources. Can view and interact with assigned packages but cannot access administrative features.
Admin Role
Capabilities
Administrators have unrestricted access to the platform:- User Management
- Resource Access
- System Configuration
Full Control:
- Create new user accounts
- Edit existing user profiles
- Change user roles
- Assign packages to users
- Activate/deactivate user accounts
- Reset user passwords
- View all user information
Admin Permissions in Code
The system checks admin status using the role field:Database-Level Permissions
Admin permissions are enforced at the database level using Row Level Security (RLS):User Role
Capabilities
Regular users have restricted access based on their assignments:- Package Access
- View-Only Resources
- Personal Settings
Limited to Assignments:
- View only assigned packages
- Cannot create new packages (unless they are the creator)
- Can update packages they created
- Cannot access unassigned packages
Package access is controlled through the
assigned_packages field in the user profile.User Permissions in Code
The application restricts UI elements based on role:Database-Level Permissions
User permissions are enforced through RLS policies:Permission Matrix
User Management
| Action | Admin | User |
|---|---|---|
| View all users | ✅ | ❌ |
| Create users | ✅ | ❌ |
| Edit any user | ✅ | ❌ |
| Edit own profile | ✅ | ✅ |
| Change user roles | ✅ | ❌ |
| Reset passwords | ✅ | ❌ |
| Change own password | ✅ | ✅ |
| Activate/deactivate users | ✅ | ❌ |
Resource Management
| Resource | Admin Access | User Access |
|---|---|---|
| Vehicles | Full (CRUD) | View only |
| Shipments | Full (CRUD) | View only |
| Packages | Full (all packages) | View assigned only |
| Routes | Full (CRUD) | View only |
| Transporters | Full (CRUD) | View only |
| Materials | Full (CRUD) | View only |
Settings & Configuration
| Setting | Admin | User |
|---|---|---|
| Own profile settings | ✅ | ✅ |
| Own notification preferences | ✅ | ✅ |
| System-wide settings | ✅ | ❌ |
| User settings (others) | ✅ | ❌ |
| Analytics & reports | ✅ | ❌ |
Row Level Security (RLS)
What is RLS?
Row Level Security is a PostgreSQL feature that restricts which rows users can access in a table. The Transport Logistics platform uses RLS to enforce permissions at the database level.RLS policies ensure data security even if the application layer is bypassed.
How RLS Works
The system uses a helper function to determine the current user’s role:Enabled Tables
RLS is enabled on all critical tables:User Data
- profiles
- user_settings
Resources
- vehicles
- shipments
- packages
- routes
- transporters
- materials
Changing User Roles
How to Change a User’s Role
Security Best Practices
Principle of Least Privilege
Principle of Least Privilege
Grant users the minimum permissions necessary to perform their job functions. Most users should have the “User” role, with “Admin” reserved for trusted team members.
Regular Access Reviews
Regular Access Reviews
Periodically review user roles and permissions to ensure they remain appropriate. Remove admin access when it’s no longer needed.
Limit Admin Accounts
Limit Admin Accounts
Keep the number of admin accounts to a minimum. Too many admins increase security risks and make audit trails harder to follow.
Use Package Assignments
Use Package Assignments
Even though admins can access all packages, document which packages each user (including admins) is responsible for using the assignment feature.
Monitor Admin Actions
Monitor Admin Actions
Track and log administrative actions for security auditing and compliance purposes.
Common Scenarios
Scenario: Team Lead Needs Admin Access
Evaluate Need
Determine if the team lead truly needs full admin access or if specific package assignments would suffice.
Scenario: User Needs Access to Additional Packages
Scenario: Temporary Admin Access
Viewing Your Own Role
All users can view their current role in the Settings page:- Navigate to Settings from the main menu
- Go to the Profile tab
- Look for the “Account Role” section
- Your current role (Admin or User)
- A description of what that role can access
You cannot change your own role. Only administrators can modify user roles.
Technical Implementation
Authentication Context
The authentication system stores the user’s role in the auth context:Role Type Definition
Database Schema
The profiles table stores user roles:Troubleshooting
User Can't See Admin Features
User Can't See Admin Features
Check:
- Verify the user’s role is set to “Admin” in User Management
- Have the user log out and log back in
- Clear browser cache and cookies
- Check browser console for errors
Permission Changes Not Taking Effect
Permission Changes Not Taking Effect
Solutions:
- Role changes are immediate but may require a page refresh
- Have the user reload the page (F5 or Cmd+R)
- In some cases, logging out and back in may be necessary
- Check that the database update was successful
Admin Can't Access User Management
Admin Can't Access User Management
Possible causes:
- Role may not be correctly set in the database
- RLS policies may be blocking access
- Check the browser console for errors
- Verify the admin user has an active account
User Sees Resources They Shouldn't
User Sees Resources They Shouldn't
Investigate:
- This should not happen due to RLS policies
- Check if the user was recently demoted from admin
- Verify RLS policies are correctly applied
- Review package assignments
Related Resources
Managing Users
Learn how to create, edit, and manage user accounts
User Settings
Guide for users to manage their profile and preferences