[PM-10762] Remove Passkey button should be hidden when I have Can View permission (#3829)

This commit is contained in:
Carlos Gonçalves 2024-08-29 16:40:01 +01:00 committed by GitHub
parent f778d7ecd1
commit 2a057bb1fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 35 additions and 3 deletions

View file

@ -92,7 +92,7 @@ fun LazyListScope.vaultAddEditLoginItems(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
canRemovePasskey = loginState.canViewPassword,
canRemovePasskey = loginState.canRemovePasskey,
loginItemTypeHandlers = loginItemTypeHandlers,
)
}

View file

@ -2054,6 +2054,7 @@ data class VaultAddEditState(
* @property totp The current TOTP (if applicable).
* @property canViewPassword Indicates whether the current user can view and copy
* passwords associated with the login item.
* @property canEditItem Indicates whether the current user can edit the login item.
* @property fido2CredentialCreationDateTime Date and time the FIDO 2 credential was
* created.
*/
@ -2063,6 +2064,7 @@ data class VaultAddEditState(
val password: String = "",
val totp: String? = null,
val canViewPassword: Boolean = true,
val canEditItem: Boolean = true,
val uriList: List<UriItem> = listOf(
UriItem(
id = UUID.randomUUID().toString(),
@ -2074,6 +2076,11 @@ data class VaultAddEditState(
val fido2CredentialCreationDateTime: Text? = null,
) : ItemType() {
override val itemTypeOption: ItemTypeOption get() = ItemTypeOption.LOGIN
/**
* Indicates whether the passkey can or cannot be removed.
*/
val canRemovePasskey: Boolean get() = this.canEditItem && this.canViewPassword
}
/**

View file

@ -48,6 +48,7 @@ fun CipherView.toViewState(
password = login?.password.orEmpty(),
totp = login?.totp,
canViewPassword = this.viewPassword,
canEditItem = this.edit,
uriList = login?.uris.toUriItems(),
fido2CredentialCreationDateTime = login
?.fido2Credentials

View file

@ -81,7 +81,7 @@ fun createMockCipherView(
passwordHistory = listOf(createMockPasswordHistoryView(number = number, clock)),
reprompt = repromptType,
secureNote = createMockSecureNoteView().takeIf { cipherType == CipherType.SECURE_NOTE },
edit = false,
edit = true,
organizationUseTotp = false,
viewPassword = true,
localData = null,

View file

@ -925,6 +925,29 @@ class VaultAddEditScreenTest : BaseComposeTest() {
type = VaultAddEditState.ViewState.Content.ItemType.Login(
fido2CredentialCreationDateTime = "fido2Credentials".asText(),
canViewPassword = false,
canEditItem = false,
),
isIndividualVaultDisabled = false,
),
)
}
composeTestRule
.onNodeWithTextAfterScroll("Passkey")
.assertTextEquals("Passkey", "fido2Credentials")
.assertIsEnabled()
composeTestRule
.onNodeWithContentDescription("Remove passkey")
.assertDoesNotExist()
mutableStateFlow.update {
it.copy(
viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(),
type = VaultAddEditState.ViewState.Content.ItemType.Login(
fido2CredentialCreationDateTime = "fido2Credentials".asText(),
canViewPassword = false,
canEditItem = true,
),
isIndividualVaultDisabled = false,
),
@ -946,6 +969,7 @@ class VaultAddEditScreenTest : BaseComposeTest() {
type = VaultAddEditState.ViewState.Content.ItemType.Login(
fido2CredentialCreationDateTime = "fido2Credentials".asText(),
canViewPassword = true,
canEditItem = true,
),
isIndividualVaultDisabled = false,
),

View file

@ -470,7 +470,7 @@ private val DEFAULT_BASE_CIPHER_VIEW: CipherView = CipherView(
favorite = false,
reprompt = CipherRepromptType.PASSWORD,
organizationUseTotp = false,
edit = false,
edit = true,
viewPassword = false,
localData = null,
attachments = null,