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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: remove workspac id in user profile (#5962)
Nathan.fooo8935b7158c53
diff --git a/frontend/appflowy_flutter/integration_test/cloud/user_setting_sync_test.dart b/frontend/appflowy_flutter/integration_test/cloud/user_setting_sync_test.dartindex 8bd9cffc03..d0377908c3 100644--- a/frontend/appflowy_flutter/integration_test/cloud/user_setting_sync_test.dart+++ b/frontend/appflowy_flutter/integration_test/cloud/user_setting_sync_test.dart@@ -47,31 +47,28 @@ void main() {await tester.openSettingsPage(SettingsPage.account);await tester.enterUserName(name);- await tester.tapEscButton();-- // wait 2 seconds for the sync to finishawait tester.pumpAndSettle(const Duration(seconds: 6));- });+ await tester.logout();+ await tester.pumpAndSettle(const Duration(seconds: 2));+ });+ });+ testWidgets('get user icon and name from server', (tester) async {+ await tester.initializeAppFlowy(+ cloudType: AuthenticatorType.appflowyCloudSelfHost,+ email: email,+ );+ await tester.tapGoogleLoginInButton();+ await tester.expectToSeeHomePageWithGetStartedPage();+ await tester.pumpAndSettle();- testWidgets('get user icon and name from server', (tester) async {- await tester.initializeAppFlowy(- cloudType: AuthenticatorType.appflowyCloudSelfHost,- email: email,- );- await tester.tapGoogleLoginInButton();- await tester.expectToSeeHomePageWithGetStartedPage();- await tester.pumpAndSettle();-- await tester.openSettings();- await tester.openSettingsPage(SettingsPage.account);+ await tester.openSettings();+ await tester.openSettingsPage(SettingsPage.account);- // Verify name- final profileSetting =- tester.widget(find.byType(UserProfileSetting)) as UserProfileSetting;+ // Verify name+ final profileSetting =+ tester.widget(find.byType(UserProfileSetting)) as UserProfileSetting;- expect(profileSetting.name, name);- });+ expect(profileSetting.name, name);});-}diff --git a/frontend/appflowy_flutter/integration_test/desktop/database/database_cell_test.dart b/frontend/appflowy_flutter/integration_test/desktop/database/database_cell_test.dartindex cb8338fbb6..66ef6cfd95 100644--- a/frontend/appflowy_flutter/integration_test/desktop/database/database_cell_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/database/database_cell_test.dart@@ -461,22 +461,22 @@ void main() {tester.assertChecklistEditorVisible(visible: true);// create a new task with enter- await tester.createNewChecklistTask(name: "task 0", enter: true);+ await tester.createNewChecklistTask(name: "task 1", enter: true);// assert that the task is displayedtester.assertChecklistTaskInEditor(index: 0,- name: "task 0",+ name: "task 1",isChecked: false,);// update the task's name- await tester.renameChecklistTask(index: 0, name: "task 1");+ await tester.renameChecklistTask(index: 0, name: "task 11");// assert that the task's name is updatedtester.assertChecklistTaskInEditor(index: 0,- name: "task 1",+ name: "task 11",isChecked: false,);diff --git a/frontend/appflowy_flutter/integration_test/shared/settings.dart b/frontend/appflowy_flutter/integration_test/shared/settings.dartindex 9dec3209a4..20193dfd9b 100644--- a/frontend/appflowy_flutter/integration_test/shared/settings.dart+++ b/frontend/appflowy_flutter/integration_test/shared/settings.dart@@ -80,7 +80,7 @@ extension AppFlowySettings on WidgetTester {of: find.byType(UserProfileSetting),matching: find.byFlowySvg(FlowySvgs.edit_s),);- await tap(editUsernameFinder);+ await tap(editUsernameFinder, warnIfMissed: false);await pumpAndSettle();final userNameFinder = find.descendant(diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_on_boarding_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_on_boarding_bloc.dartindex 3a56e93a32..902cb948b8 100644--- a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_on_boarding_bloc.dart+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_on_boarding_bloc.dart@@ -15,8 +15,11 @@ part 'local_ai_on_boarding_bloc.freezed.dart';class LocalAIOnBoardingBlocextends Bloc<LocalAIOnBoardingEvent, LocalAIOnBoardingState> {- LocalAIOnBoardingBloc(this.userProfile)- : super(const LocalAIOnBoardingState()) {+ LocalAIOnBoardingBloc(+ this.userProfile,+ this.member,+ this.workspaceId,+ ) : super(const LocalAIOnBoardingState()) {_userService = UserBackendService(userId: userProfile.id);_successListenable = getIt<SubscriptionSuccessListenable>();_successListenable.addListener(_onPaymentSuccessful);@@ -36,6 +39,8 @@ class LocalAIOnBoardingBloc}final UserProfilePB userProfile;+ final WorkspaceMemberPB member;+ final String workspaceId;late final IUserBackendService _userService;late final SubscriptionSuccessListenable _successListenable;@@ -48,7 +53,7 @@ class LocalAIOnBoardingBlocaddSubscription: (plan) async {emit(state.copyWith(isLoading: true));final result = await _userService.createSubscription(- userProfile.workspaceId,+ workspaceId,plan,);@@ -72,7 +77,7 @@ class LocalAIOnBoardingBloc);},(err) {- Log.error("Failed to get subscription plans: $err");+ Log.warn("Failed to get subscription plans: $err");},);},@@ -86,7 +91,7 @@ class LocalAIOnBoardingBloc}void _loadSubscriptionPlans() {- final payload = UserWorkspaceIdPB()..workspaceId = userProfile.workspaceId;+ final payload = UserWorkspaceIdPB()..workspaceId = workspaceId;UserEventGetWorkspaceSubscriptionInfo(payload).send().then((result) {if (!isClosed) {add(LocalAIOnBoardingEvent.didGetSubscriptionPlans(result));diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/settings_ai_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/settings_ai_bloc.dartindex fd07db4d48..af0b390ebd 100644--- a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/settings_ai_bloc.dart+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/settings_ai_bloc.dart@@ -11,8 +11,11 @@ import 'package:freezed_annotation/freezed_annotation.dart';part 'settings_ai_bloc.freezed.dart';class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {- SettingsAIBloc(this.userProfile, WorkspaceMemberPB? member)- : _userListener = UserListener(userProfile: userProfile),+ SettingsAIBloc(+ this.userProfile,+ this.workspaceId,+ WorkspaceMemberPB? member,+ ) : _userListener = UserListener(userProfile: userProfile),_userService = UserBackendService(userId: userProfile.id),super(SettingsAIState(userProfile: userProfile, member: member)) {_dispatch();@@ -36,6 +39,7 @@ class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {final UserListener _userListener;final UserProfilePB userProfile;final UserBackendService _userService;+ final String workspaceId;@overrideFuture<void> close() async {@@ -92,7 +96,7 @@ class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {AIModelPB? model,}) {final payload = UpdateUserWorkspaceSettingPB(- workspaceId: userProfile.workspaceId,+ workspaceId: workspaceId,);if (disableSearchIndexing != null) {payload.disableSearchIndexing = disableSearchIndexing;@@ -112,7 +116,7 @@ class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {);void _loadUserWorkspaceSetting() {- final payload = UserWorkspaceIdPB(workspaceId: userProfile.workspaceId);+ final payload = UserWorkspaceIdPB(workspaceId: workspaceId);UserEventGetWorkspaceSetting(payload).send().then((result) {result.fold((settings) {if (!isClosed) {@@ -133,7 +137,8 @@ class SettingsAIEvent with _$SettingsAIEvent {) = _DidLoadWorkspaceSetting;const factory SettingsAIEvent.toggleAISearch() = _toggleAISearch;- const factory SettingsAIEvent.refreshMember(WorkspaceMemberPB member) = _RefreshMember;+ const factory SettingsAIEvent.refreshMember(WorkspaceMemberPB member) =+ _RefreshMember;const factory SettingsAIEvent.selectModel(AIModelPB model) = _SelectAIModel;diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/settings_ai_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/settings_ai_view.dartindex c5e160fb03..48319e1b4a 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/settings_ai_view.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/settings_ai_view.dart@@ -6,7 +6,6 @@ import 'package:appflowy/workspace/presentation/settings/pages/setting_ai_view/mimport 'package:appflowy/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart';import 'package:flowy_infra/theme_extension.dart';import 'package:flowy_infra_ui/widget/spacing.dart';-import 'package:flutter/foundation.dart';import 'package:flutter/material.dart';import 'package:appflowy/generated/locale_keys.g.dart';@@ -40,15 +39,17 @@ class SettingsAIView extends StatelessWidget {super.key,required this.userProfile,required this.member,+ required this.workspaceId,});final UserProfilePB userProfile;final WorkspaceMemberPB? member;+ final String workspaceId;@overrideWidget build(BuildContext context) {return BlocProvider<SettingsAIBloc>(- create: (_) => SettingsAIBloc(userProfile, member)+ create: (_) => SettingsAIBloc(userProfile, workspaceId, member)..add(const SettingsAIEvent.started()),child: BlocBuilder<SettingsAIBloc, SettingsAIState>(builder: (context, state) {@@ -63,6 +64,7 @@ class SettingsAIView extends StatelessWidget {_LocalAIOnBoarding(userProfile: userProfile,member: state.member!,+ workspaceId: workspaceId,),);}@@ -127,9 +129,11 @@ class _LocalAIOnBoarding extends StatelessWidget {const _LocalAIOnBoarding({required this.userProfile,required this.member,+ required this.workspaceId,});final UserProfilePB userProfile;final WorkspaceMemberPB member;+ final String workspaceId;@overrideWidget build(BuildContext context) {@@ -137,12 +141,13 @@ class _LocalAIOnBoarding extends StatelessWidget {return BillingGateGuard(builder: (context) {return BlocProvider(- create: (context) => LocalAIOnBoardingBloc(userProfile)- ..add(const LocalAIOnBoardingEvent.started()),+ create: (context) =>+ LocalAIOnBoardingBloc(userProfile, member, workspaceId)+ ..add(const LocalAIOnBoardingEvent.started()),child: BlocBuilder<LocalAIOnBoardingBloc, LocalAIOnBoardingState>(builder: (context, state) {// Show the local AI settings if the user has purchased the AI Local plan- if (kDebugMode || state.isPurchaseAILocal) {+ if (state.isPurchaseAILocal) {return const LocalAISetting();} else {if (member.role.isOwner) {diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dartindex 5a3905ed21..c633aa3577 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart@@ -120,7 +120,11 @@ class SettingsDialog extends StatelessWidget {return const SettingsShortcutsView();case SettingsPage.ai:if (user.authenticator == AuthenticatorPB.AppFlowyCloud) {- return SettingsAIView(userProfile: user, member: member);+ return SettingsAIView(+ userProfile: user,+ member: member,+ workspaceId: workspaceId,+ );} else {return const AIFeatureOnlySupportedWhenUsingAppFlowyCloud();}diff --git a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/member_test.rs b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/member_test.rsindex 9eba50b404..ca962ae726 100644--- a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/member_test.rs+++ b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/member_test.rs@@ -38,19 +38,18 @@ async fn af_cloud_add_workspace_member_test() {user_localhost_af_cloud().await;let test_1 = EventIntegrationTest::new().await;let user_1 = test_1.af_cloud_sign_up().await;+ let workspace_id_1 = test_1.get_current_workspace().await.id;let test_2 = EventIntegrationTest::new().await;let user_2 = test_2.af_cloud_sign_up().await;- let members = test_1.get_workspace_members(&user_1.workspace_id).await;+ let members = test_1.get_workspace_members(&workspace_id_1).await;assert_eq!(members.len(), 1);assert_eq!(members[0].email, user_1.email);- test_1- .add_workspace_member(&user_1.workspace_id, &test_2)- .await;+ test_1.add_workspace_member(&workspace_id_1, &test_2).await;- let members = test_1.get_workspace_members(&user_1.workspace_id).await;+ let members = test_1.get_workspace_members(&workspace_id_1).await;assert_eq!(members.len(), 2);assert_eq!(members[0].email, user_1.email);assert_eq!(members[1].email, user_2.email);@@ -61,19 +60,18 @@ async fn af_cloud_delete_workspace_member_test() {user_localhost_af_cloud().await;let test_1 = EventIntegrationTest::new().await;let user_1 = test_1.af_cloud_sign_up().await;+ let workspace_id_1 = test_1.get_current_workspace().await.id;let test_2 = EventIntegrationTest::new().await;let user_2 = test_2.af_cloud_sign_up().await;- test_1- .add_workspace_member(&user_1.workspace_id, &test_2)- .await;+ test_1.add_workspace_member(&workspace_id_1, &test_2).await;test_1- .delete_workspace_member(&user_1.workspace_id, &user_2.email)+ .delete_workspace_member(&workspace_id_1, &user_2.email).await;- let members = test_1.get_workspace_members(&user_1.workspace_id).await;+ let members = test_1.get_workspace_members(&workspace_id_1).await;assert_eq!(members.len(), 1);assert_eq!(members[0].email, user_1.email);}@@ -82,21 +80,20 @@ async fn af_cloud_delete_workspace_member_test() {async fn af_cloud_leave_workspace_test() {user_localhost_af_cloud().await;let test_1 = EventIntegrationTest::new().await;- let user_1 = test_1.af_cloud_sign_up().await;+ test_1.af_cloud_sign_up().await;+ let workspace_id_1 = test_1.get_current_workspace().await.id;let test_2 = EventIntegrationTest::new().await;let user_2 = test_2.af_cloud_sign_up().await;- test_1- .add_workspace_member(&user_1.workspace_id, &test_2)- .await;+ test_1.add_workspace_member(&workspace_id_1, &test_2).await;// test_2 should have 2 workspacelet workspaces = get_synced_workspaces(&test_2, user_2.id).await;assert_eq!(workspaces.len(), 2);// user_2 leaves the workspace- test_2.leave_workspace(&user_1.workspace_id).await;+ test_2.leave_workspace(&workspace_id_1).await;// user_2 should have 1 workspacelet workspaces = get_synced_workspaces(&test_2, user_2.id).await;diff --git a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/workspace_test.rs b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/workspace_test.rsindex c35224ea99..03c0930f74 100644--- a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/workspace_test.rs+++ b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/workspace_test.rs@@ -163,9 +163,6 @@ async fn af_cloud_different_open_same_workspace_test() {let owner_profile = test_runner.af_cloud_sign_up().await;let shared_workspace_id = test_runner.get_current_workspace().await.id.clone();- // Verify that the workspace ID from the profile matches the current session's workspace ID.- assert_eq!(shared_workspace_id, owner_profile.workspace_id);-// Define the number of additional clientslet num_clients = 5;let mut clients = Vec::new();@@ -183,7 +180,7 @@ async fn af_cloud_different_open_same_workspace_test() {}test_runner- .add_workspace_member(&owner_profile.workspace_id, &client)+ .add_workspace_member(&shared_workspace_id, &client).await;clients.push((client, client_profile));}diff --git a/frontend/rust-lib/event-integration-test/tests/user/local_test/user_profile_test.rs b/frontend/rust-lib/event-integration-test/tests/user/local_test/user_profile_test.rsindex 798054dccf..00df14e8e1 100644--- a/frontend/rust-lib/event-integration-test/tests/user/local_test/user_profile_test.rs+++ b/frontend/rust-lib/event-integration-test/tests/user/local_test/user_profile_test.rs@@ -26,7 +26,6 @@ async fn anon_user_profile_get() {assert_eq!(user_profile.id, user.id);assert_eq!(user_profile.openai_key, user.openai_key);assert_eq!(user_profile.stability_ai_key, user.stability_ai_key);- assert_eq!(user_profile.workspace_id, user.workspace_id);assert_eq!(user_profile.authenticator, AuthenticatorPB::Local);}diff --git a/frontend/rust-lib/flowy-ai/src/chat.rs b/frontend/rust-lib/flowy-ai/src/chat.rsindex 1d6af09503..494a8f3980 100644--- a/frontend/rust-lib/flowy-ai/src/chat.rs+++ b/frontend/rust-lib/flowy-ai/src/chat.rs@@ -351,7 +351,7 @@ impl Chat {{Ok(resp) => {// Save chat messages to local disk- if let Err(err) = save_chat_message(+ if let Err(err) = save_chat_message_disk(user_service.sqlite_connection(uid)?,&chat_id,resp.messages.clone(),@@ -503,7 +503,7 @@ impl Chat {}}-fn save_chat_message(+fn save_chat_message_disk(conn: DBConnection,chat_id: &str,messages: Vec<ChatMessage>,@@ -565,7 +565,7 @@ pub(crate) fn save_and_notify_message(message: ChatMessage,) -> Result<(), FlowyError> {trace!("[Chat] save answer: answer={:?}", message);- save_chat_message(+ save_chat_message_disk(user_service.sqlite_connection(uid)?,chat_id,vec![message.clone()],diff --git a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs b/frontend/rust-lib/flowy-user/src/entities/user_profile.rsindex a637cef6d2..ffb22b976f 100644--- a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs+++ b/frontend/rust-lib/flowy-user/src/entities/user_profile.rs@@ -53,12 +53,9 @@ pub struct UserProfilePB {pub encryption_type: EncryptionTypePB,#[pb(index = 10)]- pub workspace_id: String,-- #[pb(index = 11)]pub stability_ai_key: String,- #[pb(index = 12)]+ #[pb(index = 11)]pub ai_model: AIModelPB,}@@ -90,7 +87,6 @@ impl From<UserProfile> for UserProfilePB {authenticator: user_profile.authenticator.into(),encryption_sign,encryption_type: encryption_ty,- workspace_id: user_profile.workspace_id,stability_ai_key: user_profile.stability_ai_key,ai_model: AIModelPB::from_str(&user_profile.ai_model).unwrap_or_default(),}