[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.
*/
fun List<CollectionView>?.hasDeletePermissionInAtLeastOneCollection(collectionIds: List<String>?) =
this
?.takeUnless { it.isEmpty() }
?.any {
fun List<CollectionView>?.hasDeletePermissionInAtLeastOneCollection(
collectionIds: List<String>?,
): 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.