PM-13842: Hide ownership when the user has no organizations (#4199)

This commit is contained in:
David Perez 2024-10-30 15:13:15 -05:00 committed by GitHub
parent eaa7923d1f
commit c99e5ce2de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 38 additions and 4 deletions

View file

@ -300,7 +300,7 @@ fun LazyListScope.vaultAddEditCardItems(
) )
} }
if (isAddItemMode) { if (isAddItemMode && commonState.hasOrganizations) {
item { item {
Spacer(modifier = Modifier.height(24.dp)) Spacer(modifier = Modifier.height(24.dp))
BitwardenListHeaderText( BitwardenListHeaderText(

View file

@ -414,7 +414,7 @@ fun LazyListScope.vaultAddEditIdentityItems(
) )
} }
if (isAddItemMode) { if (isAddItemMode && commonState.hasOrganizations) {
item { item {
Spacer(modifier = Modifier.height(24.dp)) Spacer(modifier = Modifier.height(24.dp))
BitwardenListHeaderText( BitwardenListHeaderText(

View file

@ -317,7 +317,7 @@ fun LazyListScope.vaultAddEditLoginItems(
) )
} }
if (isAddItemMode) { if (isAddItemMode && commonState.hasOrganizations) {
item { item {
Spacer(modifier = Modifier.height(24.dp)) Spacer(modifier = Modifier.height(24.dp))
BitwardenListHeaderText( BitwardenListHeaderText(

View file

@ -176,7 +176,7 @@ fun LazyListScope.vaultAddEditSecureNotesItems(
) )
} }
if (isAddItemMode) { if (isAddItemMode && commonState.hasOrganizations) {
item { item {
Spacer(modifier = Modifier.height(24.dp)) Spacer(modifier = Modifier.height(24.dp))
BitwardenListHeaderText( BitwardenListHeaderText(

View file

@ -2114,6 +2114,7 @@ data class VaultAddEditState(
* @property availableFolders The list of folders that this item could be added too. * @property availableFolders The list of folders that this item could be added too.
* @property selectedOwnerId The ID of the owner associated with the item. * @property selectedOwnerId The ID of the owner associated with the item.
* @property availableOwners A list of available owners. * @property availableOwners A list of available owners.
* @property hasOrganizations Indicates if the user is part of any organizations.
*/ */
@Parcelize @Parcelize
data class Common( data class Common(
@ -2129,6 +2130,7 @@ data class VaultAddEditState(
val availableFolders: List<Folder> = emptyList(), val availableFolders: List<Folder> = emptyList(),
val selectedOwnerId: String? = null, val selectedOwnerId: String? = null,
val availableOwners: List<Owner> = emptyList(), val availableOwners: List<Owner> = emptyList(),
val hasOrganizations: Boolean = false,
) : Parcelable { ) : Parcelable {
/** /**

View file

@ -106,6 +106,7 @@ fun CipherView.toViewState(
masterPasswordReprompt = this.reprompt == CipherRepromptType.PASSWORD, masterPasswordReprompt = this.reprompt == CipherRepromptType.PASSWORD,
notes = this.notes.orEmpty(), notes = this.notes.orEmpty(),
availableOwners = emptyList(), availableOwners = emptyList(),
hasOrganizations = false,
customFieldData = this.fields.orEmpty().map { it.toCustomField() }, customFieldData = this.fields.orEmpty().map { it.toCustomField() },
), ),
isIndividualVaultDisabled = isIndividualVaultDisabled, isIndividualVaultDisabled = isIndividualVaultDisabled,
@ -139,6 +140,7 @@ fun VaultAddEditState.ViewState.appendFolderAndOwnerData(
isIndividualVaultDisabled = isIndividualVaultDisabled, isIndividualVaultDisabled = isIndividualVaultDisabled,
), ),
isUnlockWithPasswordEnabled = activeAccount.hasMasterPassword, isUnlockWithPasswordEnabled = activeAccount.hasMasterPassword,
hasOrganizations = activeAccount.organizations.isNotEmpty(),
), ),
) )
} ?: this } ?: this

View file

@ -2361,6 +2361,31 @@ class VaultAddEditScreenTest : BaseComposeTest() {
} }
} }
@Test
fun `ownership section should not be displayed when no organizations present`() {
updateStateWithOwners(selectedOwnerId = "mockOwnerId-2")
composeTestRule
.onNodeWithTextAfterScroll(text = "mockCollectionName-2")
.assertIsDisplayed()
updateStateWithOwners(
selectedOwnerId = null,
availableOwners = listOf(
VaultAddEditState.Owner(
id = null,
name = "placeholder@email.com",
collections = DEFAULT_COLLECTIONS,
),
),
hasOrganizations = false,
)
composeTestRule
.onNodeWithText(text = "mockCollectionName-2")
.assertDoesNotExist()
}
@Test @Test
fun `Collection list should display according to state`() { fun `Collection list should display according to state`() {
updateStateWithOwners(selectedOwnerId = "mockOwnerId-2") updateStateWithOwners(selectedOwnerId = "mockOwnerId-2")
@ -3482,12 +3507,14 @@ class VaultAddEditScreenTest : BaseComposeTest() {
private fun updateStateWithOwners( private fun updateStateWithOwners(
selectedOwnerId: String? = null, selectedOwnerId: String? = null,
availableOwners: List<VaultAddEditState.Owner> = DEFAULT_OWNERS, availableOwners: List<VaultAddEditState.Owner> = DEFAULT_OWNERS,
hasOrganizations: Boolean = true,
) { ) {
mutableStateFlow.update { currentState -> mutableStateFlow.update { currentState ->
updateCommonContent(currentState) { updateCommonContent(currentState) {
copy( copy(
selectedOwnerId = selectedOwnerId, selectedOwnerId = selectedOwnerId,
availableOwners = availableOwners, availableOwners = availableOwners,
hasOrganizations = hasOrganizations,
) )
} }
} }

View file

@ -4026,6 +4026,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
), ),
availableOwners: List<VaultAddEditState.Owner> = createOwnerList(), availableOwners: List<VaultAddEditState.Owner> = createOwnerList(),
selectedOwnerId: String? = null, selectedOwnerId: String? = null,
hasOrganizations: Boolean = true,
): VaultAddEditState.ViewState.Content.Common = ): VaultAddEditState.ViewState.Content.Common =
VaultAddEditState.ViewState.Content.Common( VaultAddEditState.ViewState.Content.Common(
name = name, name = name,
@ -4038,6 +4039,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
originalCipher = originalCipher, originalCipher = originalCipher,
availableFolders = availableFolders, availableFolders = availableFolders,
availableOwners = availableOwners, availableOwners = availableOwners,
hasOrganizations = hasOrganizations,
) )
@Suppress("LongParameterList") @Suppress("LongParameterList")

View file

@ -505,6 +505,7 @@ class CipherViewExtensionsTest {
name = "mockName-1", name = "mockName-1",
), ),
), ),
hasOrganizations = true,
availableOwners = listOf( availableOwners = listOf(
VaultAddEditState.Owner( VaultAddEditState.Owner(
id = null, id = null,