diff --git a/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.html b/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.html index ccf853837c..56acc421de 100644 --- a/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.html +++ b/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.html @@ -7,6 +7,7 @@ *ngIf="showCipherView" [cipher]="cipher" [collections]="collections" + [isAdminConsole]="formConfig.isAdminConsole" > diff --git a/libs/vault/src/cipher-view/cipher-view.component.ts b/libs/vault/src/cipher-view/cipher-view.component.ts index 324b2358a8..5d61caf52f 100644 --- a/libs/vault/src/cipher-view/cipher-view.component.ts +++ b/libs/vault/src/cipher-view/cipher-view.component.ts @@ -51,6 +51,10 @@ export class CipherViewComponent implements OnChanges, OnDestroy { * `CipherService` and the `collectionIds` property of the cipher. */ @Input() collections: CollectionView[]; + + /** Should be set to true when the component is used within the Admin Console */ + @Input() isAdminConsole?: boolean = false; + organization$: Observable; folder$: Observable; private destroyed$: Subject = new Subject(); diff --git a/libs/vault/src/cipher-view/item-details/item-details-v2.component.html b/libs/vault/src/cipher-view/item-details/item-details-v2.component.html index 2d15230f9a..b6b4256440 100644 --- a/libs/vault/src/cipher-view/item-details/item-details-v2.component.html +++ b/libs/vault/src/cipher-view/item-details/item-details-v2.component.html @@ -4,10 +4,8 @@ {{ "itemName" | i18n }} @@ -24,11 +22,11 @@
  • { + let component: ItemDetailsV2Component; + let fixture: ComponentFixture; + + const cipher = { + id: "cipher1", + collectionIds: ["col1", "col2"], + organizationId: "org1", + folderId: "folder1", + name: "cipher name", + } as CipherView; + + const organization = { + id: "org1", + name: "Organization 1", + } as Organization; + + const collection = { + id: "col1", + name: "Collection 1", + } as CollectionView; + + const collection2 = { + id: "col2", + name: "Collection 2", + } as CollectionView; + + const folder = { + id: "folder1", + name: "Folder 1", + } as FolderView; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ItemDetailsV2Component], + providers: [{ provide: I18nService, useValue: { t: (key: string) => key } }], + }).compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ItemDetailsV2Component); + component = fixture.componentInstance; + component.cipher = cipher; + component.organization = organization; + component.collections = [collection, collection2]; + component.folder = folder; + fixture.detectChanges(); + }); + + it("displays all available fields", () => { + const itemName = fixture.debugElement.query(By.css('[data-testid="item-name"]')); + const owner = fixture.debugElement.query(By.css('[data-testid="owner"]')); + const collections = fixture.debugElement.queryAll(By.css('[data-testid="collections"] li')); + const folderElement = fixture.debugElement.query(By.css('[data-testid="folder"]')); + + expect(itemName.nativeElement.value).toBe(cipher.name); + expect(owner.nativeElement.textContent.trim()).toBe(organization.name); + expect(collections.map((c) => c.nativeElement.textContent.trim())).toEqual([ + collection.name, + collection2.name, + ]); + expect(folderElement.nativeElement.textContent.trim()).toBe(folder.name); + }); + + it("does not render owner when `hideOwner` is true", () => { + component.hideOwner = true; + fixture.detectChanges(); + + const owner = fixture.debugElement.query(By.css('[data-testid="owner"]')); + expect(owner).toBeNull(); + }); +}); diff --git a/libs/vault/src/cipher-view/item-details/item-details-v2.component.ts b/libs/vault/src/cipher-view/item-details/item-details-v2.component.ts index 48c129bd3b..daa8092f4b 100644 --- a/libs/vault/src/cipher-view/item-details/item-details-v2.component.ts +++ b/libs/vault/src/cipher-view/item-details/item-details-v2.component.ts @@ -36,4 +36,9 @@ export class ItemDetailsV2Component { @Input() organization?: Organization; @Input() collections?: CollectionView[]; @Input() folder?: FolderView; + @Input() hideOwner?: boolean = false; + + get showOwnership() { + return this.cipher.organizationId && this.organization && !this.hideOwner; + } }