1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00
Files
browser/apps/web/src/app/vault/components/vault-items/vault-collection-row.component.ts

110 lines
3.5 KiB
TypeScript

import { Component, EventEmitter, Input, Output } from "@angular/core";
import { CollectionAdminView, Unassigned } from "@bitwarden/admin-console/common";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";
import { GroupView } from "../../../admin-console/organizations/core";
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[appVaultCollectionRow]",
templateUrl: "vault-collection-row.component.html",
})
export class VaultCollectionRowComponent {
protected RowHeightClass = RowHeightClass;
protected Unassigned = "unassigned";
@Input() disabled: boolean;
@Input() collection: CollectionView;
@Input() showOwner: boolean;
@Input() showCollections: boolean;
@Input() showGroups: boolean;
@Input() canEditCollection: boolean;
@Input() canDeleteCollection: boolean;
@Input() canViewCollectionInfo: boolean;
@Input() organizations: Organization[];
@Input() groups: GroupView[];
@Input() showPermissionsColumn: boolean;
@Output() onEvent = new EventEmitter<VaultItemEvent>();
@Input() checked: boolean;
@Output() checkedToggled = new EventEmitter<void>();
constructor(private i18nService: I18nService) {}
get collectionGroups() {
if (!(this.collection instanceof CollectionAdminView)) {
return [];
}
return this.collection.groups;
}
get organization() {
return this.organizations.find((o) => o.id === this.collection.organizationId);
}
get showAddAccess() {
if (this.collection.id == Unassigned) {
return false;
}
// Only show AddAccess when viewing the Org vault (implied by CollectionAdminView)
if (this.collection instanceof CollectionAdminView) {
// Only show AddAccess if unmanaged and allowAdminAccessToAllCollectionItems is disabled
return (
!this.organization?.allowAdminAccessToAllCollectionItems &&
this.collection.unmanaged &&
this.organization?.canEditUnmanagedCollections
);
}
return false;
}
get permissionText() {
if (this.collection.id == Unassigned && this.organization?.canEditUnassignedCiphers) {
return this.i18nService.t("canEdit");
}
if ((this.collection as CollectionAdminView).assigned) {
const permissionList = getPermissionList();
return this.i18nService.t(
permissionList.find((p) => p.perm === convertToPermission(this.collection))?.labelId,
);
}
return this.i18nService.t("noAccess");
}
get permissionTooltip() {
if (this.collection.id == Unassigned) {
return this.i18nService.t("collectionAdminConsoleManaged");
}
return "";
}
protected edit(readonly: boolean) {
this.onEvent.next({ type: "editCollection", item: this.collection, readonly: readonly });
}
protected access(readonly: boolean) {
this.onEvent.next({ type: "viewCollectionAccess", item: this.collection, readonly: readonly });
}
protected deleteCollection() {
this.onEvent.next({ type: "delete", items: [{ collection: this.collection }] });
}
protected get showCheckbox() {
return this.collection?.id !== Unassigned;
}
}