Compare commits

...

4 Commits

Author SHA1 Message Date
André Bispo
d192065054 [PM-15969] Update inline comment 2025-01-02 15:10:04 +00:00
André Bispo
5f40ac3004 [PM-15969] Update test to match logic changes 2025-01-02 12:16:34 +00:00
André Bispo
7746b6c0c7 [PM-15969] Update tests to reflect previous changes 2025-01-01 20:03:47 +00:00
André Bispo
6160402186 [PM-15969] Fix bug where Edit permission couldn't assign item to collections 2025-01-01 10:33:09 +00:00
3 changed files with 14 additions and 29 deletions

View File

@@ -110,33 +110,20 @@ fun List<CollectionView>?.hasDeletePermissionInAtLeastOneCollection(
/**
* Checks if the user has permission to assign an item to a collection.
*
* Assigning to a collection is not allowed when the item is in a collection that the user does not
* have "manage" permission for and is also in a collection they cannot view the passwords in.
*
* E.g., If an item is in A collection with "view except passwords" or "edit except passwords"
* permission and in another with "manage" permission, the user **cannot** assign the item to other
* collections. Conversely, if an item is in a collection with "manage" permission and another with
* "view" or "edit" permission, the user **can** assign the item to other collections.
* Assigning to a collection is only allowed when the item is in a collection that the user does
* have "manage" or "edit" permission.
*/
fun List<CollectionView>?.canAssignToCollections(currentCollectionIds: List<String>?): Boolean {
if (this.isNullOrEmpty()) return true
if (currentCollectionIds.isNullOrEmpty()) return true
// Verify user can MANAGE at least one collection the item is in.
// Verify user can MANAGE or EDIT at least one collection the item is in.
return this
.any {
currentCollectionIds.contains(it.id) &&
it.permission == CollectionPermission.MANAGE
} &&
// Verify user does not have "edit except password" or "view except passwords"
// permission in any collection the item is not in.
this
.none {
currentCollectionIds.contains(it.id) &&
(it.permission == CollectionPermission.EDIT_EXCEPT_PASSWORD ||
it.permission == CollectionPermission.VIEW_EXCEPT_PASSWORDS)
}
(it.permission == CollectionPermission.MANAGE ||
it.permission == CollectionPermission.EDIT)
}
}
/**

View File

@@ -1187,7 +1187,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
resourceManager = resourceManager,
clock = fixedClock,
canDelete = false,
canAssignToCollections = false,
canAssignToCollections = true,
)
} returns stateWithName.viewState
@@ -1215,7 +1215,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
resourceManager = resourceManager,
clock = fixedClock,
canDelete = false,
canAssignToCollections = false,
canAssignToCollections = true,
)
}
}
@@ -1385,7 +1385,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
resourceManager = resourceManager,
clock = fixedClock,
canDelete = true,
canAssignToCollections = false,
canAssignToCollections = true,
)
} returns stateWithName.viewState
@@ -1414,7 +1414,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
resourceManager = resourceManager,
clock = fixedClock,
canDelete = true,
canAssignToCollections = false,
canAssignToCollections = true,
)
}
}
@@ -1440,7 +1440,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
),
notes = "mockNotes-1",
canDelete = true,
canAssociateToCollections = false,
canAssociateToCollections = true,
),
)
@@ -1452,7 +1452,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
resourceManager = resourceManager,
clock = fixedClock,
canDelete = true,
canAssignToCollections = false,
canAssignToCollections = true,
)
} returns stateWithName.viewState
@@ -1481,7 +1481,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
resourceManager = resourceManager,
clock = fixedClock,
canDelete = true,
canAssignToCollections = false,
canAssignToCollections = true,
)
}
}

View File

@@ -155,13 +155,11 @@ class CollectionViewExtensionsTest {
@Suppress("MaxLineLength")
@Test
fun `canAssociateToCollections should return false if the user has except password permission at least one collection`() {
fun `canAssociateToCollections should return false if the user doesn't have any manage or edit permissions`() {
val collectionList: List<CollectionView> = listOf(
createEditExceptPasswordsCollectionView(number = 1),
createViewCollectionView(number = 2),
createViewExceptPasswordsCollectionView(number = 3),
createManageCollectionView(number = 4),
createEditCollectionView(number = 5),
)
val collectionIds = collectionList.mapNotNull { it.id }
assertFalse(collectionList.canAssignToCollections(collectionIds))