This commit is contained in:
2025-11-06 22:21:27 +01:00
parent a6f79dbc75
commit ef2ed2dc58
23 changed files with 4371 additions and 3482 deletions
+12 -6
View File
@@ -26,7 +26,7 @@ use papercrate::{
},
storage::{ObjectStorage, S3Storage, TenantStorage},
tenants::TenantService,
utils::tracing::init_tracing,
utils::{text::normalize_identifier, tracing::init_tracing},
};
#[derive(Parser)]
@@ -162,20 +162,26 @@ async fn main() -> Result<()> {
}
fn create_user(pool: &PgPool, username: &str) -> Result<()> {
if username.trim().is_empty() {
bail!("username must not be empty");
}
let username = normalize_identifier(
username,
100,
"username must not be empty",
"username must not exceed 100 characters",
Some("username may only contain printable characters"),
|ch| !ch.is_control(),
)
.map_err(|err| anyhow!("{:?}", err))?;
let mut conn = pool.get().context("failed to get database connection")?;
let exists: bool =
select(exists(users::table.filter(users::username.eq(username)))).get_result(&mut conn)?;
select(exists(users::table.filter(users::username.eq(&username)))).get_result(&mut conn)?;
if exists {
bail!("user '{}' already exists", username);
}
let new_user = NewUser {
id: Uuid::new_v4(),
username: username.to_string(),
username: username.clone(),
};
diesel::insert_into(users::table)