diff --git a/apps/web/src/app/shared/loose-components.module.ts b/apps/web/src/app/shared/loose-components.module.ts index 5de56789cad..5dc34b3b5b1 100644 --- a/apps/web/src/app/shared/loose-components.module.ts +++ b/apps/web/src/app/shared/loose-components.module.ts @@ -57,13 +57,9 @@ import { WeakPasswordsReportComponent as OrgWeakPasswordsReportComponent } from /* eslint no-restricted-imports: "error" */ import { PremiumBadgeComponent } from "../vault/components/premium-badge.component"; import { AddEditCustomFieldsComponent } from "../vault/individual-vault/add-edit-custom-fields.component"; -import { AddEditComponent } from "../vault/individual-vault/add-edit.component"; -import { AttachmentsComponent } from "../vault/individual-vault/attachments.component"; import { FolderAddEditComponent } from "../vault/individual-vault/folder-add-edit.component"; import { OrganizationBadgeModule } from "../vault/individual-vault/organization-badge/organization-badge.module"; import { PipesModule } from "../vault/individual-vault/pipes/pipes.module"; -import { AddEditComponent as OrgAddEditComponent } from "../vault/org-vault/add-edit.component"; -import { AttachmentsComponent as OrgAttachmentsComponent } from "../vault/org-vault/attachments.component"; import { PurgeVaultComponent } from "../vault/settings/purge-vault.component"; import { EnvironmentSelectorModule } from "./../components/environment-selector/environment-selector.module"; @@ -97,11 +93,9 @@ import { SharedModule } from "./shared.module"; declarations: [ AcceptFamilySponsorshipComponent, AccountComponent, - AddEditComponent, AddEditCustomFieldsComponent, AddEditCustomFieldsComponent, ApiKeyComponent, - AttachmentsComponent, ChangeEmailComponent, DeauthorizeSessionsComponent, DeleteAccountDialogComponent, @@ -113,8 +107,6 @@ import { SharedModule } from "./shared.module"; EmergencyAccessViewComponent, FolderAddEditComponent, FrontendLayoutComponent, - OrgAddEditComponent, - OrgAttachmentsComponent, OrgEventsComponent, OrgExposedPasswordsReportComponent, OrgInactiveTwoFactorReportComponent, @@ -146,11 +138,9 @@ import { SharedModule } from "./shared.module"; UserVerificationModule, PremiumBadgeComponent, AccountComponent, - AddEditComponent, AddEditCustomFieldsComponent, AddEditCustomFieldsComponent, ApiKeyComponent, - AttachmentsComponent, ChangeEmailComponent, DeauthorizeSessionsComponent, DeleteAccountDialogComponent, @@ -163,9 +153,7 @@ import { SharedModule } from "./shared.module"; EmergencyAccessViewComponent, FolderAddEditComponent, FrontendLayoutComponent, - OrgAddEditComponent, OrganizationLayoutComponent, - OrgAttachmentsComponent, OrgEventsComponent, OrgExposedPasswordsReportComponent, OrgInactiveTwoFactorReportComponent, diff --git a/apps/web/src/app/vault/individual-vault/add-edit.component.html b/apps/web/src/app/vault/individual-vault/add-edit.component.html deleted file mode 100644 index 29de65efcd5..00000000000 --- a/apps/web/src/app/vault/individual-vault/add-edit.component.html +++ /dev/null @@ -1,1112 +0,0 @@ - diff --git a/apps/web/src/app/vault/individual-vault/add-edit.component.ts b/apps/web/src/app/vault/individual-vault/add-edit.component.ts deleted file mode 100644 index d8739465938..00000000000 --- a/apps/web/src/app/vault/individual-vault/add-edit.component.ts +++ /dev/null @@ -1,315 +0,0 @@ -// FIXME: Update this file to be type safe and remove this and next line -// @ts-strict-ignore -import { DatePipe } from "@angular/common"; -import { Component, OnDestroy, OnInit } from "@angular/core"; -import { firstValueFrom, map } from "rxjs"; - -import { CollectionService } from "@bitwarden/admin-console/common"; -import { AddEditComponent as BaseAddEditComponent } from "@bitwarden/angular/vault/components/add-edit.component"; -import { AuditService } from "@bitwarden/common/abstractions/audit.service"; -import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; -import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; -import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; -import { isCardExpired } from "@bitwarden/common/autofill/utils"; -import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; -import { ProductTierType } from "@bitwarden/common/billing/enums"; -import { EventType } from "@bitwarden/common/enums"; -import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; -import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service"; -import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; -import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction"; -import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service"; -import { CipherType } from "@bitwarden/common/vault/enums"; -import { Launchable } from "@bitwarden/common/vault/interfaces/launchable"; -import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service"; -import { DialogService, ToastService } from "@bitwarden/components"; -import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; -import { PasswordRepromptService, SshImportPromptService } from "@bitwarden/vault"; - -@Component({ - selector: "app-vault-add-edit", - templateUrl: "add-edit.component.html", -}) -export class AddEditComponent extends BaseAddEditComponent implements OnInit, OnDestroy { - canAccessPremium: boolean; - totpCode: string; - totpCodeFormatted: string; - totpDash: number; - totpSec: number; - totpLow: boolean; - showRevisionDate = false; - hasPasswordHistory = false; - viewingPasswordHistory = false; - viewOnly = false; - showPasswordCount = false; - cardIsExpired: boolean = false; - - protected totpInterval: number; - protected override componentName = "app-vault-add-edit"; - - constructor( - cipherService: CipherService, - folderService: FolderService, - i18nService: I18nService, - platformUtilsService: PlatformUtilsService, - auditService: AuditService, - accountService: AccountService, - collectionService: CollectionService, - protected totpService: TotpService, - protected passwordGenerationService: PasswordGenerationServiceAbstraction, - protected messagingService: MessagingService, - eventCollectionService: EventCollectionService, - protected policyService: PolicyService, - organizationService: OrganizationService, - logService: LogService, - passwordRepromptService: PasswordRepromptService, - dialogService: DialogService, - datePipe: DatePipe, - configService: ConfigService, - private billingAccountProfileStateService: BillingAccountProfileStateService, - cipherAuthorizationService: CipherAuthorizationService, - toastService: ToastService, - sdkService: SdkService, - sshImportPromptService: SshImportPromptService, - ) { - super( - cipherService, - folderService, - i18nService, - platformUtilsService, - auditService, - accountService, - collectionService, - messagingService, - eventCollectionService, - policyService, - logService, - passwordRepromptService, - organizationService, - dialogService, - window, - datePipe, - configService, - cipherAuthorizationService, - toastService, - sdkService, - sshImportPromptService, - ); - } - - async ngOnInit() { - await super.ngOnInit(); - await this.load(); - - this.viewOnly = !this.cipher.edit && this.editMode; - // remove when all the title for all clients are updated to New Item - if (this.cloneMode || !this.editMode) { - this.title = this.i18nService.t("newItem"); - } - this.showRevisionDate = this.cipher.passwordRevisionDisplayDate != null; - this.hasPasswordHistory = this.cipher.hasPasswordHistory; - this.cleanUp(); - - const activeUserId = await firstValueFrom( - this.accountService.activeAccount$.pipe(map((a) => a.id)), - ); - - this.canAccessPremium = await firstValueFrom( - this.billingAccountProfileStateService.hasPremiumFromAnySource$(activeUserId), - ); - - if (this.showTotp()) { - await this.totpUpdateCode(); - const totpResponse = await firstValueFrom(this.totpService.getCode$(this.cipher.login.totp)); - if (totpResponse) { - const interval = totpResponse.period; - await this.totpTick(interval); - - this.totpInterval = window.setInterval(async () => { - await this.totpTick(interval); - }, 1000); - } - } - - this.cardIsExpired = isCardExpired(this.cipher.card); - } - - ngOnDestroy() { - super.ngOnDestroy(); - } - - toggleFavorite() { - this.cipher.favorite = !this.cipher.favorite; - } - - togglePassword() { - super.togglePassword(); - - // Hide password count when password is hidden to be safe - if (!this.showPassword && this.showPasswordCount) { - this.togglePasswordCount(); - } - } - - togglePasswordCount() { - this.showPasswordCount = !this.showPasswordCount; - - if (this.editMode && this.showPasswordCount) { - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.eventCollectionService.collect( - EventType.Cipher_ClientToggledPasswordVisible, - this.cipherId, - ); - } - } - - launch(uri: Launchable) { - if (!uri.canLaunch) { - return; - } - - this.platformUtilsService.launchUri(uri.launchUri); - } - - async copy(value: string, typeI18nKey: string, aType: string): Promise { - if (value == null) { - return false; - } - - this.platformUtilsService.copyToClipboard(value, { window: window }); - this.toastService.showToast({ - variant: "info", - title: null, - message: this.i18nService.t("valueCopied", this.i18nService.t(typeI18nKey)), - }); - - if (this.editMode) { - if (typeI18nKey === "password") { - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.eventCollectionService.collect(EventType.Cipher_ClientCopiedPassword, this.cipherId); - } else if (typeI18nKey === "securityCode") { - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.eventCollectionService.collect(EventType.Cipher_ClientCopiedCardCode, this.cipherId); - } else if (aType === "H_Field") { - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.eventCollectionService.collect( - EventType.Cipher_ClientCopiedHiddenField, - this.cipherId, - ); - } - } - - return true; - } - - async generatePassword(): Promise { - const confirmed = await super.generatePassword(); - if (confirmed) { - const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {}; - this.cipher.login.password = await this.passwordGenerationService.generatePassword(options); - } - return confirmed; - } - - premiumRequired() { - if (!this.canAccessPremium) { - this.messagingService.send("premiumRequired"); - return; - } - } - - upgradeOrganization() { - this.messagingService.send("upgradeOrganization", { - organizationId: this.cipher.organizationId, - }); - } - - showGetPremium() { - if (this.canAccessPremium) { - return; - } - if (this.cipher.organizationUseTotp) { - this.upgradeOrganization(); - } else { - this.premiumRequired(); - } - } - - viewHistory() { - this.viewingPasswordHistory = !this.viewingPasswordHistory; - } - - protected cleanUp() { - if (this.totpInterval) { - window.clearInterval(this.totpInterval); - } - } - - protected async totpUpdateCode() { - if ( - this.cipher == null || - this.cipher.type !== CipherType.Login || - this.cipher.login.totp == null - ) { - if (this.totpInterval) { - window.clearInterval(this.totpInterval); - } - return; - } - - const totpResponse = await firstValueFrom(this.totpService.getCode$(this.cipher.login.totp)); - this.totpCode = totpResponse?.code; - if (this.totpCode != null) { - if (this.totpCode.length > 4) { - const half = Math.floor(this.totpCode.length / 2); - this.totpCodeFormatted = - this.totpCode.substring(0, half) + " " + this.totpCode.substring(half); - } else { - this.totpCodeFormatted = this.totpCode; - } - } else { - this.totpCodeFormatted = null; - if (this.totpInterval) { - window.clearInterval(this.totpInterval); - } - } - } - - protected allowOwnershipAssignment() { - return ( - (!this.editMode || this.cloneMode) && - this.ownershipOptions != null && - (this.ownershipOptions.length > 1 || !this.allowPersonal) - ); - } - - protected showTotp() { - return ( - this.cipher.type === CipherType.Login && - this.cipher.login.totp && - this.organization?.productTierType != ProductTierType.Free && - (this.cipher.organizationUseTotp || this.canAccessPremium) - ); - } - - private async totpTick(intervalSeconds: number) { - const epoch = Math.round(new Date().getTime() / 1000.0); - const mod = epoch % intervalSeconds; - - this.totpSec = intervalSeconds - mod; - this.totpDash = +(Math.round(((78.6 / intervalSeconds) * mod + "e+2") as any) + "e-2"); - this.totpLow = this.totpSec <= 7; - if (mod === 0) { - await this.totpUpdateCode(); - } - } -} diff --git a/apps/web/src/app/vault/individual-vault/attachments.component.html b/apps/web/src/app/vault/individual-vault/attachments.component.html deleted file mode 100644 index d657cd7f6c3..00000000000 --- a/apps/web/src/app/vault/individual-vault/attachments.component.html +++ /dev/null @@ -1,120 +0,0 @@ - diff --git a/apps/web/src/app/vault/individual-vault/attachments.component.ts b/apps/web/src/app/vault/individual-vault/attachments.component.ts deleted file mode 100644 index c6079dbe78f..00000000000 --- a/apps/web/src/app/vault/individual-vault/attachments.component.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { Component } from "@angular/core"; - -import { AttachmentsComponent as BaseAttachmentsComponent } from "@bitwarden/angular/vault/components/attachments.component"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; -import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; -import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; -import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service"; -import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; -import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; -import { AttachmentView } from "@bitwarden/common/vault/models/view/attachment.view"; -import { DialogService, ToastService } from "@bitwarden/components"; -import { KeyService } from "@bitwarden/key-management"; - -@Component({ - selector: "app-vault-attachments", - templateUrl: "attachments.component.html", -}) -export class AttachmentsComponent extends BaseAttachmentsComponent { - protected override componentName = "app-vault-attachments"; - - constructor( - cipherService: CipherService, - i18nService: I18nService, - keyService: KeyService, - encryptService: EncryptService, - stateService: StateService, - platformUtilsService: PlatformUtilsService, - apiService: ApiService, - logService: LogService, - fileDownloadService: FileDownloadService, - dialogService: DialogService, - billingAccountProfileStateService: BillingAccountProfileStateService, - accountService: AccountService, - toastService: ToastService, - ) { - super( - cipherService, - i18nService, - keyService, - encryptService, - platformUtilsService, - apiService, - window, - logService, - stateService, - fileDownloadService, - dialogService, - billingAccountProfileStateService, - accountService, - toastService, - ); - } - - protected async reupload(attachment: AttachmentView) { - if (this.showFixOldAttachments(attachment)) { - await this.reuploadCipherAttachment(attachment, false); - } - } - - protected showFixOldAttachments(attachment: AttachmentView) { - return attachment.key == null && this.cipher.organizationId == null; - } -} diff --git a/apps/web/src/app/vault/org-vault/add-edit.component.ts b/apps/web/src/app/vault/org-vault/add-edit.component.ts deleted file mode 100644 index 89f3b79f1fb..00000000000 --- a/apps/web/src/app/vault/org-vault/add-edit.component.ts +++ /dev/null @@ -1,138 +0,0 @@ -// FIXME: Update this file to be type safe and remove this and next line -// @ts-strict-ignore -import { DatePipe } from "@angular/common"; -import { Component } from "@angular/core"; -import { firstValueFrom } from "rxjs"; - -import { CollectionService } from "@bitwarden/admin-console/common"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; -import { AuditService } from "@bitwarden/common/abstractions/audit.service"; -import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; -import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; -import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; -import { getUserId } from "@bitwarden/common/auth/services/account.service"; -import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; -import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; -import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service"; -import { UserId } from "@bitwarden/common/types/guid"; -import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; -import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction"; -import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service"; -import { CipherData } from "@bitwarden/common/vault/models/data/cipher.data"; -import { Cipher } from "@bitwarden/common/vault/models/domain/cipher"; -import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service"; -import { DialogService, ToastService } from "@bitwarden/components"; -import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; -import { PasswordRepromptService, SshImportPromptService } from "@bitwarden/vault"; - -import { AddEditComponent as BaseAddEditComponent } from "../individual-vault/add-edit.component"; - -@Component({ - selector: "app-org-vault-add-edit", - templateUrl: "../individual-vault/add-edit.component.html", -}) -export class AddEditComponent extends BaseAddEditComponent { - originalCipher: Cipher = null; - protected override componentName = "app-org-vault-add-edit"; - - constructor( - cipherService: CipherService, - folderService: FolderService, - i18nService: I18nService, - platformUtilsService: PlatformUtilsService, - auditService: AuditService, - accountService: AccountService, - collectionService: CollectionService, - totpService: TotpService, - passwordGenerationService: PasswordGenerationServiceAbstraction, - private apiService: ApiService, - messagingService: MessagingService, - eventCollectionService: EventCollectionService, - policyService: PolicyService, - logService: LogService, - passwordRepromptService: PasswordRepromptService, - organizationService: OrganizationService, - dialogService: DialogService, - datePipe: DatePipe, - configService: ConfigService, - billingAccountProfileStateService: BillingAccountProfileStateService, - cipherAuthorizationService: CipherAuthorizationService, - toastService: ToastService, - sdkService: SdkService, - sshImportPromptService: SshImportPromptService, - ) { - super( - cipherService, - folderService, - i18nService, - platformUtilsService, - auditService, - accountService, - collectionService, - totpService, - passwordGenerationService, - messagingService, - eventCollectionService, - policyService, - organizationService, - logService, - passwordRepromptService, - dialogService, - datePipe, - configService, - billingAccountProfileStateService, - cipherAuthorizationService, - toastService, - sdkService, - sshImportPromptService, - ); - } - - protected loadCollections() { - if (!this.organization.canEditAllCiphers) { - return super.loadCollections(); - } - return Promise.resolve(this.collections); - } - - protected async loadCipher() { - this.isAdminConsoleAction = true; - const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId)); - // Calling loadCipher first to assess if the cipher is unassigned. If null use apiService getCipherAdmin - const firstCipherCheck = await super.loadCipher(activeUserId); - - if (!this.organization.canEditAllCiphers && firstCipherCheck != null) { - return firstCipherCheck; - } - 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(userId: UserId) { - if (!this.organization.canEditAllCiphers) { - return super.encryptCipher(userId); - } - - return this.cipherService.encrypt(this.cipher, userId, null, null, this.originalCipher); - } - - protected async deleteCipher() { - if (!this.organization.canEditAllCiphers) { - const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId)); - return super.deleteCipher(activeUserId); - } - return this.cipher.isDeleted - ? this.apiService.deleteCipherAdmin(this.cipherId) - : this.apiService.putDeleteCipherAdmin(this.cipherId); - } -} diff --git a/apps/web/src/app/vault/org-vault/attachments.component.ts b/apps/web/src/app/vault/org-vault/attachments.component.ts deleted file mode 100644 index c2ad82bc27a..00000000000 --- a/apps/web/src/app/vault/org-vault/attachments.component.ts +++ /dev/null @@ -1,105 +0,0 @@ -// FIXME: Update this file to be type safe and remove this and next line -// @ts-strict-ignore -import { Component, OnInit } from "@angular/core"; -import { firstValueFrom } from "rxjs"; - -import { ApiService } from "@bitwarden/common/abstractions/api.service"; -import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; -import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; -import { getUserId } from "@bitwarden/common/auth/services/account.service"; -import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; -import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service"; -import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; -import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; -import { UserId } from "@bitwarden/common/types/guid"; -import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; -import { CipherData } from "@bitwarden/common/vault/models/data/cipher.data"; -import { Cipher } from "@bitwarden/common/vault/models/domain/cipher"; -import { AttachmentView } from "@bitwarden/common/vault/models/view/attachment.view"; -import { DialogService, ToastService } from "@bitwarden/components"; -import { KeyService } from "@bitwarden/key-management"; - -import { AttachmentsComponent as BaseAttachmentsComponent } from "../individual-vault/attachments.component"; - -@Component({ - selector: "app-org-vault-attachments", - templateUrl: "../individual-vault/attachments.component.html", -}) -export class AttachmentsComponent extends BaseAttachmentsComponent implements OnInit { - viewOnly = false; - organization: Organization; - - constructor( - cipherService: CipherService, - i18nService: I18nService, - keyService: KeyService, - encryptService: EncryptService, - stateService: StateService, - platformUtilsService: PlatformUtilsService, - apiService: ApiService, - logService: LogService, - fileDownloadService: FileDownloadService, - dialogService: DialogService, - billingAccountProfileStateService: BillingAccountProfileStateService, - accountService: AccountService, - toastService: ToastService, - ) { - super( - cipherService, - i18nService, - keyService, - encryptService, - stateService, - platformUtilsService, - apiService, - logService, - fileDownloadService, - dialogService, - billingAccountProfileStateService, - accountService, - toastService, - ); - } - - async ngOnInit() { - await super.ngOnInit(); - } - - protected async reupload(attachment: AttachmentView) { - if (this.organization.canEditAllCiphers && this.showFixOldAttachments(attachment)) { - await super.reuploadCipherAttachment(attachment, true); - } - } - - protected async loadCipher() { - if (!this.organization.canEditAllCiphers) { - const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId)); - return await super.loadCipher(activeUserId); - } - const response = await this.apiService.getCipherAdmin(this.cipherId); - return new Cipher(new CipherData(response)); - } - - protected saveCipherAttachment(file: File, userId: UserId) { - return this.cipherService.saveAttachmentWithServer( - this.cipherDomain, - file, - userId, - this.organization.canEditAllCiphers, - ); - } - - protected deleteCipherAttachment(attachmentId: string, userId: UserId) { - if (!this.organization.canEditAllCiphers) { - return super.deleteCipherAttachment(attachmentId, userId); - } - return this.apiService.deleteCipherAttachmentAdmin(this.cipherId, attachmentId); - } - - protected showFixOldAttachments(attachment: AttachmentView) { - return attachment.key == null && this.organization.canEditAllCiphers; - } -}