mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 00:03:56 +00:00
[PM-12049] Remove usage of ActiveUserState from folder service (#11880)
* Migrated folder service from using active user state to single user state Added extra test cases for encrypted folder and decrypted folders Updated derived state to use decrypt with key * Update callers in the web * Update callers in the browser * Update callers in libs * Update callers in cli * Fixed test * Fixed folder state test * Fixed test * removed duplicate activeUserId * Added takewhile operator to only make calls when userId is present * Simplified to accept a single user id instead of an observable * Required userid to be passed from notification service * [PM-15635] Folders not working on desktop (#12333) * Added folders memory state definition * added decrypted folders state * Refactored service to remove derived state * removed combinedstate and added clear decrypted folders to methods * Fixed test * Fixed issue with editing folder on the desktop app * Fixed test * Changed state name * fixed ts strict issue * fixed ts strict issue * fixed ts strict issue * removed unnecessasry null encrypteed folder check * Handle null folderdata * [PM-16197] "Items with No Folder" shows as a folder to edit name and delete (#12470) * Force redcryption anytime encryption state changes * Fixed text file * revert changes * create new object with nofolder instead of modifying exisiting object * Fixed failing test * switched to use memory-large-object * Fixed ts sctrict issue --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com> Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
This commit is contained in:
@@ -150,6 +150,9 @@ export const COLLECTION_DATA = new StateDefinition("collection", "disk", {
|
||||
web: "memory",
|
||||
});
|
||||
export const FOLDER_DISK = new StateDefinition("folder", "disk", { web: "memory" });
|
||||
export const FOLDER_MEMORY = new StateDefinition("decryptedFolders", "memory", {
|
||||
browser: "memory-large-object",
|
||||
});
|
||||
export const VAULT_FILTER_DISK = new StateDefinition("vaultFilter", "disk", {
|
||||
web: "disk-local",
|
||||
});
|
||||
|
||||
@@ -85,18 +85,25 @@ export abstract class CoreSyncService implements SyncService {
|
||||
await this.stateProvider.getUser(userId, LAST_SYNC_DATE).update(() => date);
|
||||
}
|
||||
|
||||
async syncUpsertFolder(notification: SyncFolderNotification, isEdit: boolean): Promise<boolean> {
|
||||
async syncUpsertFolder(
|
||||
notification: SyncFolderNotification,
|
||||
isEdit: boolean,
|
||||
userId: UserId,
|
||||
): Promise<boolean> {
|
||||
this.syncStarted();
|
||||
if (await this.stateService.getIsAuthenticated()) {
|
||||
|
||||
const authStatus = await firstValueFrom(this.authService.authStatusFor$(userId));
|
||||
|
||||
if (authStatus >= AuthenticationStatus.Locked) {
|
||||
try {
|
||||
const localFolder = await this.folderService.get(notification.id);
|
||||
const localFolder = await this.folderService.get(notification.id, userId);
|
||||
if (
|
||||
(!isEdit && localFolder == null) ||
|
||||
(isEdit && localFolder != null && localFolder.revisionDate < notification.revisionDate)
|
||||
) {
|
||||
const remoteFolder = await this.folderApiService.get(notification.id);
|
||||
if (remoteFolder != null) {
|
||||
await this.folderService.upsert(new FolderData(remoteFolder));
|
||||
await this.folderService.upsert(new FolderData(remoteFolder), userId);
|
||||
this.messageSender.send("syncedUpsertedFolder", { folderId: notification.id });
|
||||
return this.syncCompleted(true);
|
||||
}
|
||||
@@ -108,10 +115,13 @@ export abstract class CoreSyncService implements SyncService {
|
||||
return this.syncCompleted(false);
|
||||
}
|
||||
|
||||
async syncDeleteFolder(notification: SyncFolderNotification): Promise<boolean> {
|
||||
async syncDeleteFolder(notification: SyncFolderNotification, userId: UserId): Promise<boolean> {
|
||||
this.syncStarted();
|
||||
if (await this.stateService.getIsAuthenticated()) {
|
||||
await this.folderService.delete(notification.id);
|
||||
|
||||
const authStatus = await firstValueFrom(this.authService.authStatusFor$(userId));
|
||||
|
||||
if (authStatus >= AuthenticationStatus.Locked) {
|
||||
await this.folderService.delete(notification.id, userId);
|
||||
this.messageSender.send("syncedDeletedFolder", { folderId: notification.id });
|
||||
this.syncCompleted(true);
|
||||
return true;
|
||||
|
||||
@@ -56,8 +56,9 @@ export abstract class SyncService {
|
||||
abstract syncUpsertFolder(
|
||||
notification: SyncFolderNotification,
|
||||
isEdit: boolean,
|
||||
userId: UserId,
|
||||
): Promise<boolean>;
|
||||
abstract syncDeleteFolder(notification: SyncFolderNotification): Promise<boolean>;
|
||||
abstract syncDeleteFolder(notification: SyncFolderNotification, userId: UserId): Promise<boolean>;
|
||||
abstract syncUpsertCipher(
|
||||
notification: SyncCipherNotification,
|
||||
isEdit: boolean,
|
||||
|
||||
Reference in New Issue
Block a user