mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 21:33:27 +00:00
[PM-5571] Migrate enableDDG to state provider framework (#8384)
Migrate enableDuckDuckGo to state provider framework.
This commit is contained in:
@@ -188,11 +188,6 @@ export abstract class StateService<T extends Account = Account> {
|
||||
value: boolean,
|
||||
options?: StorageOptions,
|
||||
) => Promise<void>;
|
||||
getEnableDuckDuckGoBrowserIntegration: (options?: StorageOptions) => Promise<boolean>;
|
||||
setEnableDuckDuckGoBrowserIntegration: (
|
||||
value: boolean,
|
||||
options?: StorageOptions,
|
||||
) => Promise<void>;
|
||||
getEncryptedCiphers: (options?: StorageOptions) => Promise<{ [id: string]: CipherData }>;
|
||||
setEncryptedCiphers: (
|
||||
value: { [id: string]: CipherData },
|
||||
|
||||
@@ -13,6 +13,5 @@ export class GlobalState {
|
||||
mainWindowSize?: number;
|
||||
enableBrowserIntegration?: boolean;
|
||||
enableBrowserIntegrationFingerprint?: boolean;
|
||||
enableDuckDuckGoBrowserIntegration?: boolean;
|
||||
deepLinkRedirectUrl?: string;
|
||||
}
|
||||
|
||||
@@ -867,27 +867,6 @@ export class StateService<
|
||||
);
|
||||
}
|
||||
|
||||
async getEnableDuckDuckGoBrowserIntegration(options?: StorageOptions): Promise<boolean> {
|
||||
return (
|
||||
(await this.getGlobals(this.reconcileOptions(options, await this.defaultOnDiskOptions())))
|
||||
?.enableDuckDuckGoBrowserIntegration ?? false
|
||||
);
|
||||
}
|
||||
|
||||
async setEnableDuckDuckGoBrowserIntegration(
|
||||
value: boolean,
|
||||
options?: StorageOptions,
|
||||
): Promise<void> {
|
||||
const globals = await this.getGlobals(
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions()),
|
||||
);
|
||||
globals.enableDuckDuckGoBrowserIntegration = value;
|
||||
await this.saveGlobals(
|
||||
globals,
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions()),
|
||||
);
|
||||
}
|
||||
|
||||
@withPrototypeForObjectValues(CipherData)
|
||||
async getEncryptedCiphers(options?: StorageOptions): Promise<{ [id: string]: CipherData }> {
|
||||
return (
|
||||
|
||||
@@ -43,6 +43,7 @@ import { UserDecryptionOptionsMigrator } from "./migrations/44-move-user-decrypt
|
||||
import { MergeEnvironmentState } from "./migrations/45-merge-environment-state";
|
||||
import { DeleteBiometricPromptCancelledData } from "./migrations/46-delete-orphaned-biometric-prompt-data";
|
||||
import { MoveDesktopSettingsMigrator } from "./migrations/47-move-desktop-settings";
|
||||
import { MoveDdgToStateProviderMigrator } from "./migrations/48-move-ddg-to-state-provider";
|
||||
import { AddKeyTypeToOrgKeysMigrator } from "./migrations/5-add-key-type-to-org-keys";
|
||||
import { RemoveLegacyEtmKeyMigrator } from "./migrations/6-remove-legacy-etm-key";
|
||||
import { MoveBiometricAutoPromptToAccount } from "./migrations/7-move-biometric-auto-prompt-to-account";
|
||||
@@ -51,7 +52,8 @@ import { MoveBrowserSettingsToGlobal } from "./migrations/9-move-browser-setting
|
||||
import { MinVersionMigrator } from "./migrations/min-version";
|
||||
|
||||
export const MIN_VERSION = 3;
|
||||
export const CURRENT_VERSION = 47;
|
||||
export const CURRENT_VERSION = 48;
|
||||
|
||||
export type MinVersion = typeof MIN_VERSION;
|
||||
|
||||
export function createMigrationBuilder() {
|
||||
@@ -100,7 +102,8 @@ export function createMigrationBuilder() {
|
||||
.with(UserDecryptionOptionsMigrator, 43, 44)
|
||||
.with(MergeEnvironmentState, 44, 45)
|
||||
.with(DeleteBiometricPromptCancelledData, 45, 46)
|
||||
.with(MoveDesktopSettingsMigrator, 46, CURRENT_VERSION);
|
||||
.with(MoveDesktopSettingsMigrator, 46, 47)
|
||||
.with(MoveDdgToStateProviderMigrator, 47, CURRENT_VERSION);
|
||||
}
|
||||
|
||||
export async function currentVersion(
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { runMigrator } from "../migration-helper.spec";
|
||||
|
||||
import { MoveDdgToStateProviderMigrator } from "./48-move-ddg-to-state-provider";
|
||||
|
||||
describe("MoveDdgToStateProviderMigrator", () => {
|
||||
const migrator = new MoveDdgToStateProviderMigrator(47, 48);
|
||||
|
||||
it("migrate", async () => {
|
||||
const output = await runMigrator(migrator, {
|
||||
global: {
|
||||
enableDuckDuckGoBrowserIntegration: true,
|
||||
otherStuff: "otherStuff1",
|
||||
},
|
||||
otherStuff: "otherStuff2",
|
||||
});
|
||||
|
||||
expect(output).toEqual({
|
||||
global_autofillSettings_enableDuckDuckGoBrowserIntegration: true,
|
||||
global: {
|
||||
otherStuff: "otherStuff1",
|
||||
},
|
||||
otherStuff: "otherStuff2",
|
||||
});
|
||||
});
|
||||
|
||||
it("rollback", async () => {
|
||||
const output = await runMigrator(
|
||||
migrator,
|
||||
{
|
||||
global_autofillSettings_enableDuckDuckGoBrowserIntegration: true,
|
||||
global: {
|
||||
otherStuff: "otherStuff1",
|
||||
},
|
||||
otherStuff: "otherStuff2",
|
||||
},
|
||||
"rollback",
|
||||
);
|
||||
|
||||
expect(output).toEqual({
|
||||
global: {
|
||||
enableDuckDuckGoBrowserIntegration: true,
|
||||
otherStuff: "otherStuff1",
|
||||
},
|
||||
otherStuff: "otherStuff2",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { KeyDefinitionLike, MigrationHelper } from "../migration-helper";
|
||||
import { Migrator } from "../migrator";
|
||||
|
||||
type ExpectedGlobal = {
|
||||
enableDuckDuckGoBrowserIntegration?: boolean;
|
||||
};
|
||||
|
||||
export const DDG_KEY: KeyDefinitionLike = {
|
||||
key: "enableDuckDuckGoBrowserIntegration",
|
||||
stateDefinition: {
|
||||
name: "autofillSettings",
|
||||
},
|
||||
};
|
||||
|
||||
export class MoveDdgToStateProviderMigrator extends Migrator<47, 48> {
|
||||
async migrate(helper: MigrationHelper): Promise<void> {
|
||||
// global state
|
||||
const global = await helper.get<ExpectedGlobal>("global");
|
||||
if (global?.enableDuckDuckGoBrowserIntegration == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
await helper.setToGlobal(DDG_KEY, global.enableDuckDuckGoBrowserIntegration);
|
||||
delete global.enableDuckDuckGoBrowserIntegration;
|
||||
await helper.set("global", global);
|
||||
}
|
||||
|
||||
async rollback(helper: MigrationHelper): Promise<void> {
|
||||
const enableDdg = await helper.getFromGlobal<boolean>(DDG_KEY);
|
||||
|
||||
if (!enableDdg) {
|
||||
return;
|
||||
}
|
||||
|
||||
const global = (await helper.get<ExpectedGlobal>("global")) ?? {};
|
||||
global.enableDuckDuckGoBrowserIntegration = enableDdg;
|
||||
await helper.set("global", global);
|
||||
await helper.removeFromGlobal(DDG_KEY);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user