Add dynamic completion for users and databases
All checks were successful
Build and test / check (push) Successful in 1m35s
Build and test / build (push) Successful in 2m46s
Build and test / test (push) Successful in 3m10s
Build and test / check-license (push) Successful in 6m12s
Build and test / docs (push) Successful in 4m39s

This commit is contained in:
2025-12-01 17:26:17 +09:00
parent cb3f3f3e1d
commit f348e67622
26 changed files with 383 additions and 17 deletions

View File

@@ -51,6 +51,44 @@ async fn unsafe_user_exists(
result
}
pub async fn complete_user_name(
user_prefix: String,
unix_user: &UnixUser,
connection: &mut MySqlConnection,
) -> Vec<MySQLUser> {
let result = sqlx::query(
r#"
SELECT `User` AS `user`
FROM `mysql`.`user`
WHERE `User` REGEXP ?
AND `User` LIKE ?
"#,
)
.bind(create_user_group_matching_regex(unix_user))
.bind(format!("{}%", user_prefix))
.fetch_all(connection)
.await;
match result {
Ok(rows) => rows
.into_iter()
.filter_map(|row| {
let user: String = try_get_with_binary_fallback(&row, "user").ok()?;
Some(user.into())
})
.collect(),
Err(err) => {
tracing::error!(
"Failed to complete user name for prefix '{}' and user '{}': {:?}",
user_prefix,
unix_user.username,
err
);
vec![]
}
}
}
pub async fn create_database_users(
db_users: Vec<MySQLUser>,
unix_user: &UnixUser,