Overview
Zoo Arcadia implements a flexible Role-Based Access Control (RBAC) system with three core roles and support for VIP (user-specific) permissions. This system controls access to all administrative features.The Three Roles
Admin
Full system access including user management, role configuration, and all CRUD operations.
Veterinary
Specialized access for animal health management, veterinary reports, and habitat suggestions.
Employee
Basic access for day-to-day operations like feeding logs and testimonial moderation.
Role Model
Roles are defined in theroles table and managed through the Role model:
Key Methods
Returns all roles from the database
Finds a specific role by ID
Returns all permissions assigned to a role
Updates the permissions for a role (transactional)
Permission System
How Permissions Work
Permissions are stored in three tables:permissions: Master list of all available permissionsroles_permissions: Maps permissions to rolesusers_permissions: Maps VIP permissions directly to users
Loading User Permissions
When a user logs in, the system loads ALL their permissions (role + VIP):VIP Permissions
VIP permissions allow granting specific permissions to individual users, overriding or extending their role permissions.Use Cases
When to use VIP permissions
When to use VIP permissions
- Temporarily granting elevated access to a user
- Testing new features with specific users
- Giving a user access to features outside their normal role
- Customizing access for special circumstances
Managing VIP Permissions
The
overwriteVipPermissionsIdsUserHasAssigned() method uses a database transaction to safely delete old permissions and insert new ones.Checking Permissions
The system provides ahasPermission() helper function to check if the current user has a specific permission:
Common Permission Patterns
Permission Naming Convention
Permissions follow a consistent naming pattern:Example Permissions
Animal Permissions
Animal Permissions
animals-view: View animals listanimals-create: Create new animalsanimals-edit: Edit existing animalsanimals-delete: Delete animalsanimal_feeding-assign: Create feeding logsanimal_feeding-delete: Delete feeding logs
Veterinary Permissions
Veterinary Permissions
vet_reports-view: View health reportsvet_reports-create: Create health reportsvet_reports-edit: Edit health reports
Habitat Permissions
Habitat Permissions
habitats-view: View habitatshabitats-create: Create habitatshabitats-edit: Edit habitatshabitats-delete: Delete habitats
User Management
User Management
users-view: View usersusers-create: Create usersusers-edit: Edit usersusers-delete: Delete users
Role-Specific Access
Some features check the role name directly instead of permissions:Managing Role Permissions
Admins can manage role permissions through the back office:Display permission checkboxes
Show all available permissions with checkboxes, marking the assigned ones as checked.
Transaction Safety
ThesavePermissions() method uses transactions to ensure data integrity:
Code Reference
- User Model:
App/users/models/user.php:376-409(permission loading) - Role Model:
App/roles/models/role.php:20-265(role management) - VIP Permissions:
App/users/models/user.php:309-373(VIP management) - Permission Check:
includes/functions.php(hasPermission helper)
Remember to reload user permissions after updating role or VIP permissions. Users need to log out and back in to see permission changes take effect.