1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-25982] Assign to Collections - My Items (#16591)

* update cipher form to exclude my items collections

* handle default collections for assign to collections and bulk

* account for every returning true for empty arrays
This commit is contained in:
Nick Krantz
2025-09-29 13:06:36 -05:00
committed by GitHub
parent f988d3fd70
commit c4ee2fdae2
4 changed files with 199 additions and 8 deletions

View File

@@ -406,6 +406,17 @@ export class ItemDetailsSectionComponent implements OnInit {
this.showCollectionsControl = true;
}
/**
* Determine if the the cipher is only assigned to shared collections.
* i.e. The cipher is not assigned to a default collections.
* Note: `.every` will return true for an empty array
*/
const cipherIsOnlyInOrgCollections =
(this.originalCipherView?.collectionIds ?? []).length > 0 &&
this.originalCipherView.collectionIds.every(
(cId) =>
this.collections.find((c) => c.id === cId)?.type === CollectionTypes.SharedCollection,
);
this.collectionOptions = this.collections
.filter((c) => {
// The collection belongs to the organization
@@ -423,10 +434,17 @@ export class ItemDetailsSectionComponent implements OnInit {
return true;
}
// When the cipher is only assigned to shared collections, do not allow a user to
// move it back to a default collection. Exclude the default collection from the list.
if (cipherIsOnlyInOrgCollections && c.type === CollectionTypes.DefaultUserCollection) {
return false;
}
// Non-admins can only select assigned collections that are not read only. (Non-AC)
return c.assigned && !c.readOnly;
})
.sort((a, b) => {
// Show default collection first
const aIsDefaultCollection = a.type === CollectionTypes.DefaultUserCollection ? -1 : 0;
const bIsDefaultCollection = b.type === CollectionTypes.DefaultUserCollection ? -1 : 0;
return aIsDefaultCollection - bIsDefaultCollection;