Skip to content

Commit 7ea0952

Browse files
committed
use SDK provided state instead
1 parent 142aa40 commit 7ea0952

File tree

9 files changed

+23
-235
lines changed

9 files changed

+23
-235
lines changed

app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import com.x8bit.bitwarden.ui.vault.feature.item.model.VaultItemStateData
3131
import com.x8bit.bitwarden.ui.vault.feature.item.util.toViewState
3232
import com.x8bit.bitwarden.ui.vault.feature.util.canAssignToCollections
3333
import com.x8bit.bitwarden.ui.vault.feature.util.hasDeletePermissionInAtLeastOneCollection
34-
import com.x8bit.bitwarden.ui.vault.feature.util.hasEditPermissionInAtLeastOneCollection
3534
import com.x8bit.bitwarden.ui.vault.model.VaultCardBrand
3635
import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType
3736
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -117,18 +116,11 @@ class VaultItemViewModel @Inject constructor(
117116
.data
118117
.canAssignToCollections(cipherViewState.data?.collectionIds)
119118

120-
val canEdit = collectionsState
121-
.data
122-
.hasEditPermissionInAtLeastOneCollection(
123-
cipherViewState.data?.collectionIds,
124-
)
125-
126119
VaultItemStateData(
127120
cipher = cipherViewState.data,
128121
totpCodeItemData = totpCodeData,
129122
canDelete = canDelete,
130123
canAssociateToCollections = canAssignToCollections,
131-
canEdit = canEdit,
132124
)
133125
},
134126
)
@@ -1048,7 +1040,6 @@ class VaultItemViewModel @Inject constructor(
10481040
totpCodeItemData = this.data?.totpCodeItemData,
10491041
canDelete = this.data?.canDelete == true,
10501042
canAssignToCollections = this.data?.canAssociateToCollections == true,
1051-
canEdit = this.data?.canEdit == true,
10521043
)
10531044
}
10541045
?: VaultItemState.ViewState.Error(message = errorText)
@@ -1289,7 +1280,8 @@ data class VaultItemState(
12891280
private val isCipherEditable: Boolean
12901281
get() = viewState.asContentOrNull()
12911282
?.common
1292-
?.canEdit == true
1283+
?.currentCipher
1284+
?.edit == true
12931285

12941286
/**
12951287
* Whether or not the fab is visible.
@@ -1391,7 +1383,6 @@ data class VaultItemState(
13911383
val attachments: List<AttachmentItem>?,
13921384
val canDelete: Boolean,
13931385
val canAssignToCollections: Boolean,
1394-
val canEdit: Boolean,
13951386
) : Parcelable {
13961387

13971388
/**

app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import com.bitwarden.vault.CipherView
99
* @property totpCodeItemData The data for the totp code.
1010
* @property canDelete Whether the item can be deleted.
1111
* @property canAssociateToCollections Whether the item can be associated to a collection.
12-
* @property canEdit Whether the item can be edited.
1312
*/
1413
data class VaultItemStateData(
1514
val cipher: CipherView?,
1615
val totpCodeItemData: TotpCodeItemData?,
1716
val canDelete: Boolean,
1817
val canAssociateToCollections: Boolean,
19-
val canEdit: Boolean,
2018
)

app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ fun CipherView.toViewState(
4141
clock: Clock = Clock.systemDefaultZone(),
4242
canDelete: Boolean,
4343
canAssignToCollections: Boolean,
44-
canEdit: Boolean,
4544
): VaultItemState.ViewState =
4645
VaultItemState.ViewState.Content(
4746
common = VaultItemState.ViewState.Content.Common(
@@ -84,7 +83,6 @@ fun CipherView.toViewState(
8483
.orEmpty(),
8584
canDelete = canDelete,
8685
canAssignToCollections = canAssignToCollections,
87-
canEdit = canEdit,
8886
),
8987
type = when (type) {
9088
CipherType.LOGIN -> {

app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,3 @@ fun List<CollectionView>?.canAssignToCollections(currentCollectionIds: List<Stri
122122
itemIsInCollection && (!it.manage || it.readOnly)
123123
}
124124
?: true
125-
126-
/**
127-
* Checks if the user has edit permission in at least one collection.
128-
*
129-
* Editing is allowed when the item is in any collection that isn't read-only.
130-
*/
131-
fun List<CollectionView>?.hasEditPermissionInAtLeastOneCollection(
132-
collectionIds: List<String>?,
133-
): Boolean {
134-
if (this.isNullOrEmpty() || collectionIds.isNullOrEmpty()) return true
135-
return this
136-
.any { collectionView ->
137-
collectionIds
138-
.contains(collectionView.id)
139-
.let { isInCollection -> isInCollection && !collectionView.readOnly }
140-
}
141-
}

app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,6 @@ private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common =
26982698
),
26992699
canDelete = true,
27002700
canAssignToCollections = true,
2701-
canEdit = true,
27022701
)
27032702

27042703
private val DEFAULT_PASSKEY = R.string.created_xy.asText(
@@ -2782,7 +2781,6 @@ private val EMPTY_COMMON: VaultItemState.ViewState.Content.Common =
27822781
attachments = emptyList(),
27832782
canDelete = true,
27842783
canAssignToCollections = true,
2785-
canEdit = true,
27862784
)
27872785

27882786
private val EMPTY_LOGIN_TYPE: VaultItemState.ViewState.Content.ItemType.Login =

0 commit comments

Comments
 (0)