Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(selectedOwnerId = "mockOwnerId-2")

composeTestRule
.onNodeWithTextAfterScroll(text = "mockCollectionName-2")
.assertIsDisplayed()

updateStateWithOwners(
selectedOwnerId = null,
availableOwners = listOf(
VaultAddEditState.Owner(
id = null,
name = "[email protected]",
collections = DEFAULT_COLLECTIONS,
),
),
hasOrganizations = false,
)

composeTestRule
.onNodeWithText(text = "mockCollectionName-2")
.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