[PM-10483] Fix collection manage check for delete permission (#4313)

This commit is contained in:
Patrick Honkonen 2024-11-18 09:26:58 -05:00 committed by GitHub
parent 30eb11b85e
commit e90bd136f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,16 +94,17 @@ fun String.toCollectionDisplayName(list: List<CollectionView>): String {
* *
* Deletion is allowed when the item is in any collection that the user has "manage" permission for. * Deletion is allowed when the item is in any collection that the user has "manage" permission for.
*/ */
fun List<CollectionView>?.hasDeletePermissionInAtLeastOneCollection(collectionIds: List<String>?) = fun List<CollectionView>?.hasDeletePermissionInAtLeastOneCollection(
this collectionIds: List<String>?,
?.takeUnless { it.isEmpty() } ): Boolean {
?.any { if (this.isNullOrEmpty() || collectionIds.isNullOrEmpty()) return true
return this
.any { collectionView ->
collectionIds collectionIds
?.contains(it.id) .contains(collectionView.id)
?.let { isInCollection -> !isInCollection || it.manage } .let { isInCollection -> isInCollection && collectionView.manage }
?: true
} }
?: true }
/** /**
* Checks if the user has permission to assign an item to a collection. * Checks if the user has permission to assign an item to a collection.