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

This commit is contained in:
David Perez 2024-10-30 10:39:08 -05:00
parent fab018782c
commit c685f92d5c
No known key found for this signature in database
GPG key ID: 3E29BD8B1BF090AC
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 {
Spacer(modifier = Modifier.height(24.dp))
BitwardenListHeaderText(

View file

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

View file

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

View file

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

View file

@ -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(
@ -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 {
/**

View file

@ -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,
@ -139,6 +140,7 @@ fun VaultAddEditState.ViewState.appendFolderAndOwnerData(
isIndividualVaultDisabled = isIndividualVaultDisabled,
),
isUnlockWithPasswordEnabled = activeAccount.hasMasterPassword,
hasOrganizations = activeAccount.organizations.isNotEmpty(),
),
)
} ?: 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
fun `Collection list should display according to state`() {
updateStateWithOwners(selectedOwnerId = "mockOwnerId-2")
@ -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,
)
}
}

View file

@ -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,
@ -4038,6 +4039,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
originalCipher = originalCipher,
availableFolders = availableFolders,
availableOwners = availableOwners,
hasOrganizations = hasOrganizations,
)
@Suppress("LongParameterList")

View file

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