1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-06 19:53:59 +00:00

Remove Injectable decorator from class, use safeProvider.

This commit is contained in:
Miles Blackwood
2025-06-12 13:41:07 -04:00
parent 3e88388827
commit f6b49b0404
4 changed files with 31 additions and 32 deletions

View File

@@ -43,7 +43,7 @@ import { LoginView } from "@bitwarden/common/vault/models/view/login.view";
import { TaskService } from "@bitwarden/common/vault/tasks";
import { SecurityTaskType } from "@bitwarden/common/vault/tasks/enums";
import { SecurityTask } from "@bitwarden/common/vault/tasks/models/security-task";
import { DefaultChangeLoginPasswordService } from "@bitwarden/vault";
import { ChangeLoginPasswordService } from "@bitwarden/vault";
import { openUnlockPopout } from "../../auth/popup/utils/auth-popout-window";
import { BrowserApi } from "../../platform/browser/browser-api";
@@ -140,6 +140,7 @@ export default class NotificationBackground {
private themeStateService: ThemeStateService,
private userNotificationSettingsService: UserNotificationSettingsServiceAbstraction,
private taskService: TaskService,
private changeLoginPasswordService: ChangeLoginPasswordService,
protected messagingService: MessagingService,
) {}
@@ -401,10 +402,7 @@ export default class NotificationBackground {
): Promise<boolean> {
const { activeUserId, securityTask, cipher } = message.data;
const domain = Utils.getDomain(sender.tab.url);
const passwordChangeUri = await DefaultChangeLoginPasswordService.create(
{ nativeFetch: fetch },
{ getClientType: () => "browser" },
).getChangePasswordUrl(cipher);
const passwordChangeUri = await this.changeLoginPasswordService.getChangePasswordUrl(cipher);
const authStatus = await this.getAuthStatus();

View File

@@ -229,6 +229,7 @@ import {
KeyService as KeyServiceAbstraction,
} from "@bitwarden/key-management";
import { BackgroundSyncService } from "@bitwarden/platform/background-sync";
import { ChangeLoginPasswordService, DefaultChangeLoginPasswordService } from "@bitwarden/vault";
import {
IndividualVaultExportService,
IndividualVaultExportServiceAbstraction,
@@ -415,6 +416,8 @@ export default class MainBackground {
ipcContentScriptManagerService: IpcContentScriptManagerService;
ipcService: IpcService;
changeLoginPasswordService: ChangeLoginPasswordService;
onUpdatedRan: boolean;
onReplacedRan: boolean;
loginToAutoFill: CipherView = null;
@@ -1208,6 +1211,11 @@ export default class MainBackground {
messageListener,
);
this.changeLoginPasswordService = new DefaultChangeLoginPasswordService(
this.apiService,
this.platformUtilsService,
);
this.notificationBackground = new NotificationBackground(
this.accountService,
this.authService,
@@ -1224,6 +1232,7 @@ export default class MainBackground {
this.themeStateService,
this.userNotificationSettingsService,
this.taskService,
this.changeLoginPasswordService,
this.messagingService,
);

View File

@@ -187,7 +187,10 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platfor
import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import {
PlatformUtilsService,
PlatformUtilsService as PlatformUtilsServiceAbstraction,
} from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service";
@@ -324,7 +327,11 @@ import {
import { SafeInjectionToken } from "@bitwarden/ui-common";
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
// eslint-disable-next-line no-restricted-imports
import { PasswordRepromptService } from "@bitwarden/vault";
import {
ChangeLoginPasswordService,
DefaultChangeLoginPasswordService,
PasswordRepromptService,
} from "@bitwarden/vault";
import {
IndividualVaultExportService,
IndividualVaultExportServiceAbstraction,
@@ -1559,6 +1566,11 @@ const safeProviders: SafeProvider[] = [
InternalMasterPasswordServiceAbstraction,
],
}),
safeProvider({
provide: ChangeLoginPasswordService,
useClass: DefaultChangeLoginPasswordService,
deps: [ApiService, PlatformUtilsService],
}),
];
@NgModule({

View File

@@ -1,36 +1,16 @@
import { Inject, Injectable } from "@angular/core";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CipherType } from "@bitwarden/common/vault/enums";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { ChangeLoginPasswordService } from "../abstractions/change-login-password.service";
interface PartialApiService {
nativeFetch(request: Request): Promise<Response>;
}
interface PartialPlatformUtilsService {
getClientType(): string;
}
@Injectable()
export class DefaultChangeLoginPasswordService implements ChangeLoginPasswordService {
private apiService: PartialApiService;
private platformUtilsService: PartialPlatformUtilsService;
constructor(
@Inject("ApiService") apiService: PartialApiService,
@Inject("PlatformUtilsService") platformUtilsService: PartialPlatformUtilsService,
) {
this.apiService = apiService;
this.platformUtilsService = platformUtilsService;
}
static create(apiService: PartialApiService, platformUtilsService: PartialPlatformUtilsService) {
const instance = new DefaultChangeLoginPasswordService(null!, null!);
instance.apiService = apiService;
instance.platformUtilsService = platformUtilsService;
return instance;
}
private apiService: ApiService,
private platformUtilsService: PlatformUtilsService,
) {}
/**
* @inheritDoc