pub async fn get_user_permissions(
pool: &Pool<MySql>,
user_id: i64,
) -> Result<Vec<Permission>>
Expand description
Retrieves all permissions effectively granted to a specific user.
This function computes the complete set of permissions a user has based on all their assigned roles. It eliminates duplicate permissions when a user has multiple roles that grant the same permission.
§Arguments
pool
- Database connection pool for executing the queryuser_id
- Unique identifier of the user whose permissions to retrieve
§Returns
Ok(Vec<Permission>)
- Successfully retrieved list of user permissionsErr(anyhow::Error)
- Failed to fetch user permissions
§Query Details
This function performs multiple JOIN operations across the permissions, permissions_role, and role_user tables to calculate the effective permissions for a user based on all their assigned roles.
§Performance Considerations
This query can be relatively expensive in systems with many roles and permissions. Consider caching the results when appropriate, especially for frequently accessed users.