Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: added delete account functionality (#6167)

Zacka6cce62b06bf
diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock
index 7130ab9809..14776cd9bb 100644
--- a/frontend/rust-lib/Cargo.lock
+++ b/frontend/rust-lib/Cargo.lock
@@ -163,7 +163,7 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "app-error"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"anyhow",
"bincode",
@@ -183,7 +183,7 @@ dependencies = [
[[package]]
name = "appflowy-ai-client"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"anyhow",
"bytes",
@@ -729,7 +729,7 @@ dependencies = [
[[package]]
name = "client-api"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"again",
"anyhow",
@@ -780,7 +780,7 @@ dependencies = [
[[package]]
name = "client-api-entity"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"collab-entity",
"collab-rt-entity",
@@ -793,7 +793,7 @@ dependencies = [
[[package]]
name = "client-websocket"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"futures-channel",
"futures-util",
@@ -1010,7 +1010,7 @@ dependencies = [
[[package]]
name = "collab-rt-entity"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"anyhow",
"bincode",
@@ -1035,7 +1035,7 @@ dependencies = [
[[package]]
name = "collab-rt-protocol"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"anyhow",
"async-trait",
@@ -1395,7 +1395,7 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
[[package]]
name = "database-entity"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"anyhow",
"app-error",
@@ -2795,7 +2795,7 @@ dependencies = [
[[package]]
name = "gotrue"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"anyhow",
"futures-util",
@@ -2812,7 +2812,7 @@ dependencies = [
[[package]]
name = "gotrue-entity"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"anyhow",
"app-error",
@@ -3177,7 +3177,7 @@ dependencies = [
[[package]]
name = "infra"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"anyhow",
"bytes",
@@ -5377,7 +5377,7 @@ dependencies = [
[[package]]
name = "shared-entity"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52782033948b7d243693ca159ea519d53458c8a6#52782033948b7d243693ca159ea519d53458c8a6"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=14a1382d1c4b77ba16fee3ab867e6bfded85828e#14a1382d1c4b77ba16fee3ab867e6bfded85828e"
dependencies = [
"anyhow",
"app-error",
@@ -5395,6 +5395,7 @@ dependencies = [
"serde_json",
"serde_repr",
"thiserror",
+ "tracing",
"uuid",
]
diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.toml
index 6f49a2fd39..319e057904 100644
--- a/frontend/rust-lib/Cargo.toml
+++ b/frontend/rust-lib/Cargo.toml
@@ -100,8 +100,8 @@ dashmap = "6.0.1"
# Run the script.add_workspace_members:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
-client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "52782033948b7d243693ca159ea519d53458c8a6" }
-client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "52782033948b7d243693ca159ea519d53458c8a6" }
+client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "14a1382d1c4b77ba16fee3ab867e6bfded85828e" }
+client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "14a1382d1c4b77ba16fee3ab867e6bfded85828e" }
[profile.dev]
opt-level = 0
diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
index a1dafe578b..10cfaa5c71 100644
--- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
+++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
@@ -86,6 +86,12 @@ where
Ok(())
}
+ async fn delete_account(&self) -> Result<(), FlowyError> {
+ let client = self.server.try_get_client()?;
+ client.delete_user().await?;
+ Ok(())
+ }
+
async fn generate_sign_in_url_with_email(&self, email: &str) -> Result<String, FlowyError> {
let email = email.to_string();
let try_get_client = self.server.try_get_client();
diff --git a/frontend/rust-lib/flowy-user-pub/src/cloud.rs b/frontend/rust-lib/flowy-user-pub/src/cloud.rs
index f20d66edbe..d68bf3f809 100644
--- a/frontend/rust-lib/flowy-user-pub/src/cloud.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/cloud.rs
@@ -133,6 +133,11 @@ pub trait UserCloudService: Send + Sync + 'static {
/// Sign out an account
async fn sign_out(&self, token: Option<String>) -> Result<(), FlowyError>;
+ /// Delete an account and all the data associated with the account
+ async fn delete_account(&self) -> Result<(), FlowyError> {
+ Err(FlowyError::not_support())
+ }
+
/// Generate a sign in url for the user with the given email
/// Currently, only use the admin client for testing
async fn generate_sign_in_url_with_email(&self, email: &str) -> Result<String, FlowyError>;
diff --git a/frontend/rust-lib/flowy-user/src/event_handler.rs b/frontend/rust-lib/flowy-user/src/event_handler.rs
index c2e0c0d917..a941c94429 100644
--- a/frontend/rust-lib/flowy-user/src/event_handler.rs
+++ b/frontend/rust-lib/flowy-user/src/event_handler.rs
@@ -138,6 +138,15 @@ pub async fn sign_out_handler(manager: AFPluginState<Weak<UserManager>>) -> Resu
Ok(())
}
+#[tracing::instrument(level = "debug", skip(manager))]
+pub async fn delete_account_handler(
+ manager: AFPluginState<Weak<UserManager>>,
+) -> Result<(), FlowyError> {
+ let manager = upgrade_manager(manager)?;
+ manager.delete_account().await?;
+ Ok(())
+}
+
#[tracing::instrument(level = "debug", skip(data, manager))]
pub async fn update_user_profile_handler(
data: AFPluginData<UpdateUserProfilePayloadPB>,
diff --git a/frontend/rust-lib/flowy-user/src/event_map.rs b/frontend/rust-lib/flowy-user/src/event_map.rs
index 844d640415..0807b46170 100644
--- a/frontend/rust-lib/flowy-user/src/event_map.rs
+++ b/frontend/rust-lib/flowy-user/src/event_map.rs
@@ -28,6 +28,7 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
.event(UserEvent::InitUser, init_user_handler)
.event(UserEvent::GetUserProfile, get_user_profile_handler)
.event(UserEvent::SignOut, sign_out_handler)
+ .event(UserEvent::DeleteAccount, delete_account_handler)
.event(UserEvent::UpdateUserProfile, update_user_profile_handler)
.event(UserEvent::SetAppearanceSetting, set_appearance_setting)
.event(UserEvent::GetAppearanceSetting, get_appearance_setting)
@@ -274,6 +275,9 @@ pub enum UserEvent {
#[event(input = "SuccessWorkspaceSubscriptionPB")]
NotifyDidSwitchPlan = 63,
+
+ #[event()]
+ DeleteAccount = 64,
}
#[async_trait]
diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
index 6f198de1ef..5adfced1d2 100644
--- a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
@@ -501,6 +501,16 @@ impl UserManager {
Ok(())
}
+ #[tracing::instrument(level = "info", skip(self))]
+ pub async fn delete_account(&self) -> Result<(), FlowyError> {
+ self
+ .cloud_services
+ .get_user_service()?
+ .delete_account()
+ .await?;
+ Ok(())
+ }
+
/// Updates the user's profile with the given parameters.
///
/// This function modifies the user's profile based on the provided update parameters. After updating, it