1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 02:33:46 +00:00
Files
browser/apps/web/src/app/organizations/vault/add-edit.component.ts
Daniel James Smith 200dd0a1fb [PS-1906] Extract uploadEvents from EventService into new service (#4108)
* Move event.service to it's own folder

Move abstractions/event.service to abstractions/event/event.service
Move services/event.service to services/event/event.service
Fix all the imports

* Extract event-upload from event.service

Move `uploadEvents` from `EventService` to `EventUploadService`
Create event-upload-service-factory
Fix wiring up all the dependencies

* Remove clearEvents from EventService

clearEvents is only related to uploading events and can be moved into EventUploadService

Change the logout-method to only call EventUploadService.uploadEvents as that also calls clearEvents internally

* Rename EventService to EventCollectionService

Rename libs\common\abstraction\event\event.service.ts to libs\common\abstractions\event\event-collection.service.ts

Rename libs\common\services\event\event.service.ts to libs\common\services\event\event-collection.service.ts

Fix all the imports

Fix up service regristration/instantiation

Reanme \browser\src\background\service_factories\event-service.factory.ts to \browser\src\background\service_factories\event-collection-service.factory.ts

* Move interval to upload events to EventUploadSvc

Move the `init()` from event-collection.service to event-upload.service
Change call-site in web, desktop, browser
2022-12-06 14:47:42 +01:00

133 lines
4.9 KiB
TypeScript

import { Component } from "@angular/core";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service";
import { PasswordRepromptService } from "@bitwarden/common/abstractions/passwordReprompt.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { TotpService } from "@bitwarden/common/abstractions/totp.service";
import { CipherData } from "@bitwarden/common/models/data/cipher.data";
import { Cipher } from "@bitwarden/common/models/domain/cipher";
import { CipherCreateRequest } from "@bitwarden/common/models/request/cipher-create.request";
import { CipherRequest } from "@bitwarden/common/models/request/cipher.request";
import { AddEditComponent as BaseAddEditComponent } from "../../vault/add-edit.component";
@Component({
selector: "app-org-vault-add-edit",
templateUrl: "../../vault/add-edit.component.html",
})
export class AddEditComponent extends BaseAddEditComponent {
originalCipher: Cipher = null;
constructor(
cipherService: CipherService,
folderService: FolderService,
i18nService: I18nService,
platformUtilsService: PlatformUtilsService,
auditService: AuditService,
stateService: StateService,
collectionService: CollectionService,
totpService: TotpService,
passwordGenerationService: PasswordGenerationService,
private apiService: ApiService,
messagingService: MessagingService,
eventCollectionService: EventCollectionService,
policyService: PolicyService,
logService: LogService,
passwordRepromptService: PasswordRepromptService,
organizationService: OrganizationService
) {
super(
cipherService,
folderService,
i18nService,
platformUtilsService,
auditService,
stateService,
collectionService,
totpService,
passwordGenerationService,
messagingService,
eventCollectionService,
policyService,
organizationService,
logService,
passwordRepromptService
);
}
protected allowOwnershipAssignment() {
if (
this.ownershipOptions != null &&
(this.ownershipOptions.length > 1 || !this.allowPersonal)
) {
if (this.organization != null) {
return this.cloneMode && this.organization.canEditAnyCollection;
} else {
return !this.editMode || this.cloneMode;
}
}
return false;
}
protected loadCollections() {
if (!this.organization.canEditAnyCollection) {
return super.loadCollections();
}
return Promise.resolve(this.collections);
}
protected async loadCipher() {
if (!this.organization.canEditAnyCollection) {
return await super.loadCipher();
}
const response = await this.apiService.getCipherAdmin(this.cipherId);
const data = new CipherData(response);
data.edit = true;
const cipher = new Cipher(data);
this.originalCipher = cipher;
return cipher;
}
protected encryptCipher() {
if (!this.organization.canEditAnyCollection) {
return super.encryptCipher();
}
return this.cipherService.encrypt(this.cipher, null, this.originalCipher);
}
protected async saveCipher(cipher: Cipher) {
if (!this.organization.canEditAnyCollection || cipher.organizationId == null) {
return super.saveCipher(cipher);
}
if (this.editMode && !this.cloneMode) {
const request = new CipherRequest(cipher);
return this.apiService.putCipherAdmin(this.cipherId, request);
} else {
const request = new CipherCreateRequest(cipher);
return this.apiService.postCipherAdmin(request);
}
}
protected async deleteCipher() {
if (!this.organization.canEditAnyCollection) {
return super.deleteCipher();
}
return this.cipher.isDeleted
? this.apiService.deleteCipherAdmin(this.cipherId)
: this.apiService.putDeleteCipherAdmin(this.cipherId);
}
}