Skip to content

Commit

Permalink
PM-13842: Hide ownership when the user has no organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
david-livefront committed Oct 30, 2024
1 parent fab0187 commit 0bb5a48
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ fun LazyListScope.vaultAddEditCardItems(
)
}

if (isAddItemMode) {
if (isAddItemMode && commonState.hasOrganizations) {
item {
Spacer(modifier = Modifier.height(24.dp))
BitwardenListHeaderText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ fun LazyListScope.vaultAddEditIdentityItems(
)
}

if (isAddItemMode) {
if (isAddItemMode && commonState.hasOrganizations) {
item {
Spacer(modifier = Modifier.height(24.dp))
BitwardenListHeaderText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ fun LazyListScope.vaultAddEditLoginItems(
)
}

if (isAddItemMode) {
if (isAddItemMode && commonState.hasOrganizations) {
item {
Spacer(modifier = Modifier.height(24.dp))
BitwardenListHeaderText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fun LazyListScope.vaultAddEditSecureNotesItems(
)
}

if (isAddItemMode) {
if (isAddItemMode && commonState.hasOrganizations) {
item {
Spacer(modifier = Modifier.height(24.dp))
BitwardenListHeaderText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,7 @@ data class VaultAddEditState(
* @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 availableOwners A list of available owners.
* @property hasOrganizations Indicates if the user is part of any organizations.
*/
@Parcelize
data class Common(
Expand All @@ -2129,6 +2130,7 @@ data class VaultAddEditState(
val availableFolders: List<Folder> = emptyList(),
val selectedOwnerId: String? = null,
val availableOwners: List<Owner> = emptyList(),
val hasOrganizations: Boolean = false,
) : Parcelable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fun CipherView.toViewState(
masterPasswordReprompt = this.reprompt == CipherRepromptType.PASSWORD,
notes = this.notes.orEmpty(),
availableOwners = emptyList(),
hasOrganizations = false,
customFieldData = this.fields.orEmpty().map { it.toCustomField() },
),
isIndividualVaultDisabled = isIndividualVaultDisabled,
Expand Down Expand Up @@ -139,6 +140,7 @@ fun VaultAddEditState.ViewState.appendFolderAndOwnerData(
isIndividualVaultDisabled = isIndividualVaultDisabled,
),
isUnlockWithPasswordEnabled = activeAccount.hasMasterPassword,
hasOrganizations = activeAccount.organizations.isNotEmpty(),
),
)
} ?: this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2361,6 +2361,31 @@ class VaultAddEditScreenTest : BaseComposeTest() {
}
}

@Test
fun `ownership section should not be displayed when no organizations present`() {
updateStateWithOwners()

composeTestRule
.onNodeWithTextAfterScroll("[email protected]")
.assertExists()

updateStateWithOwners(
selectedOwnerId = "mockOwnerId-1",
availableOwners = listOf(
VaultAddEditState.Owner(
id = "mockOwnerId-1",
name = "[email protected]",
collections = emptyList(),
),
),
hasOrganizations = false,
)

composeTestRule
.onNodeWithText("[email protected]")
.assertDoesNotExist()
}

@Test
fun `Collection list should display according to state`() {
updateStateWithOwners(selectedOwnerId = "mockOwnerId-2")
Expand Down Expand Up @@ -3482,12 +3507,14 @@ class VaultAddEditScreenTest : BaseComposeTest() {
private fun updateStateWithOwners(
selectedOwnerId: String? = null,
availableOwners: List<VaultAddEditState.Owner> = DEFAULT_OWNERS,
hasOrganizations: Boolean = true,
) {
mutableStateFlow.update { currentState ->
updateCommonContent(currentState) {
copy(
selectedOwnerId = selectedOwnerId,
availableOwners = availableOwners,
hasOrganizations = hasOrganizations,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4026,6 +4026,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
),
availableOwners: List<VaultAddEditState.Owner> = createOwnerList(),
selectedOwnerId: String? = null,
hasOrganizations: Boolean = true,
): VaultAddEditState.ViewState.Content.Common =
VaultAddEditState.ViewState.Content.Common(
name = name,
Expand All @@ -4038,6 +4039,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
originalCipher = originalCipher,
availableFolders = availableFolders,
availableOwners = availableOwners,
hasOrganizations = hasOrganizations,
)

@Suppress("LongParameterList")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ class CipherViewExtensionsTest {
name = "mockName-1",
),
),
hasOrganizations = true,
availableOwners = listOf(
VaultAddEditState.Owner(
id = null,
Expand Down

0 comments on commit 0bb5a48

Please sign in to comment.