hasPermission method
Checks if the user has a specific permission.
Implementation
bool hasPermission(String permission) {
// First check the map representation
final user = this.user;
if (user != null) {
// Check roles for wildcard permissions first
final roles = user['roles'];
if (roles is List<dynamic>) {
// Check for admin roles that have all permissions
if (roles.contains('admin') || roles.contains('super_admin')) {
return true;
}
}
// Check explicit permissions
final permissions = user['permissions'];
if (permissions is List<dynamic>) {
return permissions.contains(permission);
}
}
// If no map data, check if we have an Authenticatable instance
// Note: The Authenticatable interface doesn't define permissions,
// so this would need to be implemented by subclasses
return false;
}