1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 17:53:39 +00:00

[PM-5572] Event upload and collection state provider migration (#7863)

* event upload and collection state provider migration

* cipher can be null when exporting org

* Addressing pr comments. Casting UserId from calling methods

* fixing userAuth observable in event collection service

* Adding more documentation for the changes.

* cli needed state provider and account services added

* Addressing pr comments on modifying should update

* No need to auth on event upload

* Simplifying the takeEvents for pulling user events

* Reverting shouldUpdate to previous state

* Removing redundant comment

* Removing account service for event upload

* Modifying the shouldUpdate to evaluate the logic outside of the observable

* Adding back in the auth for event upload service and adding event upload to the cli logout method

* Adding the browser service factories

* Updating the browser services away from get background

* Removing event collect and upload services from browser services

* Removing the audit service import

* Adding the event collection migration and migration test

* Event collection state needs to be stored on disk

* removing event collection from state service and abstraction

* removing event collection from the account data

* Saving the migrations themselves
This commit is contained in:
Tom
2024-03-18 14:36:43 -04:00
committed by GitHub
parent 2b92c7dd10
commit cc28149e60
19 changed files with 381 additions and 97 deletions

View File

@@ -727,14 +727,16 @@ export default class MainBackground {
);
this.eventUploadService = new EventUploadService(
this.apiService,
this.stateService,
this.stateProvider,
this.logService,
this.accountService,
);
this.eventCollectionService = new EventCollectionService(
this.cipherService,
this.stateService,
this.stateProvider,
this.organizationService,
this.eventUploadService,
this.accountService,
);
this.totpService = new TotpService(this.cryptoFunctionService, this.logService);
@@ -1108,7 +1110,7 @@ export default class MainBackground {
async logout(expired: boolean, userId?: UserId) {
userId ??= (await firstValueFrom(this.accountService.activeAccount$))?.id;
await this.eventUploadService.uploadEvents(userId);
await this.eventUploadService.uploadEvents(userId as UserId);
await Promise.all([
this.syncService.setLastSync(new Date(0), userId),

View File

@@ -5,15 +5,14 @@ import {
organizationServiceFactory,
OrganizationServiceInitOptions,
} from "../../admin-console/background/service-factories/organization-service.factory";
import { accountServiceFactory } from "../../auth/background/service-factories/account-service.factory";
import {
FactoryOptions,
CachedServices,
factory,
} from "../../platform/background/service-factories/factory-options";
import {
stateServiceFactory,
StateServiceInitOptions,
} from "../../platform/background/service-factories/state-service.factory";
import { stateProviderFactory } from "../../platform/background/service-factories/state-provider.factory";
import { StateServiceInitOptions } from "../../platform/background/service-factories/state-service.factory";
import {
cipherServiceFactory,
CipherServiceInitOptions,
@@ -43,9 +42,10 @@ export function eventCollectionServiceFactory(
async () =>
new EventCollectionService(
await cipherServiceFactory(cache, opts),
await stateServiceFactory(cache, opts),
await stateProviderFactory(cache, opts),
await organizationServiceFactory(cache, opts),
await eventUploadServiceFactory(cache, opts),
await accountServiceFactory(cache, opts),
),
);
}

View File

@@ -1,6 +1,7 @@
import { EventUploadService as AbstractEventUploadService } from "@bitwarden/common/abstractions/event/event-upload.service";
import { EventUploadService } from "@bitwarden/common/services/event/event-upload.service";
import { accountServiceFactory } from "../../auth/background/service-factories/account-service.factory";
import {
ApiServiceInitOptions,
apiServiceFactory,
@@ -14,10 +15,8 @@ import {
logServiceFactory,
LogServiceInitOptions,
} from "../../platform/background/service-factories/log-service.factory";
import {
stateServiceFactory,
StateServiceInitOptions,
} from "../../platform/background/service-factories/state-service.factory";
import { stateProviderFactory } from "../../platform/background/service-factories/state-provider.factory";
import { StateServiceInitOptions } from "../../platform/background/service-factories/state-service.factory";
type EventUploadServiceOptions = FactoryOptions;
@@ -37,8 +36,9 @@ export function eventUploadServiceFactory(
async () =>
new EventUploadService(
await apiServiceFactory(cache, opts),
await stateServiceFactory(cache, opts),
await stateProviderFactory(cache, opts),
await logServiceFactory(cache, opts),
await accountServiceFactory(cache, opts),
),
);
}

View File

@@ -17,8 +17,6 @@ import {
LoginStrategyServiceAbstraction,
} from "@bitwarden/auth/common";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { EventUploadService } from "@bitwarden/common/abstractions/event/event-upload.service";
import { NotificationsService } from "@bitwarden/common/abstractions/notifications.service";
import { SearchService as SearchServiceAbstraction } from "@bitwarden/common/abstractions/search.service";
import { SettingsService } from "@bitwarden/common/abstractions/settings.service";
@@ -263,16 +261,6 @@ function getBgService<T>(service: keyof MainBackground) {
useFactory: getBgService<DevicesServiceAbstraction>("devicesService"),
deps: [],
},
{
provide: EventUploadService,
useFactory: getBgService<EventUploadService>("eventUploadService"),
deps: [],
},
{
provide: EventCollectionService,
useFactory: getBgService<EventCollectionService>("eventCollectionService"),
deps: [],
},
{
provide: PlatformUtilsService,
useExisting: ForegroundPlatformUtilsService,