BIT-480, BIT-1386: Allow for saving a text send (#535)

This commit is contained in:
David Perez 2024-01-08 13:41:09 -06:00 committed by Álison Fernandes
parent acb5fce448
commit 4bbda49d74
7 changed files with 60 additions and 29 deletions

View file

@ -19,6 +19,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import java.time.Clock
import javax.inject.Singleton
/**
@ -28,6 +29,10 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
object PlatformManagerModule {
@Provides
@Singleton
fun provideClock(): Clock = Clock.systemDefaultZone()
@Provides
@Singleton
fun provideBitwardenClipboardManager(

View file

@ -22,10 +22,17 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import java.time.Clock
import java.time.Instant
import javax.inject.Inject
private const val KEY_STATE = "state"
/**
* The default amount of time in the future the deletion date should be set to.
*/
private const val DELETION_DATE_OFFSET_SECONDS = 604_800L
/**
* View model for the new send screen.
*/
@ -34,6 +41,7 @@ private const val KEY_STATE = "state"
class AddSendViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
authRepo: AuthRepository,
private val clock: Clock,
private val environmentRepo: EnvironmentRepository,
private val vaultRepo: VaultRepository,
) : BaseViewModel<AddSendState, AddSendEvent, AddSendAction>(
@ -46,6 +54,8 @@ class AddSendViewModel @Inject constructor(
noteInput = "",
isHideEmailChecked = false,
isDeactivateChecked = false,
deletionDate = clock.instant().plusSeconds(DELETION_DATE_OFFSET_SECONDS),
expirationDate = null,
),
selectedType = AddSendState.ViewState.Content.SendType.Text(
input = "",
@ -337,6 +347,8 @@ data class AddSendState(
val noteInput: String,
val isHideEmailChecked: Boolean,
val isDeactivateChecked: Boolean,
val deletionDate: Instant,
val expirationDate: Instant?,
) : Parcelable
/**

View file

@ -10,14 +10,14 @@ import java.time.Instant
/**
* Transforms [AddSendState] into [SendView].
*/
// TODO: The 'key' needs to be updated in order to get the save operation to work (BIT-480)
fun AddSendState.ViewState.Content.toSendView(): SendView =
SendView(
id = null,
accessId = null,
name = common.name,
notes = common.noteInput,
key = "",
// TODO: Set this to null after we update the SDK with an encryption fix (BIT-1398)
key = "91Xo3Wdf0N0Cc5AHJRC3SQ",
password = common.passwordInput.takeUnless { it.isBlank() },
type = selectedType.toSendType(),
file = toSendFileView(),
@ -27,8 +27,8 @@ fun AddSendState.ViewState.Content.toSendView(): SendView =
disabled = common.isDeactivateChecked,
hideEmail = common.isHideEmailChecked,
revisionDate = Instant.now(),
deletionDate = Instant.now(),
expirationDate = null,
deletionDate = common.deletionDate,
expirationDate = common.expirationDate,
)
private fun AddSendState.ViewState.Content.SendType.toSendType(): SendType =
@ -39,7 +39,7 @@ private fun AddSendState.ViewState.Content.SendType.toSendType(): SendType =
private fun AddSendState.ViewState.Content.toSendFileView(): SendFileView? =
(this.selectedType as? AddSendState.ViewState.Content.SendType.File)?.let {
// TODO: Add support for these properties in order to save a file (BIT-480)
// TODO: Add support for these properties in order to save a file (BIT-1085)
SendFileView(
id = "",
fileName = "",

View file

@ -7,5 +7,4 @@ import com.bitwarden.core.SendView
*/
fun SendView.toSendUrl(
baseWebSendUrl: String,
// TODO: The `key` being used here is not correct and should be updated (BIT-1386)
): String = "$baseWebSendUrl$accessId/$key"

View file

@ -30,6 +30,7 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import java.time.Instant
class AddSendScreenTest : BaseComposeTest() {
@ -603,6 +604,8 @@ class AddSendScreenTest : BaseComposeTest() {
noteInput = "",
isHideEmailChecked = false,
isDeactivateChecked = false,
deletionDate = Instant.parse("2023-10-27T12:00:00Z"),
expirationDate = null,
)
private val DEFAULT_SELECTED_TYPE_STATE = AddSendState.ViewState.Content.SendType.Text(

View file

@ -26,9 +26,16 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.time.Clock
import java.time.Instant
import java.util.TimeZone
class AddSendViewModelTest : BaseViewModelTest() {
private val clock = Clock.fixed(
Instant.parse("2023-10-27T12:00:00Z"),
TimeZone.getTimeZone("UTC").toZoneId(),
)
private val mutableUserStateFlow = MutableStateFlow<UserState?>(DEFAULT_USER_STATE)
private val authRepository: AuthRepository = mockk {
every { userStateFlow } returns mutableUserStateFlow
@ -329,6 +336,7 @@ class AddSendViewModelTest : BaseViewModelTest() {
savedStateHandle = SavedStateHandle().apply { set("state", state) },
authRepo = authRepository,
environmentRepo = environmentRepository,
clock = clock,
vaultRepo = vaultRepository,
)
@ -345,6 +353,8 @@ class AddSendViewModelTest : BaseViewModelTest() {
noteInput = "",
isHideEmailChecked = false,
isDeactivateChecked = false,
deletionDate = Instant.parse("2023-11-03T12:00:00Z"),
expirationDate = null,
)
private val DEFAULT_SELECTED_TYPE_STATE = AddSendState.ViewState.Content.SendType.Text(

View file

@ -27,9 +27,8 @@ class AddSendStateExtensionsTest {
val sendView = createMockSendView(number = 1, type = SendType.FILE).copy(
id = null,
accessId = null,
key = "",
key = "91Xo3Wdf0N0Cc5AHJRC3SQ",
accessCount = 0U,
expirationDate = null,
text = null,
file = SendFileView(
id = "",
@ -53,9 +52,8 @@ class AddSendStateExtensionsTest {
val sendView = createMockSendView(number = 1, type = SendType.TEXT).copy(
id = null,
accessId = null,
key = "",
key = "91Xo3Wdf0N0Cc5AHJRC3SQ",
accessCount = 0U,
expirationDate = null,
file = null,
)
mockkStatic(Instant::class)
@ -65,23 +63,27 @@ class AddSendStateExtensionsTest {
assertEquals(sendView, result)
}
companion object {
private val DEFAULT_COMMON_STATE = AddSendState.ViewState.Content.Common(
name = "mockName-1",
maxAccessCount = 1,
passwordInput = "mockPassword-1",
noteInput = "mockNotes-1",
isHideEmailChecked = false,
isDeactivateChecked = false,
deletionDate = Instant.parse("2023-10-27T12:00:00Z"),
expirationDate = Instant.parse("2023-10-27T12:00:00Z"),
)
private val DEFAULT_SELECTED_TYPE_STATE = AddSendState.ViewState.Content.SendType.Text(
input = "mockText-1",
isHideByDefaultChecked = false,
)
private val DEFAULT_VIEW_STATE = AddSendState.ViewState.Content(
common = DEFAULT_COMMON_STATE,
selectedType = DEFAULT_SELECTED_TYPE_STATE,
)
}
}
private val DEFAULT_COMMON_STATE = AddSendState.ViewState.Content.Common(
name = "mockName-1",
maxAccessCount = 1,
passwordInput = "mockPassword-1",
noteInput = "mockNotes-1",
isHideEmailChecked = false,
isDeactivateChecked = false,
)
private val DEFAULT_SELECTED_TYPE_STATE = AddSendState.ViewState.Content.SendType.Text(
input = "mockText-1",
isHideByDefaultChecked = false,
)
private val DEFAULT_VIEW_STATE = AddSendState.ViewState.Content(
common = DEFAULT_COMMON_STATE,
selectedType = DEFAULT_SELECTED_TYPE_STATE,
)