mirror of
https://github.com/bitwarden/android.git
synced 2026-06-05 12:16:32 -05:00
BIT-784: Enforce send options policy (#933)
This commit is contained in:
committed by
Álison Fernandes
parent
c9eca38e08
commit
267fd8d077
@@ -99,6 +99,18 @@ sealed class PolicyInformation {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a policy enforcing rules on the user's add & edit send options.
|
||||
*
|
||||
* @property shouldDisableHideEmail Indicates whether the user should have the ability to hide
|
||||
* their email address from send recipients.
|
||||
*/
|
||||
@Serializable
|
||||
data class SendOptions(
|
||||
@SerialName("disableHideEmail")
|
||||
val shouldDisableHideEmail: Boolean?,
|
||||
) : PolicyInformation()
|
||||
|
||||
/**
|
||||
* Represents a policy enforcing rules on the user's vault timeout settings.
|
||||
*/
|
||||
|
||||
@@ -40,6 +40,9 @@ val SyncResponseJson.Policy.policyInformation: PolicyInformation?
|
||||
PolicyTypeJson.MAXIMUM_VAULT_TIMEOUT -> {
|
||||
Json.decodeFromStringOrNull<PolicyInformation.VaultTimeout>(it)
|
||||
}
|
||||
PolicyTypeJson.SEND_OPTIONS -> {
|
||||
Json.decodeFromStringOrNull<PolicyInformation.SendOptions>(it)
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ inline fun <reified T : PolicyInformation> PolicyManager.getActivePolicies(): Li
|
||||
val type = when (T::class.java) {
|
||||
PolicyInformation.MasterPassword::class.java -> PolicyTypeJson.MASTER_PASSWORD
|
||||
PolicyInformation.PasswordGenerator::class.java -> PolicyTypeJson.PASSWORD_GENERATOR
|
||||
PolicyInformation.SendOptions::class.java -> PolicyTypeJson.SEND_OPTIONS
|
||||
PolicyInformation.VaultTimeout::class.java -> PolicyTypeJson.MAXIMUM_VAULT_TIMEOUT
|
||||
|
||||
else -> {
|
||||
throw IllegalStateException(
|
||||
|
||||
@@ -475,6 +475,7 @@ private fun AddSendOptions(
|
||||
isChecked = state.common.isHideEmailChecked,
|
||||
onCheckedChange = addSendHandlers.onHideEmailToggle,
|
||||
readOnly = sendRestrictionPolicy,
|
||||
enabled = state.common.isHideEmailChecked || state.common.isHideEmailAddressEnabled,
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
BitwardenWideSwitch(
|
||||
|
||||
@@ -7,10 +7,12 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.bitwarden.core.SendView
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.PolicyInformation
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.UserState
|
||||
import com.x8bit.bitwarden.data.platform.manager.PolicyManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.util.getActivePolicies
|
||||
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.baseWebSendUrl
|
||||
@@ -88,6 +90,9 @@ class AddSendViewModel @Inject constructor(
|
||||
noteInput = "",
|
||||
isHideEmailChecked = false,
|
||||
isDeactivateChecked = false,
|
||||
isHideEmailAddressEnabled = !policyManager
|
||||
.getActivePolicies<PolicyInformation.SendOptions>()
|
||||
.any { it.shouldDisableHideEmail ?: false },
|
||||
deletionDate = ZonedDateTime
|
||||
.now(clock)
|
||||
// We want the default time to be midnight, so we remove all values
|
||||
@@ -319,6 +324,7 @@ class AddSendViewModel @Inject constructor(
|
||||
.environment
|
||||
.environmentUrlData
|
||||
.baseWebSendUrl,
|
||||
isHideEmailAddressEnabled = isHideEmailAddressEnabled,
|
||||
)
|
||||
?: AddSendState.ViewState.Error(
|
||||
message = R.string.generic_error_message.asText(),
|
||||
@@ -356,6 +362,7 @@ class AddSendViewModel @Inject constructor(
|
||||
.environment
|
||||
.environmentUrlData
|
||||
.baseWebSendUrl,
|
||||
isHideEmailAddressEnabled = isHideEmailAddressEnabled,
|
||||
)
|
||||
?: AddSendState.ViewState.Error(
|
||||
message = R.string.generic_error_message.asText(),
|
||||
@@ -625,6 +632,11 @@ class AddSendViewModel @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
private val isHideEmailAddressEnabled: Boolean
|
||||
get() = !policyManager
|
||||
.getActivePolicies<PolicyInformation.SendOptions>()
|
||||
.any { it.shouldDisableHideEmail ?: false }
|
||||
|
||||
private inline fun onContent(
|
||||
crossinline block: (AddSendState.ViewState.Content) -> Unit,
|
||||
) {
|
||||
@@ -764,6 +776,7 @@ data class AddSendState(
|
||||
val noteInput: String,
|
||||
val isHideEmailChecked: Boolean,
|
||||
val isDeactivateChecked: Boolean,
|
||||
val isHideEmailAddressEnabled: Boolean,
|
||||
val deletionDate: ZonedDateTime,
|
||||
val expirationDate: ZonedDateTime?,
|
||||
val sendUrl: String?,
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.time.ZonedDateTime
|
||||
fun SendView.toViewState(
|
||||
clock: Clock,
|
||||
baseWebSendUrl: String,
|
||||
isHideEmailAddressEnabled: Boolean,
|
||||
): AddSendState.ViewState.Content =
|
||||
AddSendState.ViewState.Content(
|
||||
common = AddSendState.ViewState.Content.Common(
|
||||
@@ -30,6 +31,7 @@ fun SendView.toViewState(
|
||||
expirationDate = this.expirationDate?.let { ZonedDateTime.ofInstant(it, clock.zone) },
|
||||
sendUrl = this.toSendUrl(baseWebSendUrl),
|
||||
hasPassword = this.hasPassword,
|
||||
isHideEmailAddressEnabled = isHideEmailAddressEnabled,
|
||||
),
|
||||
selectedType = when (type) {
|
||||
SendType.TEXT -> {
|
||||
|
||||
Reference in New Issue
Block a user