Skip to content

Commit

Permalink
[PM-13349] Hide edit button unless item is in at least one non-readOn…
Browse files Browse the repository at this point in the history
…ly collection (#4430)
  • Loading branch information
mpbw2 authored Jan 6, 2025
1 parent 484faed commit b958734
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ class VaultItemViewModel @Inject constructor(
.data
.canAssignToCollections(cipherViewState.data?.collectionIds)

val canEdit = cipherViewState.data?.edit == true

VaultItemStateData(
cipher = cipherViewState.data,
totpCodeItemData = totpCodeData,
canDelete = canDelete,
canAssociateToCollections = canAssignToCollections,
canEdit = canEdit,
)
},
)
Expand Down Expand Up @@ -1066,6 +1069,7 @@ class VaultItemViewModel @Inject constructor(
totpCodeItemData = this.data?.totpCodeItemData,
canDelete = this.data?.canDelete == true,
canAssignToCollections = this.data?.canAssociateToCollections == true,
canEdit = this.data?.canEdit == true,
)
}
?: VaultItemState.ViewState.Error(message = errorText)
Expand Down Expand Up @@ -1303,11 +1307,16 @@ data class VaultItemState(
?.currentCipher
?.deletedDate != null

private val isCipherEditable: Boolean
get() = viewState.asContentOrNull()
?.common
?.canEdit == true

/**
* Whether or not the fab is visible.
*/
val isFabVisible: Boolean
get() = viewState is ViewState.Content && !isCipherDeleted
get() = viewState is ViewState.Content && !isCipherDeleted && isCipherEditable

/**
* Whether or not the cipher is in a collection.
Expand Down Expand Up @@ -1403,6 +1412,7 @@ data class VaultItemState(
val attachments: List<AttachmentItem>?,
val canDelete: Boolean,
val canAssignToCollections: Boolean,
val canEdit: Boolean,
) : Parcelable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import com.bitwarden.vault.CipherView
* @property totpCodeItemData The data for the totp code.
* @property canDelete Whether the item can be deleted.
* @property canAssociateToCollections Whether the item can be associated to a collection.
* @property canEdit Whether the item can be edited.
*/
data class VaultItemStateData(
val cipher: CipherView?,
val totpCodeItemData: TotpCodeItemData?,
val canDelete: Boolean,
val canAssociateToCollections: Boolean,
val canEdit: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fun CipherView.toViewState(
clock: Clock = Clock.systemDefaultZone(),
canDelete: Boolean,
canAssignToCollections: Boolean,
canEdit: Boolean,
): VaultItemState.ViewState =
VaultItemState.ViewState.Content(
common = VaultItemState.ViewState.Content.Common(
Expand Down Expand Up @@ -83,6 +84,7 @@ fun CipherView.toViewState(
.orEmpty(),
canDelete = canDelete,
canAssignToCollections = canAssignToCollections,
canEdit = canEdit,
),
type = when (type) {
CipherType.LOGIN -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,7 @@ private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common =
),
canDelete = true,
canAssignToCollections = true,
canEdit = true,
)

private val DEFAULT_PASSKEY = R.string.created_xy.asText(
Expand Down Expand Up @@ -2793,6 +2794,7 @@ private val EMPTY_COMMON: VaultItemState.ViewState.Content.Common =
attachments = emptyList(),
canDelete = true,
canAssignToCollections = true,
canEdit = true,
)

private val EMPTY_LOGIN_TYPE: VaultItemState.ViewState.Content.ItemType.Login =
Expand Down
Loading

0 comments on commit b958734

Please sign in to comment.