Skip to content

Commit

Permalink
remove canEdit Except PW collections from edit item dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Jingo88 committed Nov 8, 2024
1 parent 2824e78 commit 4be508a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ import { CipherFormContainer } from "../../cipher-form-container";

import { ItemDetailsSectionComponent } from "./item-details-section.component";

const createMockCollection = (
id: string,
name: string,
organizationId: string,
readOnly = false,
) => {
return {
id,
name,
organizationId,
externalId: "",
readOnly,
hidePasswords: false,
manage: true,
assigned: true,
canEditItems: jest.fn().mockReturnValue(true),
canEdit: jest.fn(),
canDelete: jest.fn(),
canViewCollectionInfo: jest.fn(),
};
};

describe("ItemDetailsSectionComponent", () => {
let component: ItemDetailsSectionComponent;
let fixture: ComponentFixture<ItemDetailsSectionComponent>;
Expand Down Expand Up @@ -87,7 +109,7 @@ describe("ItemDetailsSectionComponent", () => {
component.config.allowPersonalOwnership = true;
component.config.organizations = [{ id: "org1" } as Organization];
component.config.collections = [
{ id: "col1", name: "Collection 1", organizationId: "org1" } as CollectionView,
createMockCollection("col1", "Collection 1", "org1") as CollectionView,
];
component.originalCipherView = {
name: "cipher1",
Expand Down Expand Up @@ -116,8 +138,8 @@ describe("ItemDetailsSectionComponent", () => {
component.config.allowPersonalOwnership = true;
component.config.organizations = [{ id: "org1" } as Organization];
component.config.collections = [
{ id: "col1", name: "Collection 1", organizationId: "org1" } as CollectionView,
{ id: "col2", name: "Collection 2", organizationId: "org1" } as CollectionView,
createMockCollection("col1", "Collection 1", "org1") as CollectionView,
createMockCollection("col2", "Collection 2", "org1") as CollectionView,
];
component.originalCipherView = {
name: "cipher1",
Expand Down Expand Up @@ -336,8 +358,8 @@ describe("ItemDetailsSectionComponent", () => {
component.config.allowPersonalOwnership = true;
component.config.organizations = [{ id: "org1" } as Organization];
component.config.collections = [
{ id: "col1", name: "Collection 1", organizationId: "org1" } as CollectionView,
{ id: "col2", name: "Collection 2", organizationId: "org1" } as CollectionView,
createMockCollection("col1", "Collection 1", "org1") as CollectionView,
createMockCollection("col2", "Collection 2", "org1") as CollectionView,
];

fixture.detectChanges();
Expand Down Expand Up @@ -367,9 +389,9 @@ describe("ItemDetailsSectionComponent", () => {
} as CipherView;
component.config.organizations = [{ id: "org1" } as Organization];
component.config.collections = [
{ id: "col1", name: "Collection 1", organizationId: "org1" } as CollectionView,
{ id: "col2", name: "Collection 2", organizationId: "org1" } as CollectionView,
{ id: "col3", name: "Collection 3", organizationId: "org1" } as CollectionView,
createMockCollection("col1", "Collection 1", "org1") as CollectionView,
createMockCollection("col2", "Collection 2", "org1") as CollectionView,
createMockCollection("col3", "Collection 3", "org1") as CollectionView,
];

fixture.detectChanges();
Expand All @@ -387,7 +409,7 @@ describe("ItemDetailsSectionComponent", () => {
component.config.allowPersonalOwnership = true;
component.config.organizations = [{ id: "org1" } as Organization];
component.config.collections = [
{ id: "col1", name: "Collection 1", organizationId: "org1" } as CollectionView,
createMockCollection("col1", "Collection 1", "org1") as CollectionView,
];

fixture.detectChanges();
Expand All @@ -414,14 +436,9 @@ describe("ItemDetailsSectionComponent", () => {
} as CipherView;
component.config.organizations = [{ id: "org1" } as Organization];
component.config.collections = [
{ id: "col1", name: "Collection 1", organizationId: "org1" } as CollectionView,
{ id: "col2", name: "Collection 2", organizationId: "org1" } as CollectionView,
{
id: "col3",
name: "Collection 3",
organizationId: "org1",
readOnly: true,
} as CollectionView,
createMockCollection("col1", "Collection 1", "org1") as CollectionView,
createMockCollection("col2", "Collection 2", "org1") as CollectionView,
createMockCollection("col3", "Collection 3", "org1", true) as CollectionView,
];

await component.ngOnInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,16 @@ export class ItemDetailsSectionComponent implements OnInit {
return;
}

const org = this.config.organizations[0];

this.collectionOptions = this.collections
.filter((c) => {
// If partial edit mode, show all org collections because the control is disabled.
return c.organizationId === orgId && (this.partialEdit || !c.readOnly);
return (
c.organizationId === orgId &&
(this.partialEdit || !c.readOnly) &&
c.canEditItems(org, false)
);
})
.map((c) => ({
id: c.id,
Expand Down

0 comments on commit 4be508a

Please sign in to comment.