mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 22:57:12 -04:00
chore: replace auth type with workspace type
This commit is contained in:
parent
c35609b1c3
commit
da47c11070
45 changed files with 280 additions and 184 deletions
|
@ -203,7 +203,7 @@ class MobileViewBottomSheetBody extends StatelessWidget {
|
|||
final userProfile = context.read<MobileViewPageBloc>().state.userProfilePB;
|
||||
// the publish feature is only available for AppFlowy Cloud
|
||||
if (userProfile == null ||
|
||||
userProfile.workspaceAuthType != AuthTypePB.Server) {
|
||||
userProfile.workspaceType != WorkspaceTypePB.ServerW) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ class _MobileWorkspace extends StatelessWidget {
|
|||
context.read<UserWorkspaceBloc>().add(
|
||||
UserWorkspaceEvent.openWorkspace(
|
||||
workspace.workspaceId,
|
||||
workspace.workspaceAuthType,
|
||||
workspace.workspaceType,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -48,7 +48,7 @@ class HomePageSettingsPopupMenu extends StatelessWidget {
|
|||
text: LocaleKeys.settings_popupMenuItem_settings.tr(),
|
||||
),
|
||||
// only show the member items in cloud mode
|
||||
if (userProfile.workspaceAuthType == AuthTypePB.Server) ...[
|
||||
if (userProfile.workspaceType == WorkspaceTypePB.ServerW) ...[
|
||||
const PopupMenuDivider(height: 0.5),
|
||||
_buildItem(
|
||||
value: _MobileSettingsPopupMenuItem.members,
|
||||
|
|
|
@ -164,7 +164,7 @@ class _MobileSpaceTabState extends State<MobileSpaceTab>
|
|||
return const MobileRecentSpace();
|
||||
case MobileSpaceTabType.spaces:
|
||||
final showAIFloatingButton =
|
||||
widget.userProfile.workspaceAuthType == AuthTypePB.Server;
|
||||
widget.userProfile.workspaceType == WorkspaceTypePB.ServerW;
|
||||
return Stack(
|
||||
children: [
|
||||
MobileHomeSpace(userProfile: widget.userProfile),
|
||||
|
|
|
@ -123,7 +123,7 @@ class _CreateWorkspaceButton extends StatelessWidget {
|
|||
context.read<UserWorkspaceBloc>().add(
|
||||
UserWorkspaceEvent.createWorkspace(
|
||||
name,
|
||||
AuthTypePB.Server,
|
||||
WorkspaceTypePB.ServerW,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -89,7 +89,7 @@ class MobileSearchPage extends StatelessWidget {
|
|||
final WorkspaceLatestPB workspaceLatestPB;
|
||||
|
||||
bool get enableShowAISearch =>
|
||||
userProfile.workspaceAuthType == AuthTypePB.Server;
|
||||
userProfile.workspaceType == WorkspaceTypePB.ServerW;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -31,7 +31,7 @@ class DatabaseSyncBloc extends Bloc<DatabaseSyncEvent, DatabaseSyncBlocState> {
|
|||
emit(
|
||||
state.copyWith(
|
||||
shouldShowIndicator:
|
||||
userProfile?.workspaceAuthType == AuthTypePB.Server &&
|
||||
userProfile?.workspaceType == WorkspaceTypePB.ServerW &&
|
||||
databaseId != null,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -69,8 +69,8 @@ class RowBanner extends StatefulWidget {
|
|||
class _RowBannerState extends State<RowBanner> {
|
||||
final _isHovering = ValueNotifier(false);
|
||||
late final isLocalMode =
|
||||
(widget.userProfile?.workspaceAuthType ?? AuthTypePB.Local) ==
|
||||
AuthTypePB.Local;
|
||||
(widget.userProfile?.workspaceType ?? WorkspaceTypePB.LocalW) ==
|
||||
WorkspaceTypePB.LocalW;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
|
|
|
@ -101,8 +101,8 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {
|
|||
|
||||
bool get isLocalMode {
|
||||
final userProfilePB = state.userProfilePB;
|
||||
final type = userProfilePB?.workspaceAuthType ?? AuthTypePB.Local;
|
||||
return type == AuthTypePB.Local;
|
||||
final type = userProfilePB?.workspaceType ?? WorkspaceTypePB.LocalW;
|
||||
return type == WorkspaceTypePB.LocalW;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -32,7 +32,7 @@ class DocumentCollaboratorsBloc
|
|||
emit(
|
||||
state.copyWith(
|
||||
shouldShowIndicator:
|
||||
userProfile?.workspaceAuthType == AuthTypePB.Server,
|
||||
userProfile?.workspaceType == WorkspaceTypePB.ServerW,
|
||||
),
|
||||
);
|
||||
final deviceId = ApplicationInfo.deviceId;
|
||||
|
|
|
@ -31,7 +31,7 @@ class DocumentSyncBloc extends Bloc<DocumentSyncEvent, DocumentSyncBlocState> {
|
|||
emit(
|
||||
state.copyWith(
|
||||
shouldShowIndicator:
|
||||
userProfile?.workspaceAuthType == AuthTypePB.Server,
|
||||
userProfile?.workspaceType == WorkspaceTypePB.ServerW,
|
||||
),
|
||||
);
|
||||
_syncStateListener.start(
|
||||
|
|
|
@ -184,8 +184,8 @@ Future<void> insertLocalFile(
|
|||
final fileType = file.fileType.toMediaFileTypePB();
|
||||
|
||||
// Check upload type
|
||||
final isLocalMode =
|
||||
(userProfile?.workspaceAuthType ?? AuthTypePB.Local) == AuthTypePB.Local;
|
||||
final isLocalMode = (userProfile?.workspaceType ?? WorkspaceTypePB.LocalW) ==
|
||||
WorkspaceTypePB.LocalW;
|
||||
|
||||
String? path;
|
||||
String? errorMsg;
|
||||
|
@ -229,8 +229,8 @@ Future<void> insertLocalFiles(
|
|||
if (files.every((f) => f.path.isEmpty)) return;
|
||||
|
||||
// Check upload type
|
||||
final isLocalMode =
|
||||
(userProfile?.workspaceAuthType ?? AuthTypePB.Local) == AuthTypePB.Local;
|
||||
final isLocalMode = (userProfile?.workspaceType ?? WorkspaceTypePB.LocalW) ==
|
||||
WorkspaceTypePB.LocalW;
|
||||
|
||||
for (final file in files) {
|
||||
final fileType = file.fileType.toMediaFileTypePB();
|
||||
|
|
|
@ -226,7 +226,7 @@ class PageStyleCoverImage extends StatelessWidget {
|
|||
(f) => null,
|
||||
);
|
||||
final isAppFlowyCloud =
|
||||
userProfile?.workspaceAuthType == AuthTypePB.Server;
|
||||
userProfile?.workspaceType == WorkspaceTypePB.ServerW;
|
||||
final PageStyleCoverImageType type;
|
||||
if (!isAppFlowyCloud) {
|
||||
result = await saveImageToLocalStorage(path);
|
||||
|
|
|
@ -193,7 +193,7 @@ class ShareBloc extends Bloc<ShareEvent, ShareState> {
|
|||
Future<void> _updatePublishStatus(Emitter<ShareState> emit) async {
|
||||
final publishInfo = await ViewBackendService.getPublishInfo(view);
|
||||
final enablePublish = await UserBackendService.getCurrentUserProfile().fold(
|
||||
(v) => v.workspaceAuthType == AuthTypePB.Server,
|
||||
(v) => v.workspaceType == WorkspaceTypePB.ServerW,
|
||||
(p) => false,
|
||||
);
|
||||
|
||||
|
|
|
@ -294,8 +294,9 @@ class _IconUploaderState extends State<IconUploader> {
|
|||
(userProfile) => userProfile,
|
||||
(l) => null,
|
||||
);
|
||||
final isLocalMode = (userProfile?.workspaceAuthType ?? AuthTypePB.Local) ==
|
||||
AuthTypePB.Local;
|
||||
final isLocalMode =
|
||||
(userProfile?.workspaceType ?? WorkspaceTypePB.LocalW) ==
|
||||
WorkspaceTypePB.LocalW;
|
||||
if (isLocalMode) {
|
||||
result = await pickedImages.first.saveToLocal();
|
||||
} else {
|
||||
|
|
|
@ -123,11 +123,11 @@ class UserBackendService implements IUserBackendService {
|
|||
|
||||
Future<FlowyResult<void, FlowyError>> openWorkspace(
|
||||
String workspaceId,
|
||||
AuthTypePB authType,
|
||||
WorkspaceTypePB workspaceType,
|
||||
) {
|
||||
final payload = OpenUserWorkspacePB()
|
||||
..workspaceId = workspaceId
|
||||
..workspaceAuthType = authType;
|
||||
..workspaceType = workspaceType;
|
||||
return UserEventOpenWorkspace(payload).send();
|
||||
}
|
||||
|
||||
|
@ -142,11 +142,11 @@ class UserBackendService implements IUserBackendService {
|
|||
|
||||
Future<FlowyResult<UserWorkspacePB, FlowyError>> createUserWorkspace(
|
||||
String name,
|
||||
AuthTypePB authType,
|
||||
WorkspaceTypePB workspaceType,
|
||||
) {
|
||||
final request = CreateWorkspacePB.create()
|
||||
..name = name
|
||||
..authType = authType;
|
||||
..workspaceType = workspaceType;
|
||||
return UserEventCreateWorkspace(request).send();
|
||||
}
|
||||
|
||||
|
|
|
@ -90,8 +90,8 @@ class SettingsDialogBloc
|
|||
AFRolePB? currentWorkspaceMemberRole,
|
||||
]) async {
|
||||
if ([
|
||||
AuthTypePB.Local,
|
||||
].contains(userProfile.workspaceAuthType)) {
|
||||
WorkspaceTypePB.LocalW,
|
||||
].contains(userProfile.workspaceType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
Log.info('init open workspace: ${currentWorkspace.workspaceId}');
|
||||
await _userService.openWorkspace(
|
||||
currentWorkspace.workspaceId,
|
||||
currentWorkspace.workspaceAuthType,
|
||||
currentWorkspace.workspaceType,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -97,12 +97,12 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
add(
|
||||
OpenWorkspace(
|
||||
currentWorkspace.workspaceId,
|
||||
currentWorkspace.workspaceAuthType,
|
||||
currentWorkspace.workspaceType,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
createWorkspace: (name, authType) async {
|
||||
createWorkspace: (name, workspaceType) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
actionResult: const UserWorkspaceActionResult(
|
||||
|
@ -114,7 +114,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
);
|
||||
final result = await _userService.createUserWorkspace(
|
||||
name,
|
||||
authType,
|
||||
workspaceType,
|
||||
);
|
||||
final workspaces = result.fold(
|
||||
(s) => [...state.workspaces, s],
|
||||
|
@ -137,7 +137,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
add(
|
||||
OpenWorkspace(
|
||||
s.workspaceId,
|
||||
s.workspaceAuthType,
|
||||
s.workspaceType,
|
||||
),
|
||||
);
|
||||
})
|
||||
|
@ -195,7 +195,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
add(
|
||||
OpenWorkspace(
|
||||
workspaces.first.workspaceId,
|
||||
workspaces.first.workspaceAuthType,
|
||||
workspaces.first.workspaceType,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
add(
|
||||
OpenWorkspace(
|
||||
workspaces.first.workspaceId,
|
||||
workspaces.first.workspaceAuthType,
|
||||
workspaces.first.workspaceType,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
),
|
||||
);
|
||||
},
|
||||
openWorkspace: (workspaceId, authType) async {
|
||||
openWorkspace: (workspaceId, workspaceType) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
actionResult: const UserWorkspaceActionResult(
|
||||
|
@ -236,7 +236,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
);
|
||||
final result = await _userService.openWorkspace(
|
||||
workspaceId,
|
||||
authType,
|
||||
workspaceType,
|
||||
);
|
||||
final currentWorkspace = result.fold(
|
||||
(s) => state.workspaces.firstWhereOrNull(
|
||||
|
@ -374,7 +374,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
add(
|
||||
OpenWorkspace(
|
||||
workspaces.first.workspaceId,
|
||||
workspaces.first.workspaceAuthType,
|
||||
workspaces.first.workspaceType,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -481,17 +481,17 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
|||
@freezed
|
||||
class UserWorkspaceEvent with _$UserWorkspaceEvent {
|
||||
const factory UserWorkspaceEvent.initial() = Initial;
|
||||
const factory UserWorkspaceEvent.fetchWorkspaces({String? initialWorkspaceId}) =
|
||||
FetchWorkspaces;
|
||||
const factory UserWorkspaceEvent.fetchWorkspaces(
|
||||
{String? initialWorkspaceId}) = FetchWorkspaces;
|
||||
const factory UserWorkspaceEvent.createWorkspace(
|
||||
String name,
|
||||
AuthTypePB authType,
|
||||
WorkspaceTypePB workspaceType,
|
||||
) = CreateWorkspace;
|
||||
const factory UserWorkspaceEvent.deleteWorkspace(String workspaceId) =
|
||||
DeleteWorkspace;
|
||||
const factory UserWorkspaceEvent.openWorkspace(
|
||||
String workspaceId,
|
||||
AuthTypePB authType,
|
||||
WorkspaceTypePB workspaceType,
|
||||
) = OpenWorkspace;
|
||||
const factory UserWorkspaceEvent.renameWorkspace(
|
||||
String workspaceId,
|
||||
|
|
|
@ -66,7 +66,7 @@ class WorkspaceBloc extends Bloc<WorkspaceEvent, WorkspaceState> {
|
|||
Emitter<WorkspaceState> emit,
|
||||
) async {
|
||||
final result =
|
||||
await userService.createUserWorkspace(name, AuthTypePB.Server);
|
||||
await userService.createUserWorkspace(name, WorkspaceTypePB.ServerW);
|
||||
emit(
|
||||
result.fold(
|
||||
(workspace) {
|
||||
|
|
|
@ -309,7 +309,7 @@ class _WorkspaceInfo extends StatelessWidget {
|
|||
context.read<UserWorkspaceBloc>().add(
|
||||
UserWorkspaceEvent.openWorkspace(
|
||||
workspace.workspaceId,
|
||||
workspace.workspaceAuthType,
|
||||
workspace.workspaceType,
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -389,7 +389,7 @@ class _CreateWorkspaceButton extends StatelessWidget {
|
|||
workspaceBloc.add(
|
||||
UserWorkspaceEvent.createWorkspace(
|
||||
name,
|
||||
AuthTypePB.Server,
|
||||
WorkspaceTypePB.ServerW,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -257,7 +257,7 @@ class _SidebarWorkspaceState extends State<SidebarWorkspace> {
|
|||
context.read<UserWorkspaceBloc>().add(
|
||||
UserWorkspaceEvent.openWorkspace(
|
||||
workspaceId,
|
||||
openWorkspace.workspaceAuthType,
|
||||
openWorkspace.workspaceType,
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ class ViewMoreActionTypeWrapper extends CustomActionCell {
|
|||
) {
|
||||
final userProfile = context.read<SpaceBloc>().userProfile;
|
||||
// move to feature doesn't support in local mode
|
||||
if (userProfile.workspaceAuthType != AuthTypePB.Server) {
|
||||
if (userProfile.workspaceType != WorkspaceTypePB.ServerW) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return BlocProvider.value(
|
||||
|
|
|
@ -88,7 +88,7 @@ class SettingsWorkspaceView extends StatelessWidget {
|
|||
autoSeparate: false,
|
||||
children: [
|
||||
// We don't allow changing workspace name/icon for local/offline
|
||||
if (userProfile.workspaceAuthType != AuthTypePB.Local) ...[
|
||||
if (userProfile.workspaceType != WorkspaceTypePB.LocalW) ...[
|
||||
SettingsCategory(
|
||||
title: LocaleKeys.settings_workspacePage_workspaceName_title
|
||||
.tr(),
|
||||
|
@ -180,7 +180,7 @@ class SettingsWorkspaceView extends StatelessWidget {
|
|||
),
|
||||
const SettingsCategorySpacer(),
|
||||
|
||||
if (userProfile.workspaceAuthType != AuthTypePB.Local) ...[
|
||||
if (userProfile.workspaceType != WorkspaceTypePB.LocalW) ...[
|
||||
SingleSettingAction(
|
||||
label: LocaleKeys.settings_workspacePage_manageWorkspace_title
|
||||
.tr(),
|
||||
|
|
|
@ -146,7 +146,7 @@ class SettingsDialog extends StatelessWidget {
|
|||
case SettingsPage.shortcuts:
|
||||
return const SettingsShortcutsView();
|
||||
case SettingsPage.ai:
|
||||
if (user.workspaceAuthType == AuthTypePB.Server) {
|
||||
if (user.workspaceType == WorkspaceTypePB.ServerW) {
|
||||
return SettingsAIView(
|
||||
key: ValueKey(workspaceId),
|
||||
userProfile: user,
|
||||
|
|
|
@ -63,7 +63,7 @@ class SettingsMenu extends StatelessWidget {
|
|||
changeSelectedPage: changeSelectedPage,
|
||||
),
|
||||
if (FeatureFlag.membersSettings.isOn &&
|
||||
userProfile.workspaceAuthType == AuthTypePB.Server)
|
||||
userProfile.workspaceType == WorkspaceTypePB.ServerW)
|
||||
SettingsMenuElement(
|
||||
page: SettingsPage.member,
|
||||
selectedPage: currentPage,
|
||||
|
@ -109,7 +109,7 @@ class SettingsMenu extends StatelessWidget {
|
|||
),
|
||||
changeSelectedPage: changeSelectedPage,
|
||||
),
|
||||
if (userProfile.workspaceAuthType == AuthTypePB.Server)
|
||||
if (userProfile.workspaceType == WorkspaceTypePB.ServerW)
|
||||
SettingsMenuElement(
|
||||
page: SettingsPage.sites,
|
||||
selectedPage: currentPage,
|
||||
|
|
|
@ -96,7 +96,7 @@ class _MoreViewActionsState extends State<MoreViewActions> {
|
|||
return BlocBuilder<SpaceBloc, SpaceState>(
|
||||
builder: (context, state) {
|
||||
if (state.spaces.isEmpty &&
|
||||
userProfile.workspaceAuthType == AuthTypePB.Server) {
|
||||
userProfile.workspaceType == WorkspaceTypePB.ServerW) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ use flowy_user::entities::{
|
|||
AuthTypePB, ChangeWorkspaceIconPB, CloudSettingPB, CreateWorkspacePB, ImportAppFlowyDataPB,
|
||||
OauthSignInPB, OpenUserWorkspacePB, RenameWorkspacePB, RepeatedUserWorkspacePB, SignInUrlPB,
|
||||
SignInUrlPayloadPB, SignUpPayloadPB, UpdateCloudConfigPB, UpdateUserProfilePayloadPB,
|
||||
UserProfilePB, UserWorkspaceIdPB, UserWorkspacePB,
|
||||
UserProfilePB, UserWorkspaceIdPB, UserWorkspacePB, WorkspaceTypePB,
|
||||
};
|
||||
use flowy_user::errors::{FlowyError, FlowyResult};
|
||||
use flowy_user::event_map::UserEvent;
|
||||
use flowy_user_pub::entities::AuthType;
|
||||
use flowy_user_pub::entities::WorkspaceType;
|
||||
use lib_dispatch::prelude::{AFPluginDispatcher, AFPluginRequest, ToBytes};
|
||||
|
||||
use crate::event_builder::EventBuilder;
|
||||
|
@ -190,10 +190,14 @@ impl EventIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn create_workspace(&self, name: &str, auth_type: AuthType) -> UserWorkspacePB {
|
||||
pub async fn create_workspace(
|
||||
&self,
|
||||
name: &str,
|
||||
workspace_type: WorkspaceType,
|
||||
) -> UserWorkspacePB {
|
||||
let payload = CreateWorkspacePB {
|
||||
name: name.to_string(),
|
||||
auth_type: auth_type.into(),
|
||||
workspace_type: WorkspaceTypePB::from(workspace_type),
|
||||
};
|
||||
EventBuilder::new(self.clone())
|
||||
.event(UserEvent::CreateWorkspace)
|
||||
|
@ -280,10 +284,10 @@ impl EventIntegrationTest {
|
|||
.await;
|
||||
}
|
||||
|
||||
pub async fn open_workspace(&self, workspace_id: &str, auth_type: AuthTypePB) {
|
||||
pub async fn open_workspace(&self, workspace_id: &str, workspace_type: WorkspaceTypePB) {
|
||||
let payload = OpenUserWorkspacePB {
|
||||
workspace_id: workspace_id.to_string(),
|
||||
workspace_auth_type: auth_type,
|
||||
workspace_type,
|
||||
};
|
||||
EventBuilder::new(self.clone())
|
||||
.event(UserEvent::OpenWorkspace)
|
||||
|
|
|
@ -279,7 +279,9 @@ pub async fn create_view(
|
|||
}
|
||||
|
||||
pub async fn read_view(sdk: &EventIntegrationTest, view_id: &str) -> ViewPB {
|
||||
let view_id = ViewIdPB::from(view_id);
|
||||
let view_id = ViewIdPB {
|
||||
value: view_id.to_string(),
|
||||
};
|
||||
EventBuilder::new(sdk.clone())
|
||||
.event(GetView)
|
||||
.payload(view_id)
|
||||
|
|
|
@ -7,7 +7,7 @@ use event_integration_test::user_event::use_localhost_af_cloud;
|
|||
use event_integration_test::EventIntegrationTest;
|
||||
use flowy_user::entities::AFRolePB;
|
||||
use flowy_user_pub::cloud::UserCloudServiceProvider;
|
||||
use flowy_user_pub::entities::AuthType;
|
||||
use flowy_user_pub::entities::{AuthType, WorkspaceType};
|
||||
use std::time::Duration;
|
||||
use tokio::task::LocalSet;
|
||||
use tokio::time::sleep;
|
||||
|
@ -21,7 +21,7 @@ async fn af_cloud_workspace_delete() {
|
|||
assert_eq!(workspaces.len(), 1);
|
||||
|
||||
let created_workspace = test
|
||||
.create_workspace("my second workspace", AuthType::AppFlowyCloud)
|
||||
.create_workspace("my second workspace", WorkspaceType::Server)
|
||||
.await;
|
||||
assert_eq!(created_workspace.name, "my second workspace");
|
||||
let workspaces = get_synced_workspaces(&test, user_profile_pb.id).await;
|
||||
|
@ -71,7 +71,7 @@ async fn af_cloud_create_workspace_test() {
|
|||
assert_eq!(workspaces.len(), 1);
|
||||
|
||||
let created_workspace = test
|
||||
.create_workspace("my second workspace", AuthType::AppFlowyCloud)
|
||||
.create_workspace("my second workspace", WorkspaceType::Server)
|
||||
.await;
|
||||
assert_eq!(created_workspace.name, "my second workspace");
|
||||
|
||||
|
@ -94,7 +94,7 @@ async fn af_cloud_create_workspace_test() {
|
|||
test
|
||||
.open_workspace(
|
||||
&created_workspace.workspace_id,
|
||||
created_workspace.workspace_auth_type,
|
||||
created_workspace.workspace_type,
|
||||
)
|
||||
.await;
|
||||
let folder_ws = test.folder_read_current_workspace().await;
|
||||
|
@ -126,13 +126,10 @@ async fn af_cloud_open_workspace_test() {
|
|||
assert_eq!(views[3].name, "B");
|
||||
|
||||
let user_workspace = test
|
||||
.create_workspace("second workspace", AuthType::AppFlowyCloud)
|
||||
.create_workspace("second workspace", WorkspaceType::Server)
|
||||
.await;
|
||||
test
|
||||
.open_workspace(
|
||||
&user_workspace.workspace_id,
|
||||
user_workspace.workspace_auth_type,
|
||||
)
|
||||
.open_workspace(&user_workspace.workspace_id, user_workspace.workspace_type)
|
||||
.await;
|
||||
let second_workspace = test.get_current_workspace().await;
|
||||
let second_workspace = test.get_user_workspace(&second_workspace.id).await;
|
||||
|
@ -152,7 +149,7 @@ async fn af_cloud_open_workspace_test() {
|
|||
test
|
||||
.open_workspace(
|
||||
&first_workspace.workspace_id,
|
||||
first_workspace.workspace_auth_type,
|
||||
first_workspace.workspace_type,
|
||||
)
|
||||
.await;
|
||||
sleep(Duration::from_millis(300)).await;
|
||||
|
@ -163,7 +160,7 @@ async fn af_cloud_open_workspace_test() {
|
|||
test
|
||||
.open_workspace(
|
||||
&second_workspace.workspace_id,
|
||||
second_workspace.workspace_auth_type,
|
||||
second_workspace.workspace_type,
|
||||
)
|
||||
.await;
|
||||
sleep(Duration::from_millis(200)).await;
|
||||
|
@ -176,7 +173,7 @@ async fn af_cloud_open_workspace_test() {
|
|||
test
|
||||
.open_workspace(
|
||||
&first_workspace.workspace_id,
|
||||
first_workspace.workspace_auth_type,
|
||||
first_workspace.workspace_type,
|
||||
)
|
||||
.await;
|
||||
let views_1 = test.get_all_workspace_views().await;
|
||||
|
@ -188,7 +185,7 @@ async fn af_cloud_open_workspace_test() {
|
|||
test
|
||||
.open_workspace(
|
||||
&second_workspace.workspace_id,
|
||||
second_workspace.workspace_auth_type,
|
||||
second_workspace.workspace_type,
|
||||
)
|
||||
.await;
|
||||
let views_2 = test.get_all_workspace_views().await;
|
||||
|
@ -247,7 +244,7 @@ async fn af_cloud_different_open_same_workspace_test() {
|
|||
let index = i % 2;
|
||||
let iter_workspace_id = &all_workspaces[index].workspace_id;
|
||||
client
|
||||
.open_workspace(iter_workspace_id, all_workspaces[index].workspace_auth_type)
|
||||
.open_workspace(iter_workspace_id, all_workspaces[index].workspace_type)
|
||||
.await;
|
||||
if iter_workspace_id == &cloned_shared_workspace_id {
|
||||
let views = client.get_all_workspace_views().await;
|
||||
|
@ -312,7 +309,7 @@ async fn af_cloud_create_local_workspace_test() {
|
|||
|
||||
// Test: Create a local workspace
|
||||
let local_workspace = test
|
||||
.create_workspace("my local workspace", AuthType::Local)
|
||||
.create_workspace("my local workspace", WorkspaceType::Server)
|
||||
.await;
|
||||
|
||||
// Verify: Local workspace was created correctly
|
||||
|
@ -336,7 +333,7 @@ async fn af_cloud_create_local_workspace_test() {
|
|||
test
|
||||
.open_workspace(
|
||||
&local_workspace.workspace_id,
|
||||
local_workspace.workspace_auth_type,
|
||||
local_workspace.workspace_type,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
@ -372,7 +369,7 @@ async fn af_cloud_create_local_workspace_test() {
|
|||
|
||||
// Test: Create a server workspace
|
||||
let server_workspace = test
|
||||
.create_workspace("my server workspace", AuthType::AppFlowyCloud)
|
||||
.create_workspace("my server workspace", WorkspaceType::Server)
|
||||
.await;
|
||||
|
||||
// Verify: Server workspace was created correctly
|
||||
|
|
|
@ -18,7 +18,7 @@ use flowy_storage::manager::StorageManager;
|
|||
use flowy_user::event_map::UserStatusCallback;
|
||||
use flowy_user::user_manager::UserManager;
|
||||
use flowy_user_pub::cloud::{UserCloudConfig, UserCloudServiceProvider};
|
||||
use flowy_user_pub::entities::{AuthType, UserProfile, UserWorkspace};
|
||||
use flowy_user_pub::entities::{UserProfile, UserWorkspace, WorkspaceType};
|
||||
use lib_dispatch::runtime::AFPluginRuntime;
|
||||
use lib_infra::async_trait::async_trait;
|
||||
use uuid::Uuid;
|
||||
|
@ -85,7 +85,7 @@ impl UserStatusCallbackImpl {
|
|||
&self,
|
||||
user_id: i64,
|
||||
workspace_id: &Uuid,
|
||||
auth_type: &AuthType,
|
||||
workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<FolderInitDataSource> {
|
||||
if self.is_object_exist_on_disk(user_id, workspace_id, workspace_id)? {
|
||||
return Ok(FolderInitDataSource::LocalDisk {
|
||||
|
@ -97,7 +97,7 @@ impl UserStatusCallbackImpl {
|
|||
.cloud_service()?
|
||||
.get_folder_doc_state(workspace_id, user_id, CollabType::Folder, workspace_id)
|
||||
.await;
|
||||
resolve_data_source(auth_type, doc_state_result)
|
||||
resolve_data_source(workspace_type, doc_state_result)
|
||||
}
|
||||
|
||||
fn is_object_exist_on_disk(
|
||||
|
@ -126,7 +126,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
cloud_config: &Option<UserCloudConfig>,
|
||||
workspace_id: &Uuid,
|
||||
_device_id: &str,
|
||||
auth_type: &AuthType,
|
||||
workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
if let Some(cloud_config) = cloud_config {
|
||||
self
|
||||
|
@ -151,7 +151,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
.await?;
|
||||
self
|
||||
.database_manager()?
|
||||
.initialize(user_id, auth_type == &AuthType::Local)
|
||||
.initialize(user_id, workspace_type == &WorkspaceType::Local)
|
||||
.await?;
|
||||
self.document_manager()?.initialize(user_id).await?;
|
||||
|
||||
|
@ -173,7 +173,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
user_id: i64,
|
||||
workspace_id: &Uuid,
|
||||
device_id: &str,
|
||||
auth_type: &AuthType,
|
||||
workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
event!(
|
||||
tracing::Level::TRACE,
|
||||
|
@ -182,7 +182,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
device_id
|
||||
);
|
||||
let data_source = self
|
||||
.folder_init_data_source(user_id, workspace_id, auth_type)
|
||||
.folder_init_data_source(user_id, workspace_id, workspace_type)
|
||||
.await?;
|
||||
self
|
||||
.folder_manager()?
|
||||
|
@ -190,7 +190,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
.await?;
|
||||
self
|
||||
.database_manager()?
|
||||
.initialize_after_sign_in(user_id, auth_type.is_local())
|
||||
.initialize_after_sign_in(user_id, workspace_type.is_local())
|
||||
.await?;
|
||||
self
|
||||
.document_manager()?
|
||||
|
@ -211,7 +211,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
user_profile: &UserProfile,
|
||||
workspace_id: &Uuid,
|
||||
device_id: &str,
|
||||
auth_type: &AuthType,
|
||||
workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
event!(
|
||||
tracing::Level::TRACE,
|
||||
|
@ -221,7 +221,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
device_id
|
||||
);
|
||||
let data_source = self
|
||||
.folder_init_data_source(user_profile.uid, workspace_id, auth_type)
|
||||
.folder_init_data_source(user_profile.uid, workspace_id, workspace_type)
|
||||
.await?;
|
||||
|
||||
self
|
||||
|
@ -238,7 +238,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
|
||||
self
|
||||
.database_manager()?
|
||||
.initialize_after_sign_up(user_profile.uid, auth_type.is_local())
|
||||
.initialize_after_sign_up(user_profile.uid, workspace_type.is_local())
|
||||
.await
|
||||
.context("DatabaseManager error")?;
|
||||
|
||||
|
@ -265,10 +265,10 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
user_id: i64,
|
||||
workspace_id: &Uuid,
|
||||
_user_workspace: &UserWorkspace,
|
||||
auth_type: &AuthType,
|
||||
workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
let data_source = self
|
||||
.folder_init_data_source(user_id, workspace_id, auth_type)
|
||||
.folder_init_data_source(user_id, workspace_id, workspace_type)
|
||||
.await?;
|
||||
|
||||
self
|
||||
|
@ -277,7 +277,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
.await?;
|
||||
self
|
||||
.database_manager()?
|
||||
.initialize_after_open_workspace(user_id, auth_type.is_local())
|
||||
.initialize_after_open_workspace(user_id, workspace_type.is_local())
|
||||
.await?;
|
||||
self
|
||||
.document_manager()?
|
||||
|
@ -332,21 +332,21 @@ impl UserStatusCallback for UserStatusCallbackImpl {
|
|||
}
|
||||
|
||||
fn resolve_data_source(
|
||||
auth_type: &AuthType,
|
||||
workspace_type: &WorkspaceType,
|
||||
doc_state_result: Result<Vec<u8>, FlowyError>,
|
||||
) -> FlowyResult<FolderInitDataSource> {
|
||||
match doc_state_result {
|
||||
Ok(doc_state) => Ok(match auth_type {
|
||||
AuthType::Local => FolderInitDataSource::LocalDisk {
|
||||
Ok(doc_state) => Ok(match workspace_type {
|
||||
WorkspaceType::Local => FolderInitDataSource::LocalDisk {
|
||||
create_if_not_exist: true,
|
||||
},
|
||||
AuthType::AppFlowyCloud => FolderInitDataSource::Cloud(doc_state),
|
||||
WorkspaceType::Server => FolderInitDataSource::Cloud(doc_state),
|
||||
}),
|
||||
Err(err) => match auth_type {
|
||||
AuthType::Local => Ok(FolderInitDataSource::LocalDisk {
|
||||
Err(err) => match workspace_type {
|
||||
WorkspaceType::Local => Ok(FolderInitDataSource::LocalDisk {
|
||||
create_if_not_exist: true,
|
||||
}),
|
||||
AuthType::AppFlowyCloud => Err(err),
|
||||
WorkspaceType::Server => Err(err),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
|||
use flowy_user_pub::cloud::{UserCloudService, UserCollabParams, UserUpdate, UserUpdateReceiver};
|
||||
use flowy_user_pub::entities::{
|
||||
AFCloudOAuthParams, AuthResponse, AuthType, Role, UpdateUserProfileParams, UserProfile,
|
||||
UserWorkspace, WorkspaceInvitation, WorkspaceInvitationStatus, WorkspaceMember,
|
||||
UserWorkspace, WorkspaceInvitation, WorkspaceInvitationStatus, WorkspaceMember, WorkspaceType,
|
||||
};
|
||||
use flowy_user_pub::sql::select_user_workspace;
|
||||
use lib_infra::async_trait::async_trait;
|
||||
|
@ -656,7 +656,7 @@ fn to_user_workspace(af_workspace: AFWorkspace) -> UserWorkspace {
|
|||
icon: af_workspace.icon,
|
||||
member_count: af_workspace.member_count.unwrap_or(0),
|
||||
role: af_workspace.role.map(|r| r.into()),
|
||||
workspace_type: AuthType::AppFlowyCloud,
|
||||
workspace_type: WorkspaceType::Server,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use client_api::entity::{AFRole, AFUserProfile, AFWorkspaceInvitationStatus, AFW
|
|||
|
||||
use flowy_user_pub::entities::{
|
||||
AuthType, Role, UpdateUserProfileParams, UserProfile, WorkspaceInvitationStatus, WorkspaceMember,
|
||||
USER_METADATA_ICON_URL,
|
||||
WorkspaceType, USER_METADATA_ICON_URL,
|
||||
};
|
||||
|
||||
pub fn af_update_from_update_params(update: UpdateUserProfileParams) -> UpdateUserParams {
|
||||
|
@ -25,7 +25,7 @@ pub fn af_update_from_update_params(update: UpdateUserProfileParams) -> UpdateUs
|
|||
pub fn user_profile_from_af_profile(
|
||||
token: String,
|
||||
profile: AFUserProfile,
|
||||
workspace_auth_type: AuthType,
|
||||
auth_type: AuthType,
|
||||
) -> Result<UserProfile, Error> {
|
||||
let icon_url = {
|
||||
profile
|
||||
|
@ -36,7 +36,7 @@ pub fn user_profile_from_af_profile(
|
|||
})
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
let workspace_type = WorkspaceType::from(&auth_type);
|
||||
Ok(UserProfile {
|
||||
email: profile.email.unwrap_or("".to_string()),
|
||||
name: profile.name.unwrap_or("".to_string()),
|
||||
|
@ -45,7 +45,7 @@ pub fn user_profile_from_af_profile(
|
|||
auth_type: AuthType::AppFlowyCloud,
|
||||
uid: profile.uid,
|
||||
updated_at: profile.updated_at,
|
||||
workspace_auth_type,
|
||||
workspace_type,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -115,11 +115,11 @@ pub struct UserWorkspace {
|
|||
#[serde(default)]
|
||||
pub role: Option<Role>,
|
||||
#[serde(default = "default_workspace_type")]
|
||||
pub workspace_type: AuthType,
|
||||
pub workspace_type: WorkspaceType,
|
||||
}
|
||||
|
||||
fn default_workspace_type() -> AuthType {
|
||||
AuthType::AppFlowyCloud
|
||||
fn default_workspace_type() -> WorkspaceType {
|
||||
WorkspaceType::Server
|
||||
}
|
||||
|
||||
impl UserWorkspace {
|
||||
|
@ -137,7 +137,7 @@ impl UserWorkspace {
|
|||
icon: "".to_string(),
|
||||
member_count: 1,
|
||||
role: Some(Role::Owner),
|
||||
workspace_type: AuthType::Local,
|
||||
workspace_type: WorkspaceType::Local,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ pub struct UserProfile {
|
|||
pub token: String,
|
||||
pub icon_url: String,
|
||||
pub auth_type: AuthType,
|
||||
pub workspace_auth_type: AuthType,
|
||||
pub workspace_type: WorkspaceType,
|
||||
pub updated_at: i64,
|
||||
}
|
||||
|
||||
|
@ -208,6 +208,7 @@ where
|
|||
.unwrap_or_default()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let workspace_type = WorkspaceType::from(auth_type);
|
||||
Self {
|
||||
uid: value.user_id(),
|
||||
email: value.user_email().unwrap_or_default(),
|
||||
|
@ -215,7 +216,7 @@ where
|
|||
token: value.user_token().unwrap_or_default(),
|
||||
icon_url,
|
||||
auth_type: *auth_type,
|
||||
workspace_auth_type: *auth_type,
|
||||
workspace_type,
|
||||
updated_at: value.updated_at(),
|
||||
}
|
||||
}
|
||||
|
@ -265,6 +266,44 @@ impl UpdateUserProfileParams {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Hash, Serialize_repr, Deserialize_repr, Eq, PartialEq)]
|
||||
#[repr(u8)]
|
||||
pub enum WorkspaceType {
|
||||
Local = 0,
|
||||
Server = 1,
|
||||
}
|
||||
|
||||
impl Default for WorkspaceType {
|
||||
fn default() -> Self {
|
||||
Self::Local
|
||||
}
|
||||
}
|
||||
|
||||
impl WorkspaceType {
|
||||
pub fn is_local(&self) -> bool {
|
||||
matches!(self, WorkspaceType::Local)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for WorkspaceType {
|
||||
fn from(value: i32) -> Self {
|
||||
match value {
|
||||
0 => WorkspaceType::Local,
|
||||
1 => WorkspaceType::Server,
|
||||
_ => WorkspaceType::Server,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&AuthType> for WorkspaceType {
|
||||
fn from(value: &AuthType) -> Self {
|
||||
match value {
|
||||
AuthType::Local => WorkspaceType::Local,
|
||||
AuthType::AppFlowyCloud => WorkspaceType::Server,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Hash, Serialize_repr, Deserialize_repr, Eq, PartialEq)]
|
||||
#[repr(u8)]
|
||||
pub enum AuthType {
|
||||
|
@ -275,6 +314,15 @@ pub enum AuthType {
|
|||
AppFlowyCloud = 1,
|
||||
}
|
||||
|
||||
impl From<WorkspaceType> for AuthType {
|
||||
fn from(value: WorkspaceType) -> Self {
|
||||
match value {
|
||||
WorkspaceType::Local => AuthType::Local,
|
||||
WorkspaceType::Server => AuthType::AppFlowyCloud,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for AuthType {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use crate::cloud::UserUpdate;
|
||||
use crate::entities::{AuthType, Role, UpdateUserProfileParams, UserProfile, UserWorkspace};
|
||||
use crate::entities::{
|
||||
AuthType, Role, UpdateUserProfileParams, UserProfile, UserWorkspace, WorkspaceType,
|
||||
};
|
||||
use crate::sql::{
|
||||
select_user_workspace, upsert_user_workspace, upsert_workspace_member, WorkspaceMemberTable,
|
||||
};
|
||||
|
@ -114,7 +116,7 @@ pub fn insert_local_workspace(
|
|||
joined_at: None,
|
||||
};
|
||||
|
||||
upsert_user_workspace(uid, AuthType::Local, user_workspace.clone(), conn)?;
|
||||
upsert_user_workspace(uid, WorkspaceType::Local, user_workspace.clone(), conn)?;
|
||||
upsert_workspace_member(conn, row)?;
|
||||
Ok::<_, FlowyError>(())
|
||||
})?;
|
||||
|
@ -141,7 +143,7 @@ pub fn select_user_profile(
|
|||
conn: &mut SqliteConnection,
|
||||
) -> Result<UserProfile, FlowyError> {
|
||||
let workspace = select_user_workspace(workspace_id, conn)?;
|
||||
let workspace_auth_type = AuthType::from(workspace.workspace_type);
|
||||
let workspace_type = WorkspaceType::from(workspace.workspace_type);
|
||||
let row = select_user_table_row(uid, conn)?;
|
||||
|
||||
let user = UserProfile {
|
||||
|
@ -151,7 +153,7 @@ pub fn select_user_profile(
|
|||
token: row.token,
|
||||
icon_url: row.icon_url,
|
||||
auth_type: AuthType::from(row.auth_type),
|
||||
workspace_auth_type,
|
||||
workspace_type,
|
||||
updated_at: row.updated_at,
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::entities::{AuthType, UserWorkspace};
|
||||
use crate::entities::{AuthType, UserWorkspace, WorkspaceType};
|
||||
use chrono::{TimeZone, Utc};
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sqlite::schema::user_workspace_table;
|
||||
|
@ -66,7 +66,7 @@ impl UserWorkspaceTable {
|
|||
pub fn from_workspace(
|
||||
uid_val: i64,
|
||||
workspace: &UserWorkspace,
|
||||
auth_type: AuthType,
|
||||
workspace_type: WorkspaceType,
|
||||
) -> Result<Self, FlowyError> {
|
||||
if workspace.id.is_empty() {
|
||||
return Err(FlowyError::invalid_data().with_context("The id is empty"));
|
||||
|
@ -84,7 +84,7 @@ impl UserWorkspaceTable {
|
|||
icon: workspace.icon.clone(),
|
||||
member_count: workspace.member_count,
|
||||
role: workspace.role.map(|v| v as i32),
|
||||
workspace_type: auth_type as i32,
|
||||
workspace_type: workspace_type as i32,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -102,12 +102,12 @@ pub fn select_user_workspace(
|
|||
pub fn select_user_workspace_type(
|
||||
workspace_id: &str,
|
||||
conn: &mut SqliteConnection,
|
||||
) -> FlowyResult<AuthType> {
|
||||
) -> FlowyResult<WorkspaceType> {
|
||||
let row = dsl::user_workspace_table
|
||||
.filter(user_workspace_table::id.eq(workspace_id))
|
||||
.select(user_workspace_table::workspace_type)
|
||||
.first::<i32>(conn)?;
|
||||
Ok(AuthType::from(row))
|
||||
Ok(WorkspaceType::from(row))
|
||||
}
|
||||
|
||||
pub fn select_all_user_workspace(
|
||||
|
@ -160,7 +160,7 @@ impl From<UserWorkspaceTable> for UserWorkspace {
|
|||
icon: value.icon,
|
||||
member_count: value.member_count,
|
||||
role: value.role.map(|v| v.into()),
|
||||
workspace_type: AuthType::from(value.workspace_type),
|
||||
workspace_type: WorkspaceType::from(value.workspace_type),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,11 +192,11 @@ pub enum WorkspaceChange {
|
|||
|
||||
pub fn upsert_user_workspace(
|
||||
uid_val: i64,
|
||||
auth_type: AuthType,
|
||||
workspace_type: WorkspaceType,
|
||||
user_workspace: UserWorkspace,
|
||||
conn: &mut SqliteConnection,
|
||||
) -> Result<usize, FlowyError> {
|
||||
let row = UserWorkspaceTable::from_workspace(uid_val, &user_workspace, auth_type)?;
|
||||
let row = UserWorkspaceTable::from_workspace(uid_val, &user_workspace, workspace_type)?;
|
||||
let n = insert_into(user_workspace_table::table)
|
||||
.values(row.clone())
|
||||
.on_conflict(user_workspace_table::id)
|
||||
|
@ -217,7 +217,7 @@ pub fn upsert_user_workspace(
|
|||
|
||||
pub fn sync_user_workspaces_with_diff(
|
||||
uid_val: i64,
|
||||
auth_type: AuthType,
|
||||
workspace_type: WorkspaceType,
|
||||
user_workspaces: &[UserWorkspace],
|
||||
conn: &mut SqliteConnection,
|
||||
) -> FlowyResult<Vec<WorkspaceChange>> {
|
||||
|
@ -225,7 +225,7 @@ pub fn sync_user_workspaces_with_diff(
|
|||
// 1) Load all existing workspaces into a map
|
||||
let existing_rows: Vec<UserWorkspaceTable> = dsl::user_workspace_table
|
||||
.filter(user_workspace_table::uid.eq(uid_val))
|
||||
.filter(user_workspace_table::workspace_type.eq(auth_type as i32))
|
||||
.filter(user_workspace_table::workspace_type.eq(workspace_type as i32))
|
||||
.load(conn)?;
|
||||
let mut existing_map: HashMap<String, UserWorkspaceTable> = existing_rows
|
||||
.into_iter()
|
||||
|
@ -251,7 +251,7 @@ pub fn sync_user_workspaces_with_diff(
|
|||
match existing_map.remove(&uw.id) {
|
||||
None => {
|
||||
// new workspace → insert
|
||||
let new_row = UserWorkspaceTable::from_workspace(uid_val, uw, auth_type)?;
|
||||
let new_row = UserWorkspaceTable::from_workspace(uid_val, uw, workspace_type)?;
|
||||
diesel::insert_into(user_workspace_table::table)
|
||||
.values(new_row)
|
||||
.execute(conn)?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::AFRolePB;
|
||||
use super::{AFRolePB, WorkspaceTypePB};
|
||||
use crate::entities::parser::{UserEmail, UserIcon, UserName};
|
||||
use crate::entities::AuthTypePB;
|
||||
use crate::errors::ErrorCode;
|
||||
|
@ -42,7 +42,7 @@ pub struct UserProfilePB {
|
|||
pub user_auth_type: AuthTypePB,
|
||||
|
||||
#[pb(index = 7)]
|
||||
pub workspace_auth_type: AuthTypePB,
|
||||
pub workspace_type: WorkspaceTypePB,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf_Enum, Eq, PartialEq, Debug, Clone)]
|
||||
|
@ -66,7 +66,7 @@ impl From<UserProfile> for UserProfilePB {
|
|||
token: user_profile.token,
|
||||
icon_url: user_profile.icon_url,
|
||||
user_auth_type: user_profile.auth_type.into(),
|
||||
workspace_auth_type: user_profile.workspace_auth_type.into(),
|
||||
workspace_type: user_profile.workspace_type.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ pub struct UserWorkspacePB {
|
|||
pub role: Option<AFRolePB>,
|
||||
|
||||
#[pb(index = 7)]
|
||||
pub workspace_auth_type: AuthTypePB,
|
||||
pub workspace_type: WorkspaceTypePB,
|
||||
}
|
||||
|
||||
impl From<UserWorkspace> for UserWorkspacePB {
|
||||
|
@ -198,7 +198,7 @@ impl From<UserWorkspace> for UserWorkspacePB {
|
|||
icon: workspace.icon,
|
||||
member_count: workspace.member_count,
|
||||
role: workspace.role.map(AFRolePB::from),
|
||||
workspace_auth_type: AuthTypePB::from(workspace.workspace_type),
|
||||
workspace_type: WorkspaceTypePB::from(workspace.workspace_type),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ impl From<UserWorkspaceTable> for UserWorkspacePB {
|
|||
icon: value.icon,
|
||||
member_count: value.member_count,
|
||||
role: value.role.map(AFRolePB::from),
|
||||
workspace_auth_type: AuthTypePB::from(value.workspace_type),
|
||||
workspace_type: WorkspaceTypePB::from(value.workspace_type),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ use validator::Validate;
|
|||
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_user_pub::cloud::{AFWorkspaceSettings, AFWorkspaceSettingsChange};
|
||||
use flowy_user_pub::entities::{AuthType, Role, WorkspaceInvitation, WorkspaceMember};
|
||||
use flowy_user_pub::entities::{
|
||||
AuthType, Role, WorkspaceInvitation, WorkspaceMember, WorkspaceType,
|
||||
};
|
||||
use flowy_user_pub::sql::WorkspaceSettingsTable;
|
||||
use lib_infra::validator_fn::required_not_empty_str;
|
||||
|
||||
|
@ -204,7 +206,7 @@ pub struct OpenUserWorkspacePB {
|
|||
pub workspace_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub workspace_auth_type: AuthTypePB,
|
||||
pub workspace_type: WorkspaceTypePB,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Clone, Validate)]
|
||||
|
@ -243,7 +245,43 @@ pub struct CreateWorkspacePB {
|
|||
pub name: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub auth_type: AuthTypePB,
|
||||
pub workspace_type: WorkspaceTypePB,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf_Enum, Copy, Default, Debug, Clone, Eq, PartialEq)]
|
||||
#[repr(u8)]
|
||||
pub enum WorkspaceTypePB {
|
||||
#[default]
|
||||
LocalW = 0,
|
||||
ServerW = 1,
|
||||
}
|
||||
|
||||
impl From<i32> for WorkspaceTypePB {
|
||||
fn from(value: i32) -> Self {
|
||||
match value {
|
||||
0 => WorkspaceTypePB::LocalW,
|
||||
1 => WorkspaceTypePB::ServerW,
|
||||
_ => WorkspaceTypePB::ServerW,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WorkspaceType> for WorkspaceTypePB {
|
||||
fn from(value: WorkspaceType) -> Self {
|
||||
match value {
|
||||
WorkspaceType::Local => WorkspaceTypePB::LocalW,
|
||||
WorkspaceType::Server => WorkspaceTypePB::ServerW,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WorkspaceTypePB> for WorkspaceType {
|
||||
fn from(value: WorkspaceTypePB) -> Self {
|
||||
match value {
|
||||
WorkspaceTypePB::LocalW => WorkspaceType::Local,
|
||||
WorkspaceTypePB::ServerW => WorkspaceType::Server,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf_Enum, Copy, Default, Debug, Clone, Eq, PartialEq)]
|
||||
|
|
|
@ -451,7 +451,7 @@ pub async fn open_workspace_handler(
|
|||
let params = data.try_into_inner()?;
|
||||
let workspace_id = Uuid::from_str(¶ms.workspace_id)?;
|
||||
manager
|
||||
.open_workspace(&workspace_id, AuthType::from(params.workspace_auth_type))
|
||||
.open_workspace(&workspace_id, WorkspaceType::from(params.workspace_type))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -621,9 +621,9 @@ pub async fn create_workspace_handler(
|
|||
manager: AFPluginState<Weak<UserManager>>,
|
||||
) -> DataResult<UserWorkspacePB, FlowyError> {
|
||||
let data = data.try_into_inner()?;
|
||||
let auth_type = AuthType::from(data.auth_type);
|
||||
let workspace_type = WorkspaceType::from(data.workspace_type);
|
||||
let manager = upgrade_manager(manager)?;
|
||||
let new_workspace = manager.create_workspace(&data.name, auth_type).await?;
|
||||
let new_workspace = manager.create_workspace(&data.name, workspace_type).await?;
|
||||
data_result_ok(UserWorkspacePB::from(new_workspace))
|
||||
}
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ pub trait UserStatusCallback: Send + Sync + 'static {
|
|||
_cloud_config: &Option<UserCloudConfig>,
|
||||
_workspace_id: &Uuid,
|
||||
_device_id: &str,
|
||||
_auth_type: &AuthType,
|
||||
_workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ pub trait UserStatusCallback: Send + Sync + 'static {
|
|||
_user_id: i64,
|
||||
_workspace_id: &Uuid,
|
||||
_device_id: &str,
|
||||
_auth_type: &AuthType,
|
||||
_workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ pub trait UserStatusCallback: Send + Sync + 'static {
|
|||
_user_profile: &UserProfile,
|
||||
_workspace_id: &Uuid,
|
||||
_device_id: &str,
|
||||
_auth_type: &AuthType,
|
||||
_workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ pub trait UserStatusCallback: Send + Sync + 'static {
|
|||
_user_id: i64,
|
||||
_workspace_id: &Uuid,
|
||||
_user_workspace: &UserWorkspace,
|
||||
_auth_type: &AuthType,
|
||||
_workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use tracing::instrument;
|
|||
use collab_integrate::CollabKVDB;
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_sqlite::kv::KVStorePreferences;
|
||||
use flowy_user_pub::entities::AuthType;
|
||||
use flowy_user_pub::entities::{AuthType, WorkspaceType};
|
||||
|
||||
use crate::migrations::migration::UserDataMigration;
|
||||
use crate::migrations::session_migration::get_session_workspace;
|
||||
|
@ -45,8 +45,8 @@ impl UserDataMigration for AnonUserWorkspaceTableMigration {
|
|||
if matches!(user_auth_type, AuthType::Local) {
|
||||
if let Some(mut user_workspace) = get_session_workspace(store_preferences) {
|
||||
if select_user_workspace(&user_workspace.id, db).ok().is_none() {
|
||||
user_workspace.workspace_type = AuthType::Local;
|
||||
upsert_user_workspace(user.user_id, *user_auth_type, user_workspace, db)?;
|
||||
user_workspace.workspace_type = WorkspaceType::Local;
|
||||
upsert_user_workspace(user.user_id, WorkspaceType::Local, user_workspace, db)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use chrono::Utc;
|
||||
use flowy_sqlite::kv::KVStorePreferences;
|
||||
use flowy_user_pub::entities::{AuthType, Role, UserWorkspace};
|
||||
use flowy_user_pub::entities::{Role, UserWorkspace, WorkspaceType};
|
||||
use flowy_user_pub::session::Session;
|
||||
use serde::de::{MapAccess, Visitor};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
@ -95,7 +95,7 @@ impl<'de> Visitor<'de> for SessionVisitor {
|
|||
icon: "".to_owned(),
|
||||
member_count: 1,
|
||||
role: Some(Role::Owner),
|
||||
workspace_type: AuthType::Local,
|
||||
workspace_type: WorkspaceType::Local,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use collab_plugins::local_storage::kv::KVTransactionDB;
|
|||
use flowy_error::{internal_error, ErrorCode, FlowyError, FlowyResult};
|
||||
use flowy_sqlite::kv::KVStorePreferences;
|
||||
use flowy_sqlite::DBConnection;
|
||||
use flowy_user_pub::entities::{AuthType, UserWorkspace};
|
||||
use flowy_user_pub::entities::{UserWorkspace, WorkspaceType};
|
||||
use flowy_user_pub::session::Session;
|
||||
use flowy_user_pub::sql::{select_user_workspace, select_user_workspace_type};
|
||||
use std::path::PathBuf;
|
||||
|
@ -58,7 +58,7 @@ impl AuthenticateUser {
|
|||
let session = self.get_session()?;
|
||||
let mut conn = self.get_sqlite_connection(session.user_id)?;
|
||||
let workspace_type = select_user_workspace_type(&session.workspace_id, &mut conn)?;
|
||||
Ok(matches!(workspace_type, AuthType::Local))
|
||||
Ok(matches!(workspace_type, WorkspaceType::Local))
|
||||
}
|
||||
|
||||
pub fn device_id(&self) -> FlowyResult<String> {
|
||||
|
|
|
@ -151,9 +151,10 @@ impl UserManager {
|
|||
);
|
||||
let workspace_uuid = Uuid::parse_str(&session.workspace_id)?;
|
||||
let mut conn = self.db_connection(session.user_id)?;
|
||||
let auth_type = select_user_workspace_type(&session.workspace_id, &mut conn)?;
|
||||
let workspace_type = select_user_workspace_type(&session.workspace_id, &mut conn)?;
|
||||
|
||||
let uid = session.user_id;
|
||||
let auth_type = AuthType::from(workspace_type);
|
||||
let token = self.token_from_auth_type(&auth_type)?;
|
||||
cloud_service.set_server_auth_type(&auth_type, token.clone())?;
|
||||
|
||||
|
@ -161,7 +162,7 @@ impl UserManager {
|
|||
tracing::Level::INFO,
|
||||
"init user session: {}, auth type: {:?}",
|
||||
uid,
|
||||
auth_type,
|
||||
workspace_type,
|
||||
);
|
||||
|
||||
self.prepare_user(&session).await;
|
||||
|
@ -277,7 +278,7 @@ impl UserManager {
|
|||
session.user_id,
|
||||
&session.user_uuid,
|
||||
&workspace_uuid,
|
||||
&auth_type,
|
||||
&workspace_type,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
@ -287,7 +288,7 @@ impl UserManager {
|
|||
&cloud_config,
|
||||
&workspace_uuid,
|
||||
&self.authenticate_user.user_config.device_id,
|
||||
&auth_type,
|
||||
&workspace_type,
|
||||
)
|
||||
.await?;
|
||||
} else {
|
||||
|
@ -370,7 +371,7 @@ impl UserManager {
|
|||
session.user_id,
|
||||
&session.user_uuid,
|
||||
&workspace_id,
|
||||
&user_profile.workspace_auth_type,
|
||||
&user_profile.workspace_type,
|
||||
)
|
||||
.await;
|
||||
self
|
||||
|
@ -381,7 +382,7 @@ impl UserManager {
|
|||
user_profile.uid,
|
||||
&workspace_id,
|
||||
&self.authenticate_user.user_config.device_id,
|
||||
&auth_type,
|
||||
&user_profile.workspace_type,
|
||||
)
|
||||
.await?;
|
||||
send_auth_state_notification(AuthStateChangedPB {
|
||||
|
@ -434,7 +435,7 @@ impl UserManager {
|
|||
new_session.user_id,
|
||||
&new_session.user_uuid,
|
||||
&workspace_id,
|
||||
auth_type,
|
||||
&new_user_profile.workspace_type,
|
||||
)
|
||||
.await;
|
||||
let workspace_id = Uuid::parse_str(&new_session.workspace_id)?;
|
||||
|
@ -447,7 +448,7 @@ impl UserManager {
|
|||
new_user_profile,
|
||||
&workspace_id,
|
||||
&self.authenticate_user.user_config.device_id,
|
||||
auth_type,
|
||||
&new_user_profile.workspace_type,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -560,7 +561,7 @@ impl UserManager {
|
|||
workspace_id: &str,
|
||||
) -> FlowyResult<()> {
|
||||
// If the user is a local user, no need to refresh the user profile
|
||||
if old_user_profile.workspace_auth_type.is_local() {
|
||||
if old_user_profile.workspace_type.is_local() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -757,7 +758,8 @@ impl UserManager {
|
|||
}
|
||||
|
||||
let mut conn = self.db_connection(uid)?;
|
||||
sync_user_workspaces_with_diff(uid, auth_type, response.user_workspaces(), &mut conn)?;
|
||||
let workspace_type = WorkspaceType::from(&auth_type);
|
||||
sync_user_workspaces_with_diff(uid, workspace_type, response.user_workspaces(), &mut conn)?;
|
||||
info!(
|
||||
"Save new user profile to disk, authenticator: {:?}",
|
||||
auth_type
|
||||
|
|
|
@ -12,7 +12,7 @@ use collab_integrate::CollabKVDB;
|
|||
use collab_user::core::{UserAwareness, UserAwarenessNotifier};
|
||||
use dashmap::try_result::TryResult;
|
||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||
use flowy_user_pub::entities::{user_awareness_object_id, AuthType};
|
||||
use flowy_user_pub::entities::{user_awareness_object_id, WorkspaceType};
|
||||
use tracing::{error, info, instrument, trace};
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -131,7 +131,7 @@ impl UserManager {
|
|||
uid: i64,
|
||||
user_uuid: &Uuid,
|
||||
workspace_id: &Uuid,
|
||||
workspace_auth_type: &AuthType,
|
||||
workspace_type: &WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
let object_id = user_awareness_object_id(user_uuid, &workspace_id.to_string());
|
||||
|
||||
|
@ -162,11 +162,11 @@ impl UserManager {
|
|||
let is_exist_on_disk = self
|
||||
.authenticate_user
|
||||
.is_collab_on_disk(uid, &object_id.to_string())?;
|
||||
if workspace_auth_type.is_local() || is_exist_on_disk {
|
||||
if workspace_type.is_local() || is_exist_on_disk {
|
||||
trace!(
|
||||
"Initializing new user awareness from disk:{}, {:?}",
|
||||
object_id,
|
||||
workspace_auth_type
|
||||
workspace_type
|
||||
);
|
||||
let collab_db = self.get_collab_db(uid)?;
|
||||
let doc_state =
|
||||
|
@ -191,9 +191,9 @@ impl UserManager {
|
|||
} else {
|
||||
info!(
|
||||
"Initializing new user awareness from server:{}, {:?}",
|
||||
object_id, workspace_auth_type
|
||||
object_id, workspace_type
|
||||
);
|
||||
self.load_awareness_from_server(uid, workspace_id, object_id, *workspace_auth_type)?;
|
||||
self.load_awareness_from_server(uid, workspace_id, object_id, *workspace_type)?;
|
||||
}
|
||||
} else {
|
||||
return Err(FlowyError::new(
|
||||
|
@ -216,7 +216,7 @@ impl UserManager {
|
|||
uid: i64,
|
||||
workspace_id: &Uuid,
|
||||
object_id: Uuid,
|
||||
workspace_auth_type: AuthType,
|
||||
workspace_type: WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
// Clone necessary data
|
||||
let collab_db = self.get_collab_db(uid)?;
|
||||
|
@ -234,7 +234,7 @@ impl UserManager {
|
|||
}
|
||||
};
|
||||
|
||||
let create_awareness = if workspace_auth_type.is_local() {
|
||||
let create_awareness = if workspace_type.is_local() {
|
||||
let doc_state =
|
||||
CollabPersistenceImpl::new(collab_db.clone(), uid, workspace_id).into_data_source();
|
||||
Self::collab_for_user_awareness(
|
||||
|
|
|
@ -22,6 +22,7 @@ use flowy_sqlite::ConnectionPool;
|
|||
use flowy_user_pub::cloud::{UserCloudService, UserCloudServiceProvider};
|
||||
use flowy_user_pub::entities::{
|
||||
AuthType, Role, UserWorkspace, WorkspaceInvitation, WorkspaceInvitationStatus, WorkspaceMember,
|
||||
WorkspaceType,
|
||||
};
|
||||
use flowy_user_pub::session::Session;
|
||||
use flowy_user_pub::sql::*;
|
||||
|
@ -116,7 +117,7 @@ impl UserManager {
|
|||
user_id,
|
||||
weak_user_collab_db,
|
||||
&workspace_id,
|
||||
&user.workspace_auth_type,
|
||||
&user.auth_type,
|
||||
collab_data,
|
||||
weak_user_cloud_service,
|
||||
)
|
||||
|
@ -140,16 +141,17 @@ impl UserManager {
|
|||
pub async fn open_workspace(
|
||||
&self,
|
||||
workspace_id: &Uuid,
|
||||
workspace_auth_type: AuthType,
|
||||
workspace_type: WorkspaceType,
|
||||
) -> FlowyResult<()> {
|
||||
info!(
|
||||
"open workspace: {}, auth type:{}",
|
||||
workspace_id, workspace_auth_type
|
||||
"open workspace: {}, auth type:{:?}",
|
||||
workspace_id, workspace_type
|
||||
);
|
||||
let workspace_id_str = workspace_id.to_string();
|
||||
let token = self.token_from_auth_type(&workspace_auth_type)?;
|
||||
let auth_type = AuthType::from(workspace_type);
|
||||
let token = self.token_from_auth_type(&auth_type)?;
|
||||
let cloud_service = self.cloud_service()?;
|
||||
cloud_service.set_server_auth_type(&workspace_auth_type, token)?;
|
||||
cloud_service.set_server_auth_type(&auth_type, token)?;
|
||||
|
||||
let uid = self.user_id()?;
|
||||
let profile = self
|
||||
|
@ -167,7 +169,7 @@ impl UserManager {
|
|||
workspace_id,
|
||||
cloud_service.get_user_service()?,
|
||||
uid,
|
||||
workspace_auth_type,
|
||||
workspace_type,
|
||||
self.db_pool(uid)?,
|
||||
)
|
||||
.await?
|
||||
|
@ -181,7 +183,7 @@ impl UserManager {
|
|||
let user_service = cloud_service.get_user_service()?;
|
||||
let pool = self.db_pool(uid)?;
|
||||
tokio::spawn(async move {
|
||||
let _ = sync_workspace(&workspace_id, user_service, uid, workspace_auth_type, pool).await;
|
||||
let _ = sync_workspace(&workspace_id, user_service, uid, workspace_type, pool).await;
|
||||
});
|
||||
user_workspace
|
||||
},
|
||||
|
@ -196,14 +198,14 @@ impl UserManager {
|
|||
.user_status_callback
|
||||
.read()
|
||||
.await
|
||||
.on_workspace_opened(uid, workspace_id, &user_workspace, &workspace_auth_type)
|
||||
.on_workspace_opened(uid, workspace_id, &user_workspace, &workspace_type)
|
||||
.await
|
||||
{
|
||||
error!("Open workspace failed: {:?}", err);
|
||||
}
|
||||
|
||||
if let Err(err) = self
|
||||
.initial_user_awareness(uid, &user_uuid, workspace_id, &workspace_auth_type)
|
||||
.initial_user_awareness(uid, &user_uuid, workspace_id, &workspace_type)
|
||||
.await
|
||||
{
|
||||
error!(
|
||||
|
@ -219,8 +221,9 @@ impl UserManager {
|
|||
pub async fn create_workspace(
|
||||
&self,
|
||||
workspace_name: &str,
|
||||
auth_type: AuthType,
|
||||
workspace_type: WorkspaceType,
|
||||
) -> FlowyResult<UserWorkspace> {
|
||||
let auth_type = AuthType::from(workspace_type);
|
||||
let token = self.token_from_auth_type(&auth_type)?;
|
||||
let cloud_service = self.cloud_service()?;
|
||||
cloud_service.set_server_auth_type(&auth_type, token)?;
|
||||
|
@ -232,14 +235,14 @@ impl UserManager {
|
|||
.await?;
|
||||
|
||||
info!(
|
||||
"create workspace: {}, name:{}, auth_type: {}",
|
||||
new_workspace.id, new_workspace.name, auth_type
|
||||
"create workspace: {}, name:{}, auth_type: {:?}",
|
||||
new_workspace.id, new_workspace.name, workspace_type
|
||||
);
|
||||
|
||||
// save the workspace to sqlite db
|
||||
let uid = self.user_id()?;
|
||||
let mut conn = self.db_connection(uid)?;
|
||||
upsert_user_workspace(uid, auth_type, new_workspace.clone(), &mut conn)?;
|
||||
upsert_user_workspace(uid, workspace_type, new_workspace.clone(), &mut conn)?;
|
||||
Ok(new_workspace)
|
||||
}
|
||||
|
||||
|
@ -417,9 +420,7 @@ impl UserManager {
|
|||
self.cloud_service().and_then(|v| v.get_user_service()),
|
||||
self.db_pool(uid),
|
||||
) {
|
||||
// capture only what we need
|
||||
let auth_copy = auth_type;
|
||||
|
||||
tokio::spawn(async move {
|
||||
// fetch remote list
|
||||
let new_ws = match service.get_all_workspace(uid).await {
|
||||
|
@ -440,7 +441,8 @@ impl UserManager {
|
|||
};
|
||||
|
||||
// sync + diff
|
||||
match sync_user_workspaces_with_diff(uid, auth_copy, &new_ws, &mut conn) {
|
||||
let workspace_type = WorkspaceType::from(&auth_copy);
|
||||
match sync_user_workspaces_with_diff(uid, workspace_type, &new_ws, &mut conn) {
|
||||
Ok(changes) if !changes.is_empty() => {
|
||||
info!(
|
||||
"synced {} workspaces for user {} and auth type {:?}. changes: {:?}",
|
||||
|
@ -773,12 +775,12 @@ async fn sync_workspace(
|
|||
workspace_id: &Uuid,
|
||||
user_service: Arc<dyn UserCloudService>,
|
||||
uid: i64,
|
||||
auth_type: AuthType,
|
||||
workspace_type: WorkspaceType,
|
||||
pool: Arc<ConnectionPool>,
|
||||
) -> FlowyResult<UserWorkspace> {
|
||||
let user_workspace = user_service.open_workspace(workspace_id).await?;
|
||||
if let Ok(mut conn) = pool.get() {
|
||||
upsert_user_workspace(uid, auth_type, user_workspace.clone(), &mut conn)?;
|
||||
upsert_user_workspace(uid, workspace_type, user_workspace.clone(), &mut conn)?;
|
||||
}
|
||||
Ok(user_workspace)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue