[PM-11304] Select owner and collection if creating cipher from an org folder

This commit is contained in:
André Bispo
2024-11-07 16:57:35 +00:00
parent 96f118e1e4
commit 9213ad2882
3 changed files with 24 additions and 4 deletions

View File

@@ -110,6 +110,7 @@ class VaultAddEditViewModel @Inject constructor(
?: run {
val vaultAddEditType = VaultAddEditArgs(savedStateHandle).vaultAddEditType
val selectedFolderId = VaultAddEditArgs(savedStateHandle).selectedFolderId
val selectedCollectionId = VaultAddEditArgs(savedStateHandle).selectedCollectionId
val isIndividualVaultDisabled = policyManager
.getActivePolicies(type = PolicyTypeJson.PERSONAL_OWNERSHIP)
.any()
@@ -154,6 +155,7 @@ class VaultAddEditViewModel @Inject constructor(
?: VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
selectedFolderId = selectedFolderId,
selectedCollectionId = selectedCollectionId,
),
isIndividualVaultDisabled = isIndividualVaultDisabled,
type = vaultAddEditType.vaultItemCipherType.toItemType(),
@@ -2099,6 +2101,7 @@ data class VaultAddEditState(
val favorite: Boolean = false,
val customFieldData: List<Custom> = emptyList(),
val notes: String = "",
val selectedCollectionId: String? = null,
val selectedFolderId: String? = null,
val availableFolders: List<Folder> = emptyList(),
val selectedOwnerId: String? = null,

View File

@@ -127,17 +127,23 @@ fun VaultAddEditState.ViewState.appendFolderAndOwnerData(
common = currentContentState.common.copy(
selectedFolderId = folderViewList.toSelectedFolderId(
cipherView = currentContentState.common.originalCipher,
) ?: currentContentState.common.selectedFolderId,
)
?: currentContentState.common.selectedFolderId,
availableFolders = folderViewList.toAvailableFolders(
resourceManager = resourceManager,
),
selectedOwnerId = activeAccount.toSelectedOwnerId(
cipherView = currentContentState.common.originalCipher,
),
)
?: collectionViewList.firstOrNull {
it.id == currentContentState.common.selectedCollectionId
}
?.organizationId,
availableOwners = activeAccount.toAvailableOwners(
collectionViewList = collectionViewList,
cipherView = currentContentState.common.originalCipher,
isIndividualVaultDisabled = isIndividualVaultDisabled,
selectedCollectionId = currentContentState.common.selectedCollectionId,
),
isUnlockWithPasswordEnabled = activeAccount.hasMasterPassword,
hasOrganizations = activeAccount.organizations.isNotEmpty(),
@@ -192,6 +198,7 @@ private fun UserState.Account.toAvailableOwners(
collectionViewList: List<CollectionView>,
cipherView: CipherView?,
isIndividualVaultDisabled: Boolean,
selectedCollectionId: String? = null,
): List<VaultAddEditState.Owner> =
listOfNotNull(
VaultAddEditState.Owner(
@@ -214,9 +221,11 @@ private fun UserState.Account.toAvailableOwners(
VaultCollection(
id = collection.id.orEmpty(),
name = collection.name,
isSelected = cipherView
isSelected = (cipherView
?.collectionIds
?.contains(collection.id) == true,
?.contains(collection.id))
?: (selectedCollectionId != null &&
collection.id == selectedCollectionId),
)
},
)

View File

@@ -541,6 +541,13 @@ class VaultItemListingViewModel @Inject constructor(
)
}
is VaultItemListingState.ItemListingType.Vault.Collection -> {
VaultItemListingEvent.NavigateToAddVaultItem(
vaultItemCipherType = itemListingType.toVaultItemCipherType(),
selectedCollectionId = itemListingType.collectionId,
)
}
is VaultItemListingState.ItemListingType.Vault -> {
VaultItemListingEvent.NavigateToAddVaultItem(
vaultItemCipherType = itemListingType.toVaultItemCipherType(),
@@ -2158,6 +2165,7 @@ sealed class VaultItemListingEvent {
data class NavigateToAddVaultItem(
val vaultItemCipherType: VaultItemCipherType,
val selectedFolderId: String? = null,
val selectedCollectionId: String? = null,
) : VaultItemListingEvent()
/**