mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
* Use typescript-strict-plugin to iteratively turn on strict * Add strict testing to pipeline Can be executed locally through either `npm run test:types` for full type checking including spec files, or `npx tsc-strict` for only tsconfig.json included files. * turn on strict for scripts directory * Use plugin for all tsconfigs in monorepo vscode is capable of executing tsc with plugins, but uses the most relevant tsconfig to do so. If the plugin is not a part of that config, it is skipped and developers get no feedback of strict compile time issues. These updates remedy that at the cost of slightly more complex removal of the plugin when the time comes. * remove plugin from configs that extend one that already has it * Update workspace settings to honor strict plugin * Apply strict-plugin to native message test runner * Update vscode workspace to use root tsc version * `./node_modules/.bin/update-strict-comments` 🤖 This is a one-time operation. All future files should adhere to strict type checking. * Add fixme to `ts-strict-ignore` comments * `update-strict-comments` 🤖 repeated for new merge files
207 lines
6.2 KiB
TypeScript
207 lines
6.2 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
|
import { firstValueFrom } from "rxjs";
|
|
|
|
import { CollectionView } from "@bitwarden/admin-console/common";
|
|
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
|
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
|
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
import { CipherType } from "@bitwarden/common/vault/enums";
|
|
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
|
|
|
import {
|
|
convertToPermission,
|
|
getPermissionList,
|
|
} from "./../../../admin-console/organizations/shared/components/access-selector/access-selector.models";
|
|
import { VaultItemEvent } from "./vault-item-event";
|
|
import { RowHeightClass } from "./vault-items.component";
|
|
|
|
@Component({
|
|
selector: "tr[appVaultCipherRow]",
|
|
templateUrl: "vault-cipher-row.component.html",
|
|
})
|
|
export class VaultCipherRowComponent implements OnInit {
|
|
protected RowHeightClass = RowHeightClass;
|
|
|
|
/**
|
|
* Flag to determine if the extension refresh feature flag is enabled.
|
|
*/
|
|
protected extensionRefreshEnabled = false;
|
|
|
|
@Input() disabled: boolean;
|
|
@Input() cipher: CipherView;
|
|
@Input() showOwner: boolean;
|
|
@Input() showCollections: boolean;
|
|
@Input() showGroups: boolean;
|
|
@Input() showPremiumFeatures: boolean;
|
|
@Input() useEvents: boolean;
|
|
@Input() cloneable: boolean;
|
|
@Input() organizations: Organization[];
|
|
@Input() collections: CollectionView[];
|
|
@Input() viewingOrgVault: boolean;
|
|
@Input() canEditCipher: boolean;
|
|
@Input() canManageCollection: boolean;
|
|
|
|
@Output() onEvent = new EventEmitter<VaultItemEvent>();
|
|
|
|
@Input() checked: boolean;
|
|
@Output() checkedToggled = new EventEmitter<void>();
|
|
|
|
protected CipherType = CipherType;
|
|
private permissionList = getPermissionList();
|
|
private permissionPriority = [
|
|
"canManage",
|
|
"canEdit",
|
|
"canEditExceptPass",
|
|
"canView",
|
|
"canViewExceptPass",
|
|
];
|
|
protected organization?: Organization;
|
|
|
|
constructor(
|
|
private configService: ConfigService,
|
|
private i18nService: I18nService,
|
|
) {}
|
|
|
|
/**
|
|
* Lifecycle hook for component initialization.
|
|
* Checks if the extension refresh feature flag is enabled to provide to template.
|
|
*/
|
|
async ngOnInit(): Promise<void> {
|
|
this.extensionRefreshEnabled = await firstValueFrom(
|
|
this.configService.getFeatureFlag$(FeatureFlag.ExtensionRefresh),
|
|
);
|
|
if (this.cipher.organizationId != null) {
|
|
this.organization = this.organizations.find((o) => o.id === this.cipher.organizationId);
|
|
}
|
|
}
|
|
|
|
protected get showTotpCopyButton() {
|
|
return (
|
|
(this.cipher.login?.hasTotp ?? false) &&
|
|
(this.cipher.organizationUseTotp || this.showPremiumFeatures)
|
|
);
|
|
}
|
|
|
|
protected get showFixOldAttachments() {
|
|
return this.cipher.hasOldAttachments && this.cipher.organizationId == null;
|
|
}
|
|
|
|
protected get showAttachments() {
|
|
return this.canEditCipher || this.cipher.attachments?.length > 0;
|
|
}
|
|
|
|
protected get showAssignToCollections() {
|
|
return this.organizations?.length && this.canEditCipher && !this.cipher.isDeleted;
|
|
}
|
|
|
|
protected get showClone() {
|
|
return this.cloneable && !this.cipher.isDeleted;
|
|
}
|
|
|
|
protected get showEventLogs() {
|
|
return this.useEvents && this.cipher.organizationId;
|
|
}
|
|
|
|
protected get isNotDeletedLoginCipher() {
|
|
return this.cipher.type === this.CipherType.Login && !this.cipher.isDeleted;
|
|
}
|
|
|
|
protected get permissionText() {
|
|
if (!this.cipher.organizationId || this.cipher.collectionIds.length === 0) {
|
|
return this.i18nService.t("canManage");
|
|
}
|
|
|
|
const filteredCollections = this.collections.filter((collection) => {
|
|
if (collection.assigned) {
|
|
return this.cipher.collectionIds.find((id) => {
|
|
if (collection.id === id) {
|
|
return collection;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
if (filteredCollections?.length === 1) {
|
|
return this.i18nService.t(
|
|
this.permissionList.find((p) => p.perm === convertToPermission(filteredCollections[0]))
|
|
?.labelId,
|
|
);
|
|
}
|
|
|
|
if (filteredCollections?.length > 1) {
|
|
const labels = filteredCollections.map((collection) => {
|
|
return this.permissionList.find((p) => p.perm === convertToPermission(collection))?.labelId;
|
|
});
|
|
|
|
const highestPerm = this.permissionPriority.find((perm) => labels.includes(perm));
|
|
return this.i18nService.t(highestPerm);
|
|
}
|
|
|
|
return this.i18nService.t("noAccess");
|
|
}
|
|
|
|
protected get showCopyPassword(): boolean {
|
|
return this.isNotDeletedLoginCipher && this.cipher.viewPassword;
|
|
}
|
|
|
|
protected get showCopyTotp(): boolean {
|
|
return this.isNotDeletedLoginCipher && this.showTotpCopyButton;
|
|
}
|
|
|
|
protected get showLaunchUri(): boolean {
|
|
return this.isNotDeletedLoginCipher && this.cipher.login.canLaunch;
|
|
}
|
|
|
|
protected get disableMenu() {
|
|
return !(
|
|
this.isNotDeletedLoginCipher ||
|
|
this.showCopyPassword ||
|
|
this.showCopyTotp ||
|
|
this.showLaunchUri ||
|
|
this.showAttachments ||
|
|
this.showClone ||
|
|
this.canEditCipher ||
|
|
this.cipher.isDeleted
|
|
);
|
|
}
|
|
|
|
protected copy(field: "username" | "password" | "totp") {
|
|
this.onEvent.emit({ type: "copyField", item: this.cipher, field });
|
|
}
|
|
|
|
protected clone() {
|
|
this.onEvent.emit({ type: "clone", item: this.cipher });
|
|
}
|
|
|
|
protected events() {
|
|
this.onEvent.emit({ type: "viewEvents", item: this.cipher });
|
|
}
|
|
|
|
protected restore() {
|
|
this.onEvent.emit({ type: "restore", items: [this.cipher] });
|
|
}
|
|
|
|
protected deleteCipher() {
|
|
this.onEvent.emit({ type: "delete", items: [{ cipher: this.cipher }] });
|
|
}
|
|
|
|
protected attachments() {
|
|
this.onEvent.emit({ type: "viewAttachments", item: this.cipher });
|
|
}
|
|
|
|
protected assignToCollections() {
|
|
this.onEvent.emit({ type: "assignToCollections", items: [this.cipher] });
|
|
}
|
|
|
|
protected get showCheckbox() {
|
|
if (!this.viewingOrgVault || !this.organization) {
|
|
return true; // Always show checkbox in individual vault or for non-org items
|
|
}
|
|
|
|
return this.organization.canEditAllCiphers || this.cipher.edit;
|
|
}
|
|
}
|