mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +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:
@@ -91,7 +91,8 @@ describe("ItemDetailsSectionComponent", () => {
|
|||||||
id: "col1",
|
id: "col1",
|
||||||
name: "Collection 1",
|
name: "Collection 1",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => true,
|
assigned: true,
|
||||||
|
readOnly: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
];
|
];
|
||||||
component.originalCipherView = {
|
component.originalCipherView = {
|
||||||
@@ -125,13 +126,15 @@ describe("ItemDetailsSectionComponent", () => {
|
|||||||
id: "col1",
|
id: "col1",
|
||||||
name: "Collection 1",
|
name: "Collection 1",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => false,
|
assigned: true,
|
||||||
|
readOnly: true,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
{
|
{
|
||||||
id: "col2",
|
id: "col2",
|
||||||
name: "Collection 2",
|
name: "Collection 2",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => true,
|
assigned: true,
|
||||||
|
readOnly: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
];
|
];
|
||||||
component.originalCipherView = {
|
component.originalCipherView = {
|
||||||
@@ -386,19 +389,22 @@ describe("ItemDetailsSectionComponent", () => {
|
|||||||
id: "col1",
|
id: "col1",
|
||||||
name: "Collection 1",
|
name: "Collection 1",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => true,
|
assigned: true,
|
||||||
|
readOnly: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
{
|
{
|
||||||
id: "col2",
|
id: "col2",
|
||||||
name: "Collection 2",
|
name: "Collection 2",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => true,
|
assigned: true,
|
||||||
|
readOnly: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
{
|
{
|
||||||
id: "col3",
|
id: "col3",
|
||||||
name: "Collection 3",
|
name: "Collection 3",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => true,
|
assigned: true,
|
||||||
|
readOnly: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -421,7 +427,8 @@ describe("ItemDetailsSectionComponent", () => {
|
|||||||
id: "col1",
|
id: "col1",
|
||||||
name: "Collection 1",
|
name: "Collection 1",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => true,
|
assigned: true,
|
||||||
|
readOnly: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -453,20 +460,22 @@ describe("ItemDetailsSectionComponent", () => {
|
|||||||
id: "col1",
|
id: "col1",
|
||||||
name: "Collection 1",
|
name: "Collection 1",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => true,
|
assigned: true,
|
||||||
|
readOnly: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
{
|
{
|
||||||
id: "col2",
|
id: "col2",
|
||||||
name: "Collection 2",
|
name: "Collection 2",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => true,
|
assigned: true,
|
||||||
|
readOnly: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
{
|
{
|
||||||
id: "col3",
|
id: "col3",
|
||||||
name: "Collection 3",
|
name: "Collection 3",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
canEditItems: (_org) => true,
|
assigned: true,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -490,21 +499,21 @@ describe("ItemDetailsSectionComponent", () => {
|
|||||||
name: "Collection 1",
|
name: "Collection 1",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
canEditItems: (_org) => false,
|
assigned: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
{
|
{
|
||||||
id: "col2",
|
id: "col2",
|
||||||
name: "Collection 2",
|
name: "Collection 2",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
canEditItems: (_org) => false,
|
assigned: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
{
|
{
|
||||||
id: "col3",
|
id: "col3",
|
||||||
name: "Collection 3",
|
name: "Collection 3",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
canEditItems: (_org) => false,
|
assigned: true,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -527,20 +536,20 @@ describe("ItemDetailsSectionComponent", () => {
|
|||||||
name: "Collection 1",
|
name: "Collection 1",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
canEditItems: (_org) => false,
|
assigned: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
{
|
{
|
||||||
id: "col2",
|
id: "col2",
|
||||||
name: "Collection 2",
|
name: "Collection 2",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
canEditItems: (_org) => false,
|
assigned: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
{
|
{
|
||||||
id: "col3",
|
id: "col3",
|
||||||
name: "Collection 3",
|
name: "Collection 3",
|
||||||
organizationId: "org1",
|
organizationId: "org1",
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
canEditItems: (_org) => false,
|
assigned: false,
|
||||||
} as CollectionView,
|
} as CollectionView,
|
||||||
];
|
];
|
||||||
component.originalCipherView = {
|
component.originalCipherView = {
|
||||||
|
|||||||
@@ -273,19 +273,25 @@ export class ItemDetailsSectionComponent implements OnInit {
|
|||||||
this.showCollectionsControl = true;
|
this.showCollectionsControl = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const organization = this.organizations.find((o) => o.id === orgId);
|
|
||||||
|
|
||||||
this.collectionOptions = this.collections
|
this.collectionOptions = this.collections
|
||||||
.filter((c) => {
|
.filter((c) => {
|
||||||
// Filter criteria:
|
// The collection belongs to the organization
|
||||||
// - The collection belongs to the organization
|
if (c.organizationId !== orgId) {
|
||||||
// - When in partial edit mode, show all org collections because the control is disabled.
|
return false;
|
||||||
// - 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 (
|
// When in partial edit mode, show all org collections because the control is disabled.
|
||||||
c.organizationId === orgId &&
|
if (this.partialEdit) {
|
||||||
(this.partialEdit || c.canEditItems(organization) || this.config.admin)
|
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) => ({
|
.map((c) => ({
|
||||||
id: c.id,
|
id: c.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user