[PM-26395] Hide "my items" collection when item is assigned to other collection (#6018)

This commit is contained in:
aj-rosado 2025-10-15 11:24:31 +01:00 committed by GitHub
parent b8482de96c
commit b8f4129691
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 54 additions and 2 deletions

View File

@ -266,6 +266,8 @@ private fun UserState.Account.toAvailableOwners(
?.contains(collection.id)) ?.contains(collection.id))
?: (selectedCollectionId != null && ?: (selectedCollectionId != null &&
collection.id == selectedCollectionId), collection.id == selectedCollectionId),
isDefaultUserCollection =
collection.type == CollectionType.DEFAULT_USER_COLLECTION,
) )
}, },
) )

View File

@ -64,7 +64,7 @@ fun VaultMoveToOrganizationContent(
} }
collectionItemsSelector( collectionItemsSelector(
collectionList = state.selectedOrganization.collections, collectionList = state.selectableCollections,
onCollectionSelect = collectionSelect, onCollectionSelect = collectionSelect,
isCollectionsTitleVisible = !showOnlyCollections, isCollectionsTitleVisible = !showOnlyCollections,
) )

View File

@ -419,6 +419,28 @@ data class VaultMoveToOrganizationState(
val selectedOrganization: Organization val selectedOrganization: Organization
get() = organizations.first { it.id == selectedOrganizationId } get() = organizations.first { it.id == selectedOrganizationId }
val selectableCollections: List<VaultCollection>
get() {
val collections = organizations
.first { it.id == selectedOrganizationId }
.collections
return collections.filter {
!it.isDefaultUserCollection ||
isDefaultUserCollectionSelected
}
}
private val isDefaultUserCollectionSelected: Boolean
get() =
cipherToMove
?.collectionIds
?.any { collectionId ->
selectedOrganization.collections.any {
it.id == collectionId && it.isDefaultUserCollection
}
}
?: false
/** /**
* Models an organization. * Models an organization.
* *

View File

@ -1,5 +1,6 @@
package com.x8bit.bitwarden.ui.vault.feature.movetoorganization.util package com.x8bit.bitwarden.ui.vault.feature.movetoorganization.util
import com.bitwarden.collections.CollectionType
import com.bitwarden.collections.CollectionView import com.bitwarden.collections.CollectionView
import com.bitwarden.ui.platform.resource.BitwardenString import com.bitwarden.ui.platform.resource.BitwardenString
import com.bitwarden.ui.util.asText import com.bitwarden.ui.util.asText
@ -55,6 +56,8 @@ fun Triple<CipherView?, List<CollectionView>, UserState?>.toViewState():
isSelected = currentCipher isSelected = currentCipher
.collectionIds .collectionIds
.contains(collection.id), .contains(collection.id),
isDefaultUserCollection =
collection.type == CollectionType.DEFAULT_USER_COLLECTION,
) )
}, },
) )

View File

@ -9,10 +9,12 @@ import kotlinx.parcelize.Parcelize
* @property id the collection id. * @property id the collection id.
* @property name the collection name. * @property name the collection name.
* @property isSelected if the collection is selected or not. * @property isSelected if the collection is selected or not.
* @property isDefaultUserCollection if the collection is the user default collection or not.
*/ */
@Parcelize @Parcelize
data class VaultCollection( data class VaultCollection(
val id: String, val id: String,
val name: String, val name: String,
val isSelected: Boolean, val isSelected: Boolean,
val isDefaultUserCollection: Boolean,
) : Parcelable ) : Parcelable

View File

@ -2684,6 +2684,7 @@ class VaultAddEditScreenTest : BitwardenComposeTest() {
id = "mockCollectionId-2", id = "mockCollectionId-2",
name = "mockCollectionName-2", name = "mockCollectionName-2",
isSelected = false, isSelected = false,
isDefaultUserCollection = false,
), ),
), ),
) )
@ -4444,6 +4445,7 @@ class VaultAddEditScreenTest : BitwardenComposeTest() {
id = "mockCollectionId-new", id = "mockCollectionId-new",
name = "mockCollectionName-new", name = "mockCollectionName-new",
isSelected = true, isSelected = true,
isDefaultUserCollection = false,
), ),
) )
@ -4470,6 +4472,7 @@ class VaultAddEditScreenTest : BitwardenComposeTest() {
id = "mockCollectionId-2", id = "mockCollectionId-2",
name = "mockCollectionName-2", name = "mockCollectionName-2",
isSelected = false, isSelected = false,
isDefaultUserCollection = false,
), ),
) )

View File

@ -4806,6 +4806,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
id = "mockId-1", id = "mockId-1",
name = "mockName-1", name = "mockName-1",
isSelected = isCollectionSelected, isSelected = isCollectionSelected,
isDefaultUserCollection = false,
), ),
) )
} else { } else {
@ -4823,6 +4824,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
id = "mockId-1", id = "mockId-1",
name = "mockName-1", name = "mockName-1",
isSelected = false, isSelected = false,
isDefaultUserCollection = false,
), ),
) )

View File

@ -524,7 +524,7 @@ class CipherViewExtensionsTest {
val expected = createSecureNoteViewState( val expected = createSecureNoteViewState(
cipherView = mockCipherView, cipherView = mockCipherView,
availableOwners = listOf(ORGANIZATION_OWNER), availableOwners = listOf(ORGANIZATION_OWNER_DEFAULT_COLLECTION),
availableFolders = listOf(NO_FOLDER_ITEM), availableFolders = listOf(NO_FOLDER_ITEM),
) )
@ -803,6 +803,20 @@ private val ORGANIZATION_OWNER = VaultAddEditState.Owner(
id = "mockId-1", id = "mockId-1",
name = "mockName-1", name = "mockName-1",
isSelected = true, isSelected = true,
isDefaultUserCollection = false,
),
),
)
private val ORGANIZATION_OWNER_DEFAULT_COLLECTION = VaultAddEditState.Owner(
id = "mockOrganizationId-1",
name = "organizationName",
collections = listOf(
VaultCollection(
id = "mockId-1",
name = "mockName-1",
isSelected = true,
isDefaultUserCollection = true,
), ),
), ),
) )

View File

@ -189,6 +189,7 @@ class VaultMoveToOrganizationScreenTest : BitwardenComposeTest() {
id = "mockId-2", id = "mockId-2",
name = "mockName-2", name = "mockName-2",
isSelected = false, isSelected = false,
isDefaultUserCollection = false,
), ),
), ),
), ),
@ -230,6 +231,7 @@ class VaultMoveToOrganizationScreenTest : BitwardenComposeTest() {
id = "mockId-1", id = "mockId-1",
name = "mockName-1", name = "mockName-1",
isSelected = true, isSelected = true,
isDefaultUserCollection = false,
), ),
), ),
) )

View File

@ -150,6 +150,7 @@ class VaultMoveToOrganizationViewModelTest : BaseViewModelTest() {
id = "mockId-1", id = "mockId-1",
name = "mockName-1", name = "mockName-1",
isSelected = true, isSelected = true,
isDefaultUserCollection = false,
), ),
) )
val expectedState = createVaultMoveToOrganizationState( val expectedState = createVaultMoveToOrganizationState(

View File

@ -29,6 +29,7 @@ fun createMockOrganization(
id = "mockId-$number", id = "mockId-$number",
name = "mockName-$number", name = "mockName-$number",
isSelected = isCollectionSelected, isSelected = isCollectionSelected,
isDefaultUserCollection = false,
), ),
), ),
) )