Function create_role

Source
pub async fn create_role(
    pool: &Pool<MySql>,
    name: &str,
    description: Option<&str>,
) -> Result<Role>
Expand description

Creates a new role in the system.

This function inserts a new role record with the provided name and description. Roles are a fundamental component of the role-based access control (RBAC) system, used to group related permissions and assign them to users.

§Arguments

  • pool - Database connection pool for executing the query
  • name - Name of the new role (should be unique and descriptive)
  • description - Optional description explaining the role’s purpose

§Returns

  • Ok(Role) - Successfully created role record
  • Err(anyhow::Error) - Failed to create role record

§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.

§Note

Creating a role doesn’t automatically assign any permissions to it. Use assign_permission_to_role to associate permissions with the newly created role.