mirror of
https://github.com/bitwarden/browser
synced 2026-01-05 01:53:55 +00:00
[PM-24677] Slim StateService down so it can be moved to state lib (#16021)
* Slim StateService down so it can be moved to state lib * Fix accidental import changes * Add `switchAccount` assertion * Needs to use mock
This commit is contained in:
@@ -9,6 +9,7 @@ import { CollectionService } from "@bitwarden/admin-console/common";
|
||||
import { ApiService } from "../../abstractions/api.service";
|
||||
import { AccountService } from "../../auth/abstractions/account.service";
|
||||
import { AuthService } from "../../auth/abstractions/auth.service";
|
||||
import { TokenService } from "../../auth/abstractions/token.service";
|
||||
import { AuthenticationStatus } from "../../auth/enums/authentication-status";
|
||||
import {
|
||||
SyncCipherNotification,
|
||||
@@ -26,7 +27,6 @@ import { SyncService } from "../../vault/abstractions/sync/sync.service.abstract
|
||||
import { CipherData } from "../../vault/models/data/cipher.data";
|
||||
import { FolderData } from "../../vault/models/data/folder.data";
|
||||
import { LogService } from "../abstractions/log.service";
|
||||
import { StateService } from "../abstractions/state.service";
|
||||
import { MessageSender } from "../messaging";
|
||||
import { StateProvider, SYNC_DISK, UserKeyDefinition } from "../state";
|
||||
|
||||
@@ -44,7 +44,7 @@ export abstract class CoreSyncService implements SyncService {
|
||||
syncInProgress = false;
|
||||
|
||||
constructor(
|
||||
protected readonly stateService: StateService,
|
||||
readonly tokenService: TokenService,
|
||||
protected readonly folderService: InternalFolderService,
|
||||
protected readonly folderApiService: FolderApiServiceAbstraction,
|
||||
protected readonly messageSender: MessageSender,
|
||||
@@ -256,7 +256,13 @@ export abstract class CoreSyncService implements SyncService {
|
||||
|
||||
async syncDeleteSend(notification: SyncSendNotification): Promise<boolean> {
|
||||
this.syncStarted();
|
||||
if (await this.stateService.getIsAuthenticated()) {
|
||||
const activeUserId = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
||||
);
|
||||
if (
|
||||
activeUserId != null &&
|
||||
(await firstValueFrom(this.tokenService.hasAccessToken$(activeUserId)))
|
||||
) {
|
||||
await this.sendService.delete(notification.id);
|
||||
this.messageSender.send("syncedDeletedSend", { sendId: notification.id });
|
||||
// TODO: Update syncCompleted userId when send service allows modification of non-active users
|
||||
|
||||
@@ -36,7 +36,6 @@ import { CipherService } from "../../vault/abstractions/cipher.service";
|
||||
import { FolderApiServiceAbstraction } from "../../vault/abstractions/folder/folder-api.service.abstraction";
|
||||
import { InternalFolderService } from "../../vault/abstractions/folder/folder.service.abstraction";
|
||||
import { LogService } from "../abstractions/log.service";
|
||||
import { StateService } from "../abstractions/state.service";
|
||||
import { MessageSender } from "../messaging";
|
||||
import { StateProvider } from "../state";
|
||||
|
||||
@@ -57,7 +56,6 @@ describe("DefaultSyncService", () => {
|
||||
let sendService: MockProxy<InternalSendService>;
|
||||
let logService: MockProxy<LogService>;
|
||||
let keyConnectorService: MockProxy<KeyConnectorService>;
|
||||
let stateService: MockProxy<StateService>;
|
||||
let providerService: MockProxy<ProviderService>;
|
||||
let folderApiService: MockProxy<FolderApiServiceAbstraction>;
|
||||
let organizationService: MockProxy<InternalOrganizationServiceAbstraction>;
|
||||
@@ -86,7 +84,6 @@ describe("DefaultSyncService", () => {
|
||||
sendService = mock();
|
||||
logService = mock();
|
||||
keyConnectorService = mock();
|
||||
stateService = mock();
|
||||
providerService = mock();
|
||||
folderApiService = mock();
|
||||
organizationService = mock();
|
||||
@@ -113,7 +110,6 @@ describe("DefaultSyncService", () => {
|
||||
sendService,
|
||||
logService,
|
||||
keyConnectorService,
|
||||
stateService,
|
||||
providerService,
|
||||
folderApiService,
|
||||
organizationService,
|
||||
|
||||
@@ -53,7 +53,6 @@ import { FolderData } from "../../vault/models/data/folder.data";
|
||||
import { CipherResponse } from "../../vault/models/response/cipher.response";
|
||||
import { FolderResponse } from "../../vault/models/response/folder.response";
|
||||
import { LogService } from "../abstractions/log.service";
|
||||
import { StateService } from "../abstractions/state.service";
|
||||
import { MessageSender } from "../messaging";
|
||||
import { StateProvider } from "../state";
|
||||
|
||||
@@ -87,7 +86,6 @@ export class DefaultSyncService extends CoreSyncService {
|
||||
sendService: InternalSendService,
|
||||
logService: LogService,
|
||||
private keyConnectorService: KeyConnectorService,
|
||||
stateService: StateService,
|
||||
private providerService: ProviderService,
|
||||
folderApiService: FolderApiServiceAbstraction,
|
||||
private organizationService: InternalOrganizationServiceAbstraction,
|
||||
@@ -96,12 +94,12 @@ export class DefaultSyncService extends CoreSyncService {
|
||||
private avatarService: AvatarService,
|
||||
private logoutCallback: (logoutReason: LogoutReason, userId?: UserId) => Promise<void>,
|
||||
private billingAccountProfileStateService: BillingAccountProfileStateService,
|
||||
private tokenService: TokenService,
|
||||
tokenService: TokenService,
|
||||
authService: AuthService,
|
||||
stateProvider: StateProvider,
|
||||
) {
|
||||
super(
|
||||
stateService,
|
||||
tokenService,
|
||||
folderService,
|
||||
folderApiService,
|
||||
messageSender,
|
||||
|
||||
Reference in New Issue
Block a user