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.

chore: update workspace id from nanoid to uuid (#2731)

Nathan.fooo3e3bdb59ae7c
diff --git a/.github/workflows/rust_ci.yaml b/.github/workflows/rust_ci.yaml
index 87ef9792f0..53a1576fcc 100644
--- a/.github/workflows/rust_ci.yaml
+++ b/.github/workflows/rust_ci.yaml
@@ -65,6 +65,10 @@ jobs:
run: |
cargo make --profile development-linux-x86_64 appflowy-core-dev
+ - name: Run rust-lib tests
+ working-directory: frontend/rust-lib
+ run: RUST_LOG=info RUST_BACKTRACE=1 cargo test --no-default-features --features="rev-sqlite"
+
- name: rustfmt rust-lib
run: cargo fmt --all -- --check
working-directory: frontend/rust-lib/
@@ -73,10 +77,6 @@ jobs:
run: cargo clippy --features="rev-sqlite"
working-directory: frontend/rust-lib
- - name: Run rust-lib tests
- working-directory: frontend/rust-lib
- run: RUST_LOG=info cargo test --no-default-features --features="rev-sqlite"
-
- name: rustfmt shared-lib
run: cargo fmt --all -- --check
working-directory: shared-lib
diff --git a/frontend/.vscode/launch.json b/frontend/.vscode/launch.json
index 0d2444c613..cd131cf179 100644
--- a/frontend/.vscode/launch.json
+++ b/frontend/.vscode/launch.json
@@ -13,7 +13,7 @@
"preLaunchTask": "AF: Build Appflowy Core",
"env": {
"RUST_LOG": "trace",
- "RUST_BACKTRACE": 1,
+ "RUST_BACKTRACE": 1
},
"cwd": "${workspaceRoot}/appflowy_flutter"
},
diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.toml b/frontend/appflowy_tauri/src-tauri/Cargo.toml
index 3c8b57e6c5..cd86332439 100644
--- a/frontend/appflowy_tauri/src-tauri/Cargo.toml
+++ b/frontend/appflowy_tauri/src-tauri/Cargo.toml
@@ -34,12 +34,12 @@ default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]
[patch.crates-io]
-collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
-collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
-collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
-collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
-collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
-appflowy-integrate = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
+collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
+collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
+collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
+collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
+collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
+appflowy-integrate = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
#collab = { path = "../../AppFlowy-Collab/collab" }
#collab-folder = { path = "../../AppFlowy-Collab/collab-folder" }
diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock
index 21a1555671..352b6591fc 100644
--- a/frontend/rust-lib/Cargo.lock
+++ b/frontend/rust-lib/Cargo.lock
@@ -85,7 +85,7 @@ checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
[[package]]
name = "appflowy-integrate"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"anyhow",
"collab",
@@ -887,7 +887,7 @@ dependencies = [
[[package]]
name = "collab"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"anyhow",
"bytes",
@@ -905,7 +905,7 @@ dependencies = [
[[package]]
name = "collab-client-ws"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"bytes",
"collab-sync",
@@ -923,7 +923,7 @@ dependencies = [
[[package]]
name = "collab-database"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"anyhow",
"async-trait",
@@ -949,7 +949,7 @@ dependencies = [
[[package]]
name = "collab-derive"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"proc-macro2",
"quote",
@@ -961,7 +961,7 @@ dependencies = [
[[package]]
name = "collab-document"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"anyhow",
"collab",
@@ -978,7 +978,7 @@ dependencies = [
[[package]]
name = "collab-folder"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"anyhow",
"collab",
@@ -997,7 +997,7 @@ dependencies = [
[[package]]
name = "collab-persistence"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"bincode",
"chrono",
@@ -1017,7 +1017,7 @@ dependencies = [
[[package]]
name = "collab-plugins"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"anyhow",
"async-trait",
@@ -1048,7 +1048,7 @@ dependencies = [
[[package]]
name = "collab-sync"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a647d9#a647d922ef432510d6be0abb5f968d9a75dc7011"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
dependencies = [
"bytes",
"collab",
diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.toml
index 117b545839..9168b380eb 100644
--- a/frontend/rust-lib/Cargo.toml
+++ b/frontend/rust-lib/Cargo.toml
@@ -33,11 +33,11 @@ opt-level = 3
incremental = false
[patch.crates-io]
-collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
-collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
-collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
-collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
-appflowy-integrate = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a647d9" }
+collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
+collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
+collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
+collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
+appflowy-integrate = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c611b6" }
#collab = { path = "../AppFlowy-Collab/collab" }
#collab-folder = { path = "../AppFlowy-Collab/collab-folder" }
diff --git a/frontend/rust-lib/flowy-folder2/src/manager.rs b/frontend/rust-lib/flowy-folder2/src/manager.rs
index a943d36c5a..54a7c59a44 100644
--- a/frontend/rust-lib/flowy-folder2/src/manager.rs
+++ b/frontend/rust-lib/flowy-folder2/src/manager.rs
@@ -64,13 +64,27 @@ impl Folder2Manager {
pub async fn get_current_workspace(&self) -> FlowyResult<WorkspacePB> {
self.with_folder(Err(FlowyError::internal()), |folder| {
+ let workspace_pb_from_workspace = |workspace: Workspace, folder: &Folder| {
+ let views = get_workspace_view_pbs(&workspace.id, folder);
+ let workspace: WorkspacePB = (workspace.clone(), views).into();
+ Ok::<WorkspacePB, FlowyError>(workspace)
+ };
+
match folder.get_current_workspace() {
- None => Err(FlowyError::record_not_found().context("Can not find the workspace")),
- Some(workspace) => {
- let views = get_workspace_view_pbs(&workspace.id, folder);
- let workspace: WorkspacePB = (workspace, views).into();
- Ok(workspace)
+ None => {
+ // The current workspace should always exist. If not, try to find the first workspace.
+ // from the folder. Otherwise, return an error.
+ let mut workspaces = folder.workspaces.get_all_workspaces();
+ if workspaces.is_empty() {
+ Err(FlowyError::record_not_found().context("Can not find the workspace"))
+ } else {
+ tracing::error!("Can't find the current workspace, use the first workspace");
+ let workspace = workspaces.remove(0);
+ folder.set_current_workspace(&workspace.id);
+ workspace_pb_from_workspace(workspace, folder)
+ }
},
+ Some(workspace) => workspace_pb_from_workspace(workspace, folder),
}
})
}
@@ -167,6 +181,7 @@ impl Folder2Manager {
.cloud_service
.create_workspace(self.user.user_id()?, &params.name)
.await?;
+
self.with_folder((), |folder| {
folder.workspaces.create_workspace(workspace.clone());
folder.set_current_workspace(&workspace.id);
@@ -187,7 +202,7 @@ impl Folder2Manager {
.ok_or_else(|| {
FlowyError::record_not_found().context("Can't open not existing workspace")
})?;
- folder.set_current_workspace(workspace_id);
+ folder.set_current_workspace(&workspace.id);
Ok::<Workspace, FlowyError>(workspace)
})
}
diff --git a/frontend/rust-lib/flowy-folder2/src/user_default.rs b/frontend/rust-lib/flowy-folder2/src/user_default.rs
index 7543951e38..6f853e004c 100644
--- a/frontend/rust-lib/flowy-folder2/src/user_default.rs
+++ b/frontend/rust-lib/flowy-folder2/src/user_default.rs
@@ -1,7 +1,6 @@
use std::sync::Arc;
use collab_folder::core::{FolderData, RepeatedView, ViewIdentifier, Workspace};
-use nanoid::nanoid;
use tokio::sync::RwLock;
use lib_infra::util::timestamp;
@@ -73,7 +72,7 @@ impl DefaultFolderBuilder {
}
pub fn gen_workspace_id() -> String {
- nanoid!(10)
+ uuid::Uuid::new_v4().to_string()
}
impl From<&ParentChildViews> for ViewPB {
diff --git a/frontend/scripts/makefile/tests.toml b/frontend/scripts/makefile/tests.toml
index cb173e15fd..ad246b3836 100644
--- a/frontend/scripts/makefile/tests.toml
+++ b/frontend/scripts/makefile/tests.toml
@@ -44,7 +44,7 @@ env = { RUST_LOG = "info" }
description = "Run rust-lib unit tests"
script = '''
cd rust-lib
-cargo test --no-default-features --features="rev-sqlite"
+RUST_LOG=info RUST_BACKTRACE=1 cargo test --no-default-features --features="rev-sqlite"
'''
[tasks.shared_lib_unit_test]