feat: move access control to feature flag

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2023-10-21 02:04:34 +02:00
parent 769cf99529
commit fddb926770
4 changed files with 25 additions and 23 deletions

View File

@ -3,20 +3,25 @@ package chat.revolt.api.settings
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import chat.revolt.api.RevoltAPI
annotation class FeatureFlag(val name: String) annotation class FeatureFlag(val name: String)
annotation class Treatment(val description: String) annotation class Treatment(val description: String)
@FeatureFlag("TiramisuFilePicker") @FeatureFlag("ClosedBetaAccessControl")
enum class FilePickerFeatureFlagVariates { sealed class ClosedBetaAccessControlVariates {
@Treatment("Use the READ_MEDIA_IMAGES or READ_MEDIA_VIDEO permissions introduced in Android Tiramisu") @Treatment("Restrict access to the app to users that meet certain or all criteria (implementation-specific)")
TiramisuMediaPermissions, data class Restricted(val predicate: () -> Boolean) : ClosedBetaAccessControlVariates()
@Treatment("Use the DocumentsUI picker introduced in Android KitKat") @Treatment("Allow access to the app to all users")
DocumentsUI data object Unrestricted : ClosedBetaAccessControlVariates()
} }
object FeatureFlags { object FeatureFlags {
@FeatureFlag("TiramisuFilePicker") @FeatureFlag("ClosedBetaAccessControl")
var filePickerType by mutableStateOf(FilePickerFeatureFlagVariates.TiramisuMediaPermissions) var closedBetaAccessControl by mutableStateOf<ClosedBetaAccessControlVariates>(
} ClosedBetaAccessControlVariates.Restricted {
RevoltAPI.channelCache.containsKey("01H7X2KRB0CA4QDSMB4N7WGERF")
})
}

View File

@ -73,7 +73,9 @@ import chat.revolt.api.realtime.RealtimeSocket
import chat.revolt.api.routes.server.fetchMembers import chat.revolt.api.routes.server.fetchMembers
import chat.revolt.api.schemas.ChannelType import chat.revolt.api.schemas.ChannelType
import chat.revolt.api.schemas.User import chat.revolt.api.schemas.User
import chat.revolt.api.settings.ClosedBetaAccessControlVariates
import chat.revolt.api.settings.FeatureFlag import chat.revolt.api.settings.FeatureFlag
import chat.revolt.api.settings.FeatureFlags
import chat.revolt.api.settings.SyncedSettings import chat.revolt.api.settings.SyncedSettings
import chat.revolt.callbacks.Action import chat.revolt.callbacks.Action
import chat.revolt.callbacks.ActionChannel import chat.revolt.callbacks.ActionChannel
@ -199,9 +201,13 @@ class ChatRouterViewModel @Inject constructor(
fun navigateToChannel(channelId: String, navController: NavController, pure: Boolean = false) { fun navigateToChannel(channelId: String, navController: NavController, pure: Boolean = false) {
if (!pure) setSaveCurrentChannel(channelId) if (!pure) setSaveCurrentChannel(channelId)
// Only allow access to closed beta users, currently "has access to #beta-chat in Jenvolt"
@FeatureFlag("ClosedBetaAccessControl") @FeatureFlag("ClosedBetaAccessControl")
if (RevoltAPI.channelCache.size > 0 && !RevoltAPI.channelCache.containsKey("01H7X2KRB0CA4QDSMB4N7WGERF")) { if (RevoltAPI.channelCache.size > 0
&& FeatureFlags.closedBetaAccessControl is ClosedBetaAccessControlVariates.Restricted
&& (FeatureFlags.closedBetaAccessControl as ClosedBetaAccessControlVariates.Restricted)
.predicate()
.not()
) {
Pipebomb.incrementHardCrashCounter() Pipebomb.incrementHardCrashCounter()
navController.navigate("no_current_channel") { navController.navigate("no_current_channel") {

View File

@ -72,9 +72,6 @@ import chat.revolt.api.internals.ChannelUtils
import chat.revolt.api.routes.microservices.autumn.FileArgs import chat.revolt.api.routes.microservices.autumn.FileArgs
import chat.revolt.api.schemas.Channel import chat.revolt.api.schemas.Channel
import chat.revolt.api.schemas.ChannelType import chat.revolt.api.schemas.ChannelType
import chat.revolt.api.settings.FeatureFlag
import chat.revolt.api.settings.FeatureFlags
import chat.revolt.api.settings.FilePickerFeatureFlagVariates
import chat.revolt.components.chat.Message import chat.revolt.components.chat.Message
import chat.revolt.components.chat.MessageField import chat.revolt.components.chat.MessageField
import chat.revolt.components.chat.SystemMessage import chat.revolt.components.chat.SystemMessage
@ -491,10 +488,8 @@ fun ChannelScreen(
onAddAttachment = { onAddAttachment = {
val isTiramisu = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU val isTiramisu = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
@FeatureFlag("TiramisuFilePicker")
when { when {
FeatureFlags.filePickerType == FilePickerFeatureFlagVariates.TiramisuMediaPermissions isTiramisu -> {
&& isTiramisu -> {
focusManager.clearFocus() focusManager.clearFocus()
if (viewModel.currentBottomPane == BottomPane.InbuiltMediaPicker) { if (viewModel.currentBottomPane == BottomPane.InbuiltMediaPicker) {
viewModel.currentBottomPane = BottomPane.None viewModel.currentBottomPane = BottomPane.None
@ -503,8 +498,7 @@ fun ChannelScreen(
} }
} }
FeatureFlags.filePickerType == FilePickerFeatureFlagVariates.DocumentsUI !isTiramisu -> {
|| !isTiramisu -> {
pickFileLauncher.launch(arrayOf("*/*")) pickFileLauncher.launch(arrayOf("*/*"))
} }
} }
@ -592,7 +586,7 @@ fun ChannelScreen(
) )
} }
} }
AnimatedVisibility(visible = viewModel.currentBottomPane == BottomPane.EmojiPicker) { AnimatedVisibility(visible = viewModel.currentBottomPane == BottomPane.EmojiPicker) {
BackHandler(enabled = viewModel.currentBottomPane == BottomPane.EmojiPicker) { BackHandler(enabled = viewModel.currentBottomPane == BottomPane.EmojiPicker) {
viewModel.currentBottomPane = BottomPane.None viewModel.currentBottomPane = BottomPane.None

View File

@ -40,7 +40,6 @@ import chat.revolt.api.routes.server.fetchMember
import chat.revolt.api.routes.user.addUserIfUnknown import chat.revolt.api.routes.user.addUserIfUnknown
import chat.revolt.api.schemas.Channel import chat.revolt.api.schemas.Channel
import chat.revolt.api.schemas.Message import chat.revolt.api.schemas.Message
import chat.revolt.api.settings.FeatureFlag
import chat.revolt.callbacks.UiCallback import chat.revolt.callbacks.UiCallback
import chat.revolt.callbacks.UiCallbacks import chat.revolt.callbacks.UiCallbacks
import io.ktor.http.ContentType import io.ktor.http.ContentType
@ -57,8 +56,6 @@ import kotlinx.datetime.Instant
sealed class BottomPane { sealed class BottomPane {
data object None : BottomPane() data object None : BottomPane()
@FeatureFlag("TiramisuFilePicker")
data object InbuiltMediaPicker : BottomPane() data object InbuiltMediaPicker : BottomPane()
data object EmojiPicker : BottomPane() data object EmojiPicker : BottomPane()
} }