Function update_permission

Source
pub async fn update_permission(
    pool: &Pool<MySql>,
    id: i64,
    name: Option<&str>,
    description: Option<&str>,
    resource_type: Option<&str>,
) -> Result<Permission>
Expand description

Updates an existing permission’s information.

This function modifies a permission record with the provided name, description, and/or resource type. It supports partial updates, allowing you to update only the fields that need changing.

§Arguments

  • pool - Database connection pool for executing the query
  • id - Unique identifier of the permission to update
  • name - Optional new name for the permission
  • description - Optional new description for the permission
  • resource_type - Optional new resource type for the permission

§Returns

  • Ok(Permission) - Successfully updated permission record
  • Err(anyhow::Error) - Failed to update permission

§Dynamic Query Building

This function dynamically builds an SQL query based on which parameters are provided. Only the fields specified with Some values will be updated, while None values are ignored.

§Transaction Handling

This function uses a database transaction to ensure atomicity of the operation. If any part of the operation fails, the entire operation is rolled back.

§Important

Changing a permission’s properties may affect the behavior of the RBAC system. Consider the impact on existing roles and users before making changes, especially to the name or resource_type fields.