make transactions higher level (pass them everywhere)
This commit is contained in:
@@ -8,27 +8,33 @@ use crate::{
|
||||
};
|
||||
|
||||
pub fn initialise_reserved_users_if_needed() -> Result<(), UserError> {
|
||||
let conn = database::conn()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
if conn
|
||||
if tx
|
||||
.prepare("SELECT handle FROM users WHERE id = ?1")?
|
||||
.query_one((&Uuid::nil(),), |_| Ok(()))
|
||||
.optional()?
|
||||
.is_none()
|
||||
{
|
||||
let u = User::create_systemuser()?;
|
||||
LogEntry::new(u, LogAction::Initialize)?;
|
||||
let u = User::create_systemuser(&tx)?;
|
||||
LogEntry::new(&tx, u, LogAction::Initialize)?;
|
||||
}
|
||||
|
||||
if conn
|
||||
if tx
|
||||
.prepare("SELECT handle FROM users WHERE id = ?1")?
|
||||
.query_one((&Uuid::max(),), |_| Ok(()))
|
||||
.optional()?
|
||||
.is_none()
|
||||
{
|
||||
User::create_infradmin()?;
|
||||
LogEntry::new(User::get_by_id(Uuid::nil())?, LogAction::RegenInfradmin)?;
|
||||
User::create_infradmin(&tx)?;
|
||||
LogEntry::new(
|
||||
&tx,
|
||||
User::get_by_id(&tx, Uuid::nil())?,
|
||||
LogAction::RegenInfradmin,
|
||||
)?;
|
||||
}
|
||||
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user