1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

[PM-11199] added permission labels to ciphers in AC (#11210)

* added permission labels to ciphers in AC
This commit is contained in:
Jason Ng
2024-10-22 10:07:22 -04:00
committed by GitHub
parent 4a30782939
commit 023abe2969
3 changed files with 57 additions and 2 deletions

View File

@@ -5,9 +5,14 @@ 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";
@@ -43,9 +48,20 @@ export class VaultCipherRowComponent implements OnInit {
@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) {}
constructor(
private configService: ConfigService,
private i18nService: I18nService,
) {}
/**
* Lifecycle hook for component initialization.
@@ -91,6 +107,40 @@ export class VaultCipherRowComponent implements OnInit {
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;
}