Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
}

@Test
fun testWebPortalPasswordButtonIsHidden() {
fun testWebPortalPasswordButtonIsVisibleForUserWithoutCustomerFesUrl() {
activeActivityRule?.launch(intent)
registerAllIdlingResources()

Expand All @@ -700,9 +700,9 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
onView(withId(R.id.editTextEmailSubject))
.perform(scrollTo(), click())

//because account.useCustomerFesUrl == false btnSetWebPortalPassword should not be visible
//for users with account.useCustomerFesUrl == false btnSetWebPortalPassword should be visible too
onView(withId(R.id.btnSetWebPortalPassword))
.check(matches(not(isDisplayed())))
.check(matches(isDisplayed()))
}

private fun checkIsDisplayedEncryptedAttributes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,15 +690,10 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),
for (recipient in composeMsgViewModel.allRecipients) {
val recipientWithPubKeys = recipient.value.recipientWithPubKeys
if (!recipientWithPubKeys.hasAtLeastOnePubKey()) {
return if (isPasswordProtectedFunctionalityEnabled()) {
if (composeMsgViewModel.webPortalPasswordStateFlow.value.isEmpty()) {
showNoPgpFoundDialog(recipientWithPubKeys)
true
} else continue
} else {
return if (composeMsgViewModel.webPortalPasswordStateFlow.value.isEmpty()) {
showNoPgpFoundDialog(recipientWithPubKeys)
true
}
} else continue
}

if (!recipientWithPubKeys.hasNotExpiredPubKey()) {
Expand Down Expand Up @@ -997,8 +992,7 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),
navController?.navigate(
CreateMessageFragmentDirections.actionCreateMessageFragmentToNoPgpFoundDialogFragment(
recipientWithPubKeys = recipient,
isRemoveActionEnabled = true,
isProtectingWithPasswordEnabled = isPasswordProtectedFunctionalityEnabled()
isRemoveActionEnabled = true
)
)
}
Expand Down Expand Up @@ -1236,17 +1230,15 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),
countingIdlingResource?.incrementSafely(this@CreateMessageFragment)
}

if (isPasswordProtectedFunctionalityEnabled()) {
val hasRecipientsWithoutPgp =
recipients.any { recipient -> !recipient.value.recipientWithPubKeys.hasAtLeastOnePubKey() }
if (hasRecipientsWithoutPgp &&
composeMsgViewModel.msgEncryptionType == MessageEncryptionType.ENCRYPTED
) {
binding?.btnSetWebPortalPassword?.visible()
} else {
binding?.btnSetWebPortalPassword?.gone()
composeMsgViewModel.setWebPortalPassword()
}
val hasRecipientsWithoutPgp =
recipients.any { recipient -> !recipient.value.recipientWithPubKeys.hasAtLeastOnePubKey() }
if (hasRecipientsWithoutPgp &&
composeMsgViewModel.msgEncryptionType == MessageEncryptionType.ENCRYPTED
) {
binding?.btnSetWebPortalPassword?.visible()
} else {
binding?.btnSetWebPortalPassword?.gone()
composeMsgViewModel.setWebPortalPassword()
}

if (recipients.none { it.value.isUpdating }) {
Expand Down Expand Up @@ -1316,33 +1308,31 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),

lifecycleScope.launchWhenStarted {
composeMsgViewModel.webPortalPasswordStateFlow.collect { webPortalPassword ->
if (isPasswordProtectedFunctionalityEnabled()) {
binding?.btnSetWebPortalPassword?.apply {
if (webPortalPassword.isEmpty()) {
setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_password_not_protected_white_24,
0,
0,
0
binding?.btnSetWebPortalPassword?.apply {
if (webPortalPassword.isEmpty()) {
setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_password_not_protected_white_24,
0,
0,
0
)
setText(R.string.tap_to_protect_with_web_portal_password)
background?.colorFilter =
BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
ContextCompat.getColor(context, R.color.orange), BlendModeCompat.MODULATE
)
setText(R.string.tap_to_protect_with_web_portal_password)
background?.colorFilter =
BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
ContextCompat.getColor(context, R.color.orange), BlendModeCompat.MODULATE
)
} else {
setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_password_protected_white_24,
0,
0,
0
} else {
setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_password_protected_white_24,
0,
0,
0
)
setText(R.string.web_portal_password_added)
background?.colorFilter =
BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
ContextCompat.getColor(context, R.color.colorPrimary), BlendModeCompat.MODULATE
)
setText(R.string.web_portal_password_added)
background?.colorFilter =
BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
ContextCompat.getColor(context, R.color.colorPrimary), BlendModeCompat.MODULATE
)
}
}
}
}
Expand Down Expand Up @@ -1475,28 +1465,26 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),
return false
}

