mirror of
https://tangled.org/tranquil.farm/tranquil-pds
synced 2026-09-12 13:16:04 +00:00
migration improvements
This commit is contained in:
@@ -905,6 +905,7 @@ pub struct RecoverPasskeyAccountResult {
|
||||
pub struct MigrationReactivationInput {
|
||||
pub did: Did,
|
||||
pub new_handle: Handle,
|
||||
pub new_email: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@@ -2699,12 +2699,22 @@ impl UserRepository for PostgresUserRepository {
|
||||
return Err(tranquil_db_traits::MigrationReactivationError::NotDeactivated);
|
||||
}
|
||||
|
||||
let update_result: Result<_, sqlx::Error> =
|
||||
let update_result: Result<_, sqlx::Error> = if let Some(ref new_email) = input.new_email {
|
||||
sqlx::query(
|
||||
"UPDATE users SET handle = $1, email = $2, email_verified = false WHERE id = $3",
|
||||
)
|
||||
.bind(input.new_handle.as_str())
|
||||
.bind(new_email)
|
||||
.bind(account_id)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
} else {
|
||||
sqlx::query("UPDATE users SET handle = $1 WHERE id = $2")
|
||||
.bind(input.new_handle.as_str())
|
||||
.bind(account_id)
|
||||
.execute(&mut *tx)
|
||||
.await;
|
||||
.await
|
||||
};
|
||||
|
||||
if let Err(e) = update_result {
|
||||
if let Some(db_err) = e.as_database_error()
|
||||
|
||||
@@ -410,6 +410,7 @@ pub async fn create_account(
|
||||
let reactivate_input = tranquil_db_traits::MigrationReactivationInput {
|
||||
did: Did::new_unchecked(&did),
|
||||
new_handle: Handle::new_unchecked(&handle),
|
||||
new_email: email.clone(),
|
||||
};
|
||||
match state
|
||||
.user_repo
|
||||
@@ -477,6 +478,29 @@ pub async fn create_account(
|
||||
error!("Error creating session: {:?}", e);
|
||||
return ApiError::InternalError(None).into_response();
|
||||
}
|
||||
let hostname =
|
||||
std::env::var("PDS_HOSTNAME").unwrap_or_else(|_| "localhost".to_string());
|
||||
let verification_required = if let Some(ref user_email) = email {
|
||||
let token =
|
||||
crate::auth::verification_token::generate_migration_token(&did, user_email);
|
||||
let formatted_token =
|
||||
crate::auth::verification_token::format_token_for_display(&token);
|
||||
if let Err(e) = crate::comms::comms_repo::enqueue_migration_verification(
|
||||
state.user_repo.as_ref(),
|
||||
state.infra_repo.as_ref(),
|
||||
reactivated.user_id,
|
||||
user_email,
|
||||
&formatted_token,
|
||||
&hostname,
|
||||
)
|
||||
.await
|
||||
{
|
||||
warn!("Failed to enqueue migration verification email: {:?}", e);
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
return (
|
||||
axum::http::StatusCode::OK,
|
||||
Json(CreateAccountOutput {
|
||||
@@ -485,7 +509,7 @@ pub async fn create_account(
|
||||
did_doc: state.did_resolver.resolve_did_document(&did).await,
|
||||
access_jwt: access_meta.token,
|
||||
refresh_jwt: refresh_meta.token,
|
||||
verification_required: false,
|
||||
verification_required,
|
||||
verification_channel: "email".to_string(),
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -151,6 +151,8 @@ pub async fn submit_plc_operation(
|
||||
}
|
||||
}
|
||||
let _ = state.cache.delete(&format!("handle:{}", user.handle)).await;
|
||||
let _ = state.cache.delete(&format!("plc:doc:{}", did)).await;
|
||||
let _ = state.cache.delete(&format!("plc:data:{}", did)).await;
|
||||
if state.did_resolver.refresh_did(did).await.is_none() {
|
||||
warn!(did = %did, "Failed to refresh DID cache after PLC update");
|
||||
}
|
||||
|
||||
@@ -425,6 +425,11 @@ pub async fn activate_account(
|
||||
if let Some(ref h) = handle {
|
||||
let _ = state.cache.delete(&format!("handle:{}", h)).await;
|
||||
}
|
||||
let _ = state.cache.delete(&format!("plc:doc:{}", did)).await;
|
||||
let _ = state.cache.delete(&format!("plc:data:{}", did)).await;
|
||||
if state.did_resolver.refresh_did(did.as_str()).await.is_none() {
|
||||
warn!("[MIGRATION] activateAccount: Failed to refresh DID cache for {}", did);
|
||||
}
|
||||
info!(
|
||||
"[MIGRATION] activateAccount: Sequencing account event (active=true) for did={}",
|
||||
did
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
pub fn test_function() -> &'static str {
|
||||
"NEW_FILE_TEST_67890"
|
||||
}
|
||||
Reference in New Issue
Block a user