From e90bd136f6bbe78734daf700ddcc0cc736dce646 Mon Sep 17 00:00:00 2001 From: Patrick Honkonen <1883101+SaintPatrck@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:26:58 -0500 Subject: [PATCH] [PM-10483] Fix collection manage check for delete permission (#4313) --- .../feature/util/CollectionViewExtensions.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt index 554b2bdb1..b75b186be 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt @@ -94,16 +94,17 @@ fun String.toCollectionDisplayName(list: List): String { * * Deletion is allowed when the item is in any collection that the user has "manage" permission for. */ -fun List?.hasDeletePermissionInAtLeastOneCollection(collectionIds: List?) = - this - ?.takeUnless { it.isEmpty() } - ?.any { +fun List?.hasDeletePermissionInAtLeastOneCollection( + collectionIds: List?, +): Boolean { + if (this.isNullOrEmpty() || collectionIds.isNullOrEmpty()) return true + return this + .any { collectionView -> collectionIds - ?.contains(it.id) - ?.let { isInCollection -> !isInCollection || it.manage } - ?: true + .contains(collectionView.id) + .let { isInCollection -> isInCollection && collectionView.manage } } - ?: true +} /** * Checks if the user has permission to assign an item to a collection.