mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
[PM-5276] Migrate FolderService to state providers (#7682)
* added state definitionand key definition for folder service * added data migrations * created folder to house key definitions * deleted browser-folder-service and added state provider to the browser * exposed decrypt function so it can be used by the key definition, updated folder service to use state provider * removed memory since derived state is now used * updated test cases * updated test cases * updated migrations after merge conflict fix * added state provider to the folder service constructor * renamed migration file * updated comments * updated comments * removed service registartion from browser service module and removed unused set and get encrypted folders from state service * renamed files * added storage location overides and removed extra methods
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { KeyDefinitionLike, MigrationHelper } from "../migration-helper";
|
||||
import { Migrator } from "../migrator";
|
||||
|
||||
type FolderDataType = {
|
||||
id: string;
|
||||
name: string;
|
||||
revisionDate: string;
|
||||
};
|
||||
|
||||
type ExpectedAccountType = {
|
||||
data?: {
|
||||
folders?: {
|
||||
encrypted?: Record<string, FolderDataType>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
const USER_ENCRYPTED_FOLDERS: KeyDefinitionLike = {
|
||||
key: "folders",
|
||||
stateDefinition: {
|
||||
name: "folder",
|
||||
},
|
||||
};
|
||||
|
||||
export class FolderMigrator extends Migrator<14, 15> {
|
||||
async migrate(helper: MigrationHelper): Promise<void> {
|
||||
const accounts = await helper.getAccounts<ExpectedAccountType>();
|
||||
async function migrateAccount(userId: string, account: ExpectedAccountType): Promise<void> {
|
||||
const value = account?.data?.folders?.encrypted;
|
||||
if (value != null) {
|
||||
await helper.setToUser(userId, USER_ENCRYPTED_FOLDERS, value);
|
||||
delete account.data.folders;
|
||||
await helper.set(userId, account);
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all([...accounts.map(({ userId, account }) => migrateAccount(userId, account))]);
|
||||
}
|
||||
|
||||
async rollback(helper: MigrationHelper): Promise<void> {
|
||||
const accounts = await helper.getAccounts<ExpectedAccountType>();
|
||||
async function rollbackAccount(userId: string, account: ExpectedAccountType): Promise<void> {
|
||||
const value = await helper.getFromUser(userId, USER_ENCRYPTED_FOLDERS);
|
||||
if (account) {
|
||||
account.data = Object.assign(account.data ?? {}, {
|
||||
folders: {
|
||||
encrypted: value,
|
||||
},
|
||||
});
|
||||
await helper.set(userId, account);
|
||||
}
|
||||
await helper.setToUser(userId, USER_ENCRYPTED_FOLDERS, null);
|
||||
}
|
||||
|
||||
await Promise.all([...accounts.map(({ userId, account }) => rollbackAccount(userId, account))]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user