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