mirror of
https://github.com/bitwarden/android.git
synced 2026-05-09 05:20:24 -05:00
Compare commits
4 Commits
qrcode/2-u
...
821
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d192065054 | ||
|
|
5f40ac3004 | ||
|
|
7746b6c0c7 | ||
|
|
6160402186 |
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user