if (isPasswordProtectedFunctionalityEnabled()) {
val password = composeMsgViewModel.webPortalPasswordStateFlow.value
if (password.isNotEmpty()) {
val keysStorage = KeysStorageImpl.getInstance(requireContext())
if (keysStorage.hasPassphrase(Passphrase(password.toString().toCharArray()))) {
showInfoDialog(
dialogTitle = getString(R.string.warning),
dialogMsg = getString(R.string.warning_use_private_key_pass_phrase_as_password)
)
return false
}
val password = composeMsgViewModel.webPortalPasswordStateFlow.value
if (password.isNotEmpty()) {
val keysStorage = KeysStorageImpl.getInstance(requireContext())
if (keysStorage.hasPassphrase(Passphrase(password.toString().toCharArray()))) {
showInfoDialog(
dialogTitle = getString(R.string.warning),
dialogMsg = getString(R.string.warning_use_private_key_pass_phrase_as_password)
)
return false
}

if (binding?.editTextEmailSubject?.text.toString() == password.toString()) {
showInfoDialog(
dialogTitle = getString(R.string.warning),
dialogMsg = getString(
R.string.warning_use_subject_as_password,
getString(R.string.app_name)
)
if (binding?.editTextEmailSubject?.text.toString() == password.toString()) {
showInfoDialog(
dialogTitle = getString(R.string.warning),
dialogMsg = getString(
R.string.warning_use_subject_as_password,
getString(R.string.app_name)
)
return false
}
)
return false
}
}
}
Expand Down Expand Up @@ -1527,19 +1515,14 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),
}

private fun usePasswordIfNeeded(): CharArray? {
return if (isPasswordProtectedFunctionalityEnabled()) {
for (recipient in composeMsgViewModel.allRecipients) {
val recipientWithPubKeys = recipient.value.recipientWithPubKeys
if (!recipientWithPubKeys.hasAtLeastOnePubKey()) {
return composeMsgViewModel.webPortalPasswordStateFlow.value.toString().toCharArray()
}
for (recipient in composeMsgViewModel.allRecipients) {
val recipientWithPubKeys = recipient.value.recipientWithPubKeys
if (!recipientWithPubKeys.hasAtLeastOnePubKey()) {
return composeMsgViewModel.webPortalPasswordStateFlow.value.toString().toCharArray()
}
null
} else null
}
}

private fun isPasswordProtectedFunctionalityEnabled(): Boolean {
return accountViewModel.activeAccountLiveData.value?.useCustomerFesUrl ?: return false
return null
}

private fun subscribeToSetWebPortalPassword() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ class NoPgpFoundDialogFragment : BaseDialogFragment(), DialogInterface.OnClickLi
super.onCreate(savedInstanceState)
dialogItems = ArrayList()

if (args.isProtectingWithPasswordEnabled) {
dialogItems.add(
DialogItem(
iconResourceId = R.drawable.ic_password_protected_gray_48,
title = getString(R.string.protect_with_password),
id = RESULT_CODE_PROTECT_WITH_PASSWORD
)
dialogItems.add(
DialogItem(
iconResourceId = R.drawable.ic_password_protected_gray_48,
title = getString(R.string.protect_with_password),
id = RESULT_CODE_PROTECT_WITH_PASSWORD
)
}
)

dialogItems.add(
DialogItem(
Expand Down
4 changes: 0 additions & 4 deletions FlowCrypt/src/main/res/navigation/create_msg_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,5 @@
<argument
android:name="isRemoveActionEnabled"
app:argType="boolean" />
<argument
android:name="isProtectingWithPasswordEnabled"
android:defaultValue="false"
app:argType="boolean" />
</dialog>
</navigation>