1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

[PM-15824] Re-organize collection filter logic to only consider organization setting to edit all ciphers in AC (#12323)

This commit is contained in:
Shane Melton
2024-12-13 11:51:07 -08:00
committed by GitHub
parent 8874cb18f8
commit 9288ab839c
2 changed files with 42 additions and 27 deletions

View File

@@ -91,7 +91,8 @@ describe("ItemDetailsSectionComponent", () => {
id: "col1",
name: "Collection 1",
organizationId: "org1",
canEditItems: (_org) => true,
assigned: true,
readOnly: false,
} as CollectionView,
];
component.originalCipherView = {
@@ -125,13 +126,15 @@ describe("ItemDetailsSectionComponent", () => {
id: "col1",
name: "Collection 1",
organizationId: "org1",
canEditItems: (_org) => false,
assigned: true,
readOnly: true,
} as CollectionView,
{
id: "col2",
name: "Collection 2",
organizationId: "org1",
canEditItems: (_org) => true,
assigned: true,
readOnly: false,
} as CollectionView,
];
component.originalCipherView = {
@@ -386,19 +389,22 @@ describe("ItemDetailsSectionComponent", () => {
id: "col1",
name: "Collection 1",
organizationId: "org1",
canEditItems: (_org) => true,
assigned: true,
readOnly: false,
} as CollectionView,
{
id: "col2",
name: "Collection 2",
organizationId: "org1",
canEditItems: (_org) => true,
assigned: true,
readOnly: false,
} as CollectionView,
{
id: "col3",
name: "Collection 3",
organizationId: "org1",
canEditItems: (_org) => true,
assigned: true,
readOnly: false,
} as CollectionView,
];
@@ -421,7 +427,8 @@ describe("ItemDetailsSectionComponent", () => {
id: "col1",
name: "Collection 1",
organizationId: "org1",
canEditItems: (_org) => true,
assigned: true,
readOnly: false,
} as CollectionView,
];
@@ -453,20 +460,22 @@ describe("ItemDetailsSectionComponent", () => {
id: "col1",
name: "Collection 1",
organizationId: "org1",
canEditItems: (_org) => true,
assigned: true,
readOnly: false,
} as CollectionView,
{
id: "col2",
name: "Collection 2",
organizationId: "org1",
canEditItems: (_org) => true,
assigned: true,
readOnly: false,
} as CollectionView,
{
id: "col3",
name: "Collection 3",
organizationId: "org1",
readOnly: true,
canEditItems: (_org) => true,
assigned: true,
} as CollectionView,
];
@@ -490,21 +499,21 @@ describe("ItemDetailsSectionComponent", () => {
name: "Collection 1",
organizationId: "org1",
readOnly: true,
canEditItems: (_org) => false,
assigned: false,
} as CollectionView,
{
id: "col2",
name: "Collection 2",
organizationId: "org1",
readOnly: true,
canEditItems: (_org) => false,
assigned: false,
} as CollectionView,
{
id: "col3",
name: "Collection 3",
organizationId: "org1",
readOnly: false,
canEditItems: (_org) => false,
assigned: true,
} as CollectionView,
];
@@ -527,20 +536,20 @@ describe("ItemDetailsSectionComponent", () => {
name: "Collection 1",
organizationId: "org1",
readOnly: true,
canEditItems: (_org) => false,
assigned: false,
} as CollectionView,
{
id: "col2",
name: "Collection 2",
organizationId: "org1",
canEditItems: (_org) => false,
assigned: false,
} as CollectionView,
{
id: "col3",
name: "Collection 3",
organizationId: "org1",
readOnly: true,
canEditItems: (_org) => false,
assigned: false,
} as CollectionView,
];
component.originalCipherView = {

View File

@@ -273,19 +273,25 @@ export class ItemDetailsSectionComponent implements OnInit {
this.showCollectionsControl = true;
}
const organization = this.organizations.find((o) => o.id === orgId);
this.collectionOptions = this.collections
.filter((c) => {
// Filter criteria:
// - The collection belongs to the organization
// - When in partial edit mode, show all org collections because the control is disabled.
// - The user can edit items within the collection
// - When viewing as an admin, all collections should be shown, even readonly. When non-admin, filter out readonly collections
return (
c.organizationId === orgId &&
(this.partialEdit || c.canEditItems(organization) || this.config.admin)
);
// The collection belongs to the organization
if (c.organizationId !== orgId) {
return false;
}
// When in partial edit mode, show all org collections because the control is disabled.
if (this.partialEdit) {
return true;
}
// When viewing as an admin, all collections should be shown, even readonly. (AC Only)
if (this.config.admin) {
return true;
}
// Non-admins can only select assigned collections that are not read only. (Non-AC)
return c.assigned && !c.readOnly;
})
.map((c) => ({
id: c.id,