fix notification bar content script using old server config state storage (#8618)
This commit is contained in:
parent
8ae44b13ed
commit
216bbdb44c
|
@ -1,4 +1,5 @@
|
|||
import { NeverDomains } from "@bitwarden/common/models/domain/domain-service";
|
||||
import { ServerConfig } from "@bitwarden/common/platform/abstractions/config/server-config";
|
||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
|
||||
import { NotificationQueueMessageTypes } from "../../enums/notification-queue-message-type.enum";
|
||||
|
@ -113,6 +114,7 @@ type NotificationBackgroundExtensionMessageHandlers = {
|
|||
bgGetEnableChangedPasswordPrompt: () => Promise<boolean>;
|
||||
bgGetEnableAddedLoginPrompt: () => Promise<boolean>;
|
||||
bgGetExcludedDomains: () => Promise<NeverDomains>;
|
||||
bgGetActiveUserServerConfig: () => Promise<ServerConfig>;
|
||||
getWebVaultUrlForNotification: () => Promise<string>;
|
||||
};
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authenticatio
|
|||
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
|
||||
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
|
||||
import { UserNotificationSettingsService } from "@bitwarden/common/autofill/services/user-notification-settings.service";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { SelfHostedEnvironment } from "@bitwarden/common/platform/services/default-environment.service";
|
||||
|
@ -54,6 +55,7 @@ describe("NotificationBackground", () => {
|
|||
const environmentService = mock<EnvironmentService>();
|
||||
const logService = mock<LogService>();
|
||||
const themeStateService = mock<ThemeStateService>();
|
||||
const configService = mock<ConfigService>();
|
||||
|
||||
beforeEach(() => {
|
||||
notificationBackground = new NotificationBackground(
|
||||
|
@ -68,6 +70,7 @@ describe("NotificationBackground", () => {
|
|||
environmentService,
|
||||
logService,
|
||||
themeStateService,
|
||||
configService,
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ import { NOTIFICATION_BAR_LIFESPAN_MS } from "@bitwarden/common/autofill/constan
|
|||
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
|
||||
import { UserNotificationSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/user-notification-settings.service";
|
||||
import { NeverDomains } from "@bitwarden/common/models/domain/domain-service";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { ServerConfig } from "@bitwarden/common/platform/abstractions/config/server-config";
|
||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
|
@ -64,6 +66,7 @@ export default class NotificationBackground {
|
|||
bgGetEnableChangedPasswordPrompt: () => this.getEnableChangedPasswordPrompt(),
|
||||
bgGetEnableAddedLoginPrompt: () => this.getEnableAddedLoginPrompt(),
|
||||
bgGetExcludedDomains: () => this.getExcludedDomains(),
|
||||
bgGetActiveUserServerConfig: () => this.getActiveUserServerConfig(),
|
||||
getWebVaultUrlForNotification: () => this.getWebVaultUrl(),
|
||||
};
|
||||
|
||||
|
@ -79,6 +82,7 @@ export default class NotificationBackground {
|
|||
private environmentService: EnvironmentService,
|
||||
private logService: LogService,
|
||||
private themeStateService: ThemeStateService,
|
||||
private configService: ConfigService,
|
||||
) {}
|
||||
|
||||
async init() {
|
||||
|
@ -112,6 +116,13 @@ export default class NotificationBackground {
|
|||
return await firstValueFrom(this.domainSettingsService.neverDomains$);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the active user server config from the config service.
|
||||
*/
|
||||
async getActiveUserServerConfig(): Promise<ServerConfig> {
|
||||
return await firstValueFrom(this.configService.serverConfig$);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the notification queue for any messages that need to be sent to the
|
||||
* specified tab. If no tab is specified, the current tab will be used.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ServerConfig } from "../../../../../libs/common/src/platform/abstractions/config/server-config";
|
||||
import {
|
||||
AddLoginMessageData,
|
||||
ChangePasswordMessageData,
|
||||
|
@ -6,12 +7,7 @@ import AutofillField from "../models/autofill-field";
|
|||
import { WatchedForm } from "../models/watched-form";
|
||||
import { NotificationBarIframeInitData } from "../notification/abstractions/notification-bar";
|
||||
import { FormData } from "../services/abstractions/autofill.service";
|
||||
import { UserSettings } from "../types";
|
||||
import {
|
||||
getFromLocalStorage,
|
||||
sendExtensionMessage,
|
||||
setupExtensionDisconnectAction,
|
||||
} from "../utils";
|
||||
import { sendExtensionMessage, setupExtensionDisconnectAction } from "../utils";
|
||||
|
||||
interface HTMLElementWithFormOpId extends HTMLElement {
|
||||
formOpId: string;
|
||||
|
@ -95,25 +91,17 @@ async function loadNotificationBar() {
|
|||
);
|
||||
const enableAddedLoginPrompt = await sendExtensionMessage("bgGetEnableAddedLoginPrompt");
|
||||
const excludedDomains = await sendExtensionMessage("bgGetExcludedDomains");
|
||||
const activeUserServerConfig: ServerConfig = await sendExtensionMessage(
|
||||
"bgGetActiveUserServerConfig",
|
||||
);
|
||||
const activeUserVault = activeUserServerConfig?.environment?.vault;
|
||||
|
||||
let showNotificationBar = true;
|
||||
// Look up the active user id from storage
|
||||
const activeUserIdKey = "activeUserId";
|
||||
let activeUserId: string;
|
||||
|
||||
const activeUserStorageValue = await getFromLocalStorage(activeUserIdKey);
|
||||
if (activeUserStorageValue[activeUserIdKey]) {
|
||||
activeUserId = activeUserStorageValue[activeUserIdKey];
|
||||
}
|
||||
|
||||
// Look up the user's settings from storage
|
||||
const userSettingsStorageValue = await getFromLocalStorage(activeUserId);
|
||||
if (userSettingsStorageValue[activeUserId]) {
|
||||
const userSettings: UserSettings = userSettingsStorageValue[activeUserId].settings;
|
||||
|
||||
if (activeUserVault) {
|
||||
// Do not show the notification bar on the Bitwarden vault
|
||||
// because they can add logins and change passwords there
|
||||
if (window.location.origin === userSettings.serverConfig.environment.vault) {
|
||||
if (window.location.origin === activeUserVault) {
|
||||
showNotificationBar = false;
|
||||
} else {
|
||||
// NeverDomains is a dictionary of domains that the user has chosen to never
|
||||
|
|
|
@ -908,6 +908,7 @@ export default class MainBackground {
|
|||
this.environmentService,
|
||||
this.logService,
|
||||
themeStateService,
|
||||
this.configService,
|
||||
);
|
||||
this.overlayBackground = new OverlayBackground(
|
||||
this.cipherService,
|
||||
|
|
Loading…
Reference in New Issue