Ensure more overflow action types get reprompts on Search (#940)

This commit is contained in:
Brian Yencho
2024-02-01 02:04:06 -06:00
committed by Álison Fernandes
parent b800b77194
commit 624e60fd71
4 changed files with 61 additions and 217 deletions

View File

@@ -133,28 +133,13 @@ fun SearchContent(
showConfirmationDialog = option
}
is ListingItemOverflowAction.VaultAction.EditClick -> {
if (it.shouldDisplayMasterPasswordReprompt) {
is ListingItemOverflowAction.VaultAction -> {
if (option.requiresPasswordReprompt &&
it.shouldDisplayMasterPasswordReprompt
) {
masterPasswordRepromptData =
MasterPasswordRepromptData(
cipherId = it.id,
type = MasterPasswordRepromptData.Type.Edit,
)
} else {
searchHandlers.onOverflowItemClick(option)
}
}
is ListingItemOverflowAction.VaultAction.CopyPasswordClick -> {
if (it.shouldDisplayMasterPasswordReprompt) {
masterPasswordRepromptData =
MasterPasswordRepromptData(
cipherId = it.id,
type = MasterPasswordRepromptData
.Type
.CopyPassword(
password = option.password,
),
MasterPasswordRepromptData.OverflowItem(
action = option,
)
} else {
searchHandlers.onOverflowItemClick(option)
@@ -195,24 +180,19 @@ private fun AutofillSelectionDialog(
onMasterPasswordRepromptRequest: (MasterPasswordRepromptData) -> Unit,
onDismissRequest: () -> Unit,
) {
val selectionCallback: (SearchState.DisplayItem, MasterPasswordRepromptData.Type) -> Unit =
{ item, type ->
val selectionCallback: (SearchState.DisplayItem, MasterPasswordRepromptData) -> Unit =
{ item, data ->
onDismissRequest()
if (item.shouldDisplayMasterPasswordReprompt) {
onMasterPasswordRepromptRequest(
MasterPasswordRepromptData(
cipherId = item.id,
type = type,
),
)
onMasterPasswordRepromptRequest(data)
} else {
when (type) {
MasterPasswordRepromptData.Type.Autofill -> {
onAutofillItemClick(item.id)
when (data) {
is MasterPasswordRepromptData.Autofill -> {
onAutofillItemClick(data.cipherId)
}
MasterPasswordRepromptData.Type.AutofillAndSave -> {
onAutofillAndSaveItemClick(item.id)
is MasterPasswordRepromptData.AutofillAndSave -> {
onAutofillAndSaveItemClick(data.cipherId)
}
else -> Unit
@@ -229,7 +209,7 @@ private fun AutofillSelectionDialog(
onClick = {
selectionCallback(
displayItem,
MasterPasswordRepromptData.Type.Autofill,
MasterPasswordRepromptData.Autofill(cipherId = displayItem.id),
)
},
)
@@ -240,7 +220,7 @@ private fun AutofillSelectionDialog(
onClick = {
selectionCallback(
displayItem,
MasterPasswordRepromptData.Type.AutofillAndSave,
MasterPasswordRepromptData.AutofillAndSave(cipherId = displayItem.id),
)
},
)

View File

@@ -526,42 +526,27 @@ class SearchViewModel @Inject constructor(
data: MasterPasswordRepromptData,
) {
// Complete the deferred actions
val cipherId = data.cipherId
when (val type = data.type) {
MasterPasswordRepromptData.Type.Autofill -> {
when (data) {
is MasterPasswordRepromptData.Autofill -> {
trySendAction(
SearchAction.AutofillItemClick(
itemId = cipherId,
itemId = data.cipherId,
),
)
}
MasterPasswordRepromptData.Type.AutofillAndSave -> {
is MasterPasswordRepromptData.AutofillAndSave -> {
trySendAction(
SearchAction.AutofillAndSaveItemClick(
itemId = cipherId,
itemId = data.cipherId,
),
)
}
MasterPasswordRepromptData.Type.Edit -> {
is MasterPasswordRepromptData.OverflowItem -> {
trySendAction(
SearchAction.OverflowOptionClick(
overflowAction = ListingItemOverflowAction.VaultAction.EditClick(
cipherId = cipherId,
),
),
)
}
is MasterPasswordRepromptData.Type.CopyPassword -> {
trySendAction(
SearchAction.OverflowOptionClick(
overflowAction = ListingItemOverflowAction
.VaultAction
.CopyPasswordClick(
password = type.password,
),
overflowAction = data.action,
),
)
}
@@ -1116,44 +1101,31 @@ sealed class SearchEvent {
}
/**
* Data tracking the type of request that triggered a master password reprompt during an autofill
* selection process.
* Data tracking the type of request that triggered a master password reprompt.
*/
@Parcelize
data class MasterPasswordRepromptData(
val cipherId: String,
val type: Type,
) : Parcelable {
sealed class MasterPasswordRepromptData : Parcelable {
/**
* The type of action that requires the prompt.
* Autofill was selected.
*/
sealed class Type : Parcelable {
@Parcelize
data class Autofill(
val cipherId: String,
) : MasterPasswordRepromptData()
/**
* Autofill was selected.
*/
@Parcelize
data object Autofill : Type()
/**
* Autofill-and-save was selected.
*/
@Parcelize
data class AutofillAndSave(
val cipherId: String,
) : MasterPasswordRepromptData()
/**
* Autofill-and-save was selected.
*/
@Parcelize
data object AutofillAndSave : Type()
/**
* Edit was selected.
*/
@Parcelize
data object Edit : Type()
/**
* Copy password was selected.
*/
@Parcelize
data class CopyPassword(
val password: String,
) : Type()
}
/**
* A cipher overflow menu item action was selected.
*/
@Parcelize
data class OverflowItem(
val action: ListingItemOverflowAction.VaultAction,
) : MasterPasswordRepromptData()
}