chore: fix test

This commit is contained in:
Nathan 2025-04-20 13:35:06 +08:00
parent ccd1f5f8e9
commit bb5d36402a
8 changed files with 38 additions and 51 deletions

View File

@ -17,10 +17,10 @@ use flowy_server::af_cloud::define::{USER_DEVICE_ID, USER_EMAIL, USER_SIGN_IN_UR
use flowy_server_pub::af_cloud_config::AFCloudConfiguration;
use flowy_server_pub::AuthenticatorType;
use flowy_user::entities::{
AuthTypePB, AuthTypePB, ChangeWorkspaceIconPB, CloudSettingPB, CreateWorkspacePB,
ImportAppFlowyDataPB, OauthSignInPB, OpenUserWorkspacePB, RenameWorkspacePB,
RepeatedUserWorkspacePB, SignInUrlPB, SignInUrlPayloadPB, SignUpPayloadPB, UpdateCloudConfigPB,
UpdateUserProfilePayloadPB, UserProfilePB, UserWorkspaceIdPB, UserWorkspacePB,
AuthTypePB, ChangeWorkspaceIconPB, CloudSettingPB, CreateWorkspacePB, ImportAppFlowyDataPB,
OauthSignInPB, OpenUserWorkspacePB, RenameWorkspacePB, RepeatedUserWorkspacePB, SignInUrlPB,
SignInUrlPayloadPB, SignUpPayloadPB, UpdateCloudConfigPB, UpdateUserProfilePayloadPB,
UserProfilePB, UserWorkspaceIdPB, UserWorkspacePB,
};
use flowy_user::errors::{FlowyError, FlowyResult};
use flowy_user::event_map::UserEvent;
@ -140,7 +140,7 @@ impl EventIntegrationTest {
pub async fn af_cloud_sign_in_with_email(&self, email: &str) -> FlowyResult<UserProfilePB> {
let payload = SignInUrlPayloadPB {
email: email.to_string(),
authenticator: AuthTypePB::AppFlowyCloud,
authenticator: AuthTypePB::Server,
};
let sign_in_url = EventBuilder::new(self.clone())
.event(UserEvent::GenerateSignInURL)
@ -155,7 +155,7 @@ impl EventIntegrationTest {
map.insert(USER_DEVICE_ID.to_string(), Uuid::new_v4().to_string());
let payload = OauthSignInPB {
map,
authenticator: AuthTypePB::AppFlowyCloud,
authenticator: AuthTypePB::Server,
};
let user_profile = EventBuilder::new(self.clone())

View File

@ -46,7 +46,7 @@ impl UserStatusCallbackImpl {
#[async_trait]
impl UserStatusCallback for UserStatusCallbackImpl {
async fn did_init(
async fn on_launch_if_authenticated(
&self,
user_id: i64,
cloud_config: &Option<UserCloudConfig>,
@ -88,7 +88,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
Ok(())
}
async fn did_sign_in(
async fn on_sign_in(
&self,
user_id: i64,
user_workspace: &UserWorkspace,
@ -119,7 +119,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
Ok(())
}
async fn did_sign_up(
async fn on_sign_up(
&self,
is_new_user: bool,
user_profile: &UserProfile,
@ -196,12 +196,12 @@ impl UserStatusCallback for UserStatusCallbackImpl {
Ok(())
}
async fn did_expired(&self, _token: &str, user_id: i64) -> FlowyResult<()> {
async fn on_token_expired(&self, _token: &str, user_id: i64) -> FlowyResult<()> {
self.folder_manager.clear(user_id).await;
Ok(())
}
async fn open_workspace(
async fn on_workspace_opened(
&self,
user_id: i64,
user_workspace: &UserWorkspace,
@ -230,13 +230,13 @@ impl UserStatusCallback for UserStatusCallbackImpl {
Ok(())
}
fn did_update_network(&self, reachable: bool) {
fn on_network_status_changed(&self, reachable: bool) {
info!("Notify did update network: reachable: {}", reachable);
self.collab_builder.update_network(reachable);
self.storage_manager.update_network_reachable(reachable);
}
fn did_update_plans(&self, plans: Vec<SubscriptionPlan>) {
fn on_subscription_plans_updated(&self, plans: Vec<SubscriptionPlan>) {
let mut storage_plan_changed = false;
for plan in &plans {
match plan {
@ -249,7 +249,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
}
}
fn did_update_storage_limitation(&self, can_write: bool) {
fn on_storage_permission_updated(&self, can_write: bool) {
if can_write {
self.storage_manager.enable_storage_write_access();
} else {

View File

@ -475,7 +475,7 @@ pub async fn update_network_state_handler(
.user_status_callback
.read()
.await
.did_update_network(reachable);
.on_network_status_changed(reachable);
Ok(())
}

View File

@ -279,10 +279,9 @@ pub enum UserEvent {
pub trait UserStatusCallback: Send + Sync + 'static {
/// When the [AuthType] changed, this method will be called. Currently, the auth type
/// will be changed when the user sign in or sign up.
fn authenticator_did_changed(&self, _authenticator: AuthType) {}
/// This will be called after the application launches if the user is already signed in.
/// If the user is not signed in, this method will not be called
async fn did_init(
fn on_auth_type_changed(&self, _authenticator: AuthType) {}
/// Fires on app launch, but only if the user is already signed in.
async fn on_launch_if_authenticated(
&self,
_user_id: i64,
_cloud_config: &Option<UserCloudConfig>,
@ -292,8 +291,8 @@ pub trait UserStatusCallback: Send + Sync + 'static {
) -> FlowyResult<()> {
Ok(())
}
/// Will be called after the user signed in.
async fn did_sign_in(
/// Fires right after the user successfully signs in.
async fn on_sign_in(
&self,
_user_id: i64,
_user_workspace: &UserWorkspace,
@ -302,8 +301,9 @@ pub trait UserStatusCallback: Send + Sync + 'static {
) -> FlowyResult<()> {
Ok(())
}
/// Will be called after the user signed up.
async fn did_sign_up(
/// Fires right after the user successfully signs up.
async fn on_sign_up(
&self,
_is_new_user: bool,
_user_profile: &UserProfile,
@ -314,10 +314,13 @@ pub trait UserStatusCallback: Send + Sync + 'static {
Ok(())
}
async fn did_expired(&self, _token: &str, _user_id: i64) -> FlowyResult<()> {
/// Fires when an authentication token has expired.
async fn on_token_expired(&self, _token: &str, _user_id: i64) -> FlowyResult<()> {
Ok(())
}
async fn open_workspace(
/// Fires when a workspace is opened by the user.
async fn on_workspace_opened(
&self,
_user_id: i64,
_user_workspace: &UserWorkspace,
@ -325,9 +328,9 @@ pub trait UserStatusCallback: Send + Sync + 'static {
) -> FlowyResult<()> {
Ok(())
}
fn did_update_network(&self, _reachable: bool) {}
fn did_update_plans(&self, _plans: Vec<SubscriptionPlan>) {}
fn did_update_storage_limitation(&self, _can_write: bool) {}
fn on_network_status_changed(&self, _reachable: bool) {}
fn on_subscription_plans_updated(&self, _plans: Vec<SubscriptionPlan>) {}
fn on_storage_permission_updated(&self, _can_write: bool) {}
}
/// Acts as a placeholder [UserStatusCallback] for the user session, but does not perform any function

View File

@ -1,7 +1,7 @@
use client_api::entity::GotrueTokenResponse;
use collab_integrate::collab_builder::AppFlowyCollabBuilder;
use collab_integrate::CollabKVDB;
use flowy_error::{internal_error, ErrorCode, FlowyResult};
use flowy_error::{internal_error, FlowyResult};
use arc_swap::ArcSwapOption;
use collab::lock::RwLock;
@ -21,7 +21,6 @@ use serde_json::Value;
use std::string::ToString;
use std::sync::atomic::{AtomicI64, Ordering};
use std::sync::{Arc, Weak};
use tokio::sync::Mutex;
use tokio_stream::StreamExt;
use tracing::{debug, error, event, info, instrument, warn};
use uuid::Uuid;
@ -40,7 +39,6 @@ use crate::services::cloud_config::get_cloud_config;
use crate::services::collab_interact::{DefaultCollabInteract, UserReminder};
use crate::migrations::doc_key_with_workspace::CollabDocKeyWithWorkspaceIdMigration;
use crate::user_manager::user_login_state::UserAuthProcess;
use crate::{errors::FlowyError, notification::*};
use flowy_user_pub::session::Session;
use flowy_user_pub::sql::*;
@ -53,7 +51,6 @@ pub struct UserManager {
pub(crate) collab_builder: Weak<AppFlowyCollabBuilder>,
pub(crate) collab_interact: RwLock<Arc<dyn UserReminder>>,
pub(crate) user_workspace_service: Arc<dyn UserWorkspaceService>,
auth_process: Mutex<Option<UserAuthProcess>>,
pub(crate) authenticate_user: Arc<AuthenticateUser>,
refresh_user_profile_since: AtomicI64,
pub(crate) is_loading_awareness: Arc<DashMap<Uuid, bool>>,
@ -78,7 +75,6 @@ impl UserManager {
user_status_callback,
collab_builder,
collab_interact: RwLock::new(Arc::new(DefaultCollabInteract)),
auth_process: Default::default(),
authenticate_user,
refresh_user_profile_since,
user_workspace_service,
@ -270,7 +266,7 @@ impl UserManager {
let _ = self.initial_user_awareness(&session, &user.auth_type).await;
user_status_callback
.did_init(
.on_launch_if_authenticated(
user.uid,
&cloud_config,
&session.user_workspace,
@ -363,7 +359,7 @@ impl UserManager {
.user_status_callback
.read()
.await
.did_sign_in(
.on_sign_in(
user_profile.uid,
&latest_workspace,
&self.authenticate_user.user_config.device_id,
@ -421,7 +417,7 @@ impl UserManager {
.user_status_callback
.read()
.await
.did_sign_up(
.on_sign_up(
response.is_new_user,
new_user_profile,
&new_session.user_workspace,

View File

@ -195,7 +195,7 @@ impl UserManager {
.user_status_callback
.read()
.await
.open_workspace(uid, &user_workspace, &user_profile.auth_type)
.on_workspace_opened(uid, &user_workspace, &user_profile.auth_type)
.await
{
error!("Open workspace failed: {:?}", err);
@ -532,7 +532,7 @@ impl UserManager {
.user_status_callback
.read()
.await
.did_update_storage_limitation(can_write);
.on_storage_permission_updated(can_write);
Ok(workspace_usage)
}
@ -693,7 +693,7 @@ impl UserManager {
.user_status_callback
.read()
.await
.did_update_plans(plans);
.on_subscription_plans_updated(plans);
Ok(())
}
}

View File

@ -3,6 +3,5 @@ pub(crate) mod manager_history_user;
pub(crate) mod manager_user_awareness;
pub(crate) mod manager_user_encryption;
pub(crate) mod manager_user_workspace;
mod user_login_state;
pub use manager::*;

View File

@ -1,11 +0,0 @@
use crate::migrations::AnonUser;
use flowy_user_pub::entities::{AuthResponse, AuthType, UserProfile};
/// recording the intermediate state of the sign-in/sign-up process
#[derive(Clone)]
pub struct UserAuthProcess {
pub user_profile: UserProfile,
pub response: AuthResponse,
pub authenticator: AuthType,
pub migration_user: Option<AnonUser>,
}