chore: temp

This commit is contained in:
Nathan 2025-04-22 20:18:13 +08:00
parent 63e43db0c2
commit 7e88a3897c
4 changed files with 22 additions and 19 deletions

View File

@ -11,6 +11,7 @@ async fn migrate_historical_empty_document_test() {
"historical_empty_document", "historical_empty_document",
) )
.unwrap(); .unwrap();
let s = user_db_path.to_str().unwrap().to_string();
let test = let test =
EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string()).await; EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string()).await;

View File

@ -1,4 +1,6 @@
use crate::user_manager::manager_history_user::ANON_USER;
use flowy_sqlite::kv::KVStorePreferences; use flowy_sqlite::kv::KVStorePreferences;
use flowy_user_pub::entities::AuthType;
use flowy_user_pub::session::Session; use flowy_user_pub::session::Session;
use serde_json::{json, Value}; use serde_json::{json, Value};
use std::sync::Arc; use std::sync::Arc;
@ -6,7 +8,7 @@ use uuid::Uuid;
const MIGRATION_USER_NO_USER_UUID: &str = "migration_user_no_user_uuid"; const MIGRATION_USER_NO_USER_UUID: &str = "migration_user_no_user_uuid";
pub fn migrate_session_with_user_uuid( pub fn migrate_session(
session_cache_key: &str, session_cache_key: &str,
store_preferences: &Arc<KVStorePreferences>, store_preferences: &Arc<KVStorePreferences>,
) -> Option<Session> { ) -> Option<Session> {
@ -24,10 +26,20 @@ pub fn migrate_session_with_user_uuid(
if let Ok(new_session) = serde_json::from_value::<Session>(value) { if let Ok(new_session) = serde_json::from_value::<Session>(value) {
let _ = store_preferences.set_object(session_cache_key, &new_session); let _ = store_preferences.set_object(session_cache_key, &new_session);
return Some(new_session);
} }
} }
} }
None if let Some(mut session) = store_preferences.get_object::<Session>(session_cache_key) {
if let Some(anon_session) = store_preferences.get_object::<Session>(ANON_USER) {
if session.user_id == anon_session.user_id
&& session.user_workspace.workspace_type != AuthType::Local
{
session.user_workspace.workspace_type = AuthType::Local;
let _ = store_preferences.set_object(session_cache_key, &session);
}
}
}
store_preferences.get_object::<Session>(session_cache_key)
} }

View File

@ -1,9 +1,8 @@
use crate::migrations::session_migration::migrate_session_with_user_uuid; use crate::migrations::session_migration::migrate_session;
use crate::services::db::UserDB; use crate::services::db::UserDB;
use crate::services::entities::{UserConfig, UserPaths}; use crate::services::entities::{UserConfig, UserPaths};
use collab_integrate::CollabKVDB; use collab_integrate::CollabKVDB;
use crate::user_manager::manager_history_user::ANON_USER;
use arc_swap::ArcSwapOption; use arc_swap::ArcSwapOption;
use collab_plugins::local_storage::kv::doc::CollabKVAction; use collab_plugins::local_storage::kv::doc::CollabKVAction;
use collab_plugins::local_storage::kv::KVTransactionDB; use collab_plugins::local_storage::kv::KVTransactionDB;
@ -30,9 +29,7 @@ impl AuthenticateUser {
pub fn new(user_config: UserConfig, store_preferences: Arc<KVStorePreferences>) -> Self { pub fn new(user_config: UserConfig, store_preferences: Arc<KVStorePreferences>) -> Self {
let user_paths = UserPaths::new(user_config.storage_path.clone()); let user_paths = UserPaths::new(user_config.storage_path.clone());
let database = Arc::new(UserDB::new(user_paths.clone())); let database = Arc::new(UserDB::new(user_paths.clone()));
let session = let session = migrate_session(&user_config.session_cache_key, &store_preferences).map(Arc::new);
migrate_session_with_user_uuid(&user_config.session_cache_key, &store_preferences)
.map(Arc::new);
Self { Self {
user_config, user_config,
database, database,
@ -150,17 +147,10 @@ impl AuthenticateUser {
.get_object::<Session>(&self.user_config.session_cache_key) .get_object::<Session>(&self.user_config.session_cache_key)
{ {
None => Err(FlowyError::new( None => Err(FlowyError::new(
ErrorCode::UserUnauthorized, ErrorCode::RecordNotFound,
"Can't find user session. Please login again", "Can't find user session. Please login again",
)), )),
Some(mut session) => { Some(session) => {
// Set the workspace type to local if the user is anon.
if let Some(anon_session) = self.store_preferences.get_object::<Session>(ANON_USER) {
if session.user_id == anon_session.user_id {
session.user_workspace.workspace_type = AuthType::Local;
}
}
let session = Arc::new(session); let session = Arc::new(session);
self.session.store(Some(session.clone())); self.session.store(Some(session.clone()));
Ok(session) Ok(session)

View File

@ -1,4 +1,4 @@
use crate::migrations::session_migration::migrate_session_with_user_uuid; use crate::migrations::session_migration::migrate_session;
use crate::services::data_import::importer::load_collab_by_object_ids; use crate::services::data_import::importer::load_collab_by_object_ids;
use crate::services::db::UserDBPath; use crate::services::db::UserDBPath;
@ -80,7 +80,7 @@ pub(crate) fn prepare_import(
} }
let user_paths = UserPaths::new(path.to_string()); let user_paths = UserPaths::new(path.to_string());
let other_store_preferences = Arc::new(KVStorePreferences::new(path)?); let other_store_preferences = Arc::new(KVStorePreferences::new(path)?);
migrate_session_with_user_uuid("appflowy_session_cache", &other_store_preferences); migrate_session("appflowy_session_cache", &other_store_preferences);
let imported_session = other_store_preferences let imported_session = other_store_preferences
.get_object::<Session>("appflowy_session_cache") .get_object::<Session>("appflowy_session_cache")
.ok_or(anyhow!( .ok_or(anyhow!(