pub fn clamp_permission(
delegated_permission: Permission,
bounds: &PermissionBounds,
) -> PermissionExpand description
Clamp a delegated permission to fit within the specified bounds
This function enforces permission boundaries by:
- Applying the maximum bound (required) - reduces permission if it exceeds max
- Applying the minimum bound (optional) - increases permission if it’s below min
§Arguments
delegated_permission- The permission level from the delegated treebounds- The permission bounds configured for this delegation
§Returns
The effective permission after applying bounds
§Examples
use eidetica::auth::permission::clamp_permission;
use eidetica::auth::types::{Permission, PermissionBounds};
let bounds = PermissionBounds {
max: Permission::Write(10),
min: Some(Permission::Read),
};
// Admin permission gets clamped down to Write(10)
let clamped = clamp_permission(Permission::Admin(5), &bounds);
assert_eq!(clamped, Permission::Write(10));
// Read permission stays as Read (meets minimum)
let clamped = clamp_permission(Permission::Read, &bounds);
assert_eq!(clamped, Permission::Read);