refactor: centralize unauthorized detection and simplify workspace rollback
This commit is contained in:
@@ -34,3 +34,8 @@ data class BoardsDrawerState(
|
|||||||
val isWorkspaceInteractionEnabled: Boolean = false,
|
val isWorkspaceInteractionEnabled: Boolean = false,
|
||||||
val isWorkspaceSwitchInFlight: Boolean = false,
|
val isWorkspaceSwitchInFlight: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internal fun String.isUnauthorizedFailureMessage(): Boolean {
|
||||||
|
val normalized = lowercase()
|
||||||
|
return "401" in normalized || "403" in normalized || "authentication" in normalized || "unauthorized" in normalized
|
||||||
|
}
|
||||||
|
|||||||
@@ -219,8 +219,7 @@ class BoardsRepository(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isUnauthorizedMessage(message: String): Boolean {
|
private fun isUnauthorizedMessage(message: String): Boolean {
|
||||||
val normalized = message.lowercase()
|
return message.isUnauthorizedFailureMessage()
|
||||||
return "401" in normalized || "403" in normalized || "authentication" in normalized || "unauthorized" in normalized
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isNetworkMessage(message: String): Boolean {
|
private fun isNetworkMessage(message: String): Boolean {
|
||||||
|
|||||||
@@ -89,9 +89,6 @@ class BoardsViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
is BoardsApiResult.Failure -> {
|
is BoardsApiResult.Failure -> {
|
||||||
if (!currentWorkspaceId.isNullOrBlank()) {
|
|
||||||
repository.switchWorkspace(currentWorkspaceId)
|
|
||||||
}
|
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
drawer = it.drawer.copy(
|
drawer = it.drawer.copy(
|
||||||
@@ -292,8 +289,3 @@ class BoardsViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.isUnauthorizedFailureMessage(): Boolean {
|
|
||||||
val normalized = lowercase()
|
|
||||||
return "401" in normalized || "403" in normalized || "authentication" in normalized || "unauthorized" in normalized
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ class BoardsViewModelTest {
|
|||||||
|
|
||||||
assertEquals("ws-1", viewModel.uiState.value.drawer.activeWorkspaceId)
|
assertEquals("ws-1", viewModel.uiState.value.drawer.activeWorkspaceId)
|
||||||
assertEquals("ws-1", sessionStore.getWorkspaceId())
|
assertEquals("ws-1", sessionStore.getWorkspaceId())
|
||||||
|
assertEquals(1, api.listBoardsCalls)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -342,6 +343,7 @@ class BoardsViewModelTest {
|
|||||||
val event = eventDeferred.await()
|
val event = eventDeferred.await()
|
||||||
assertTrue(event is BoardsUiEvent.ForceSignOut)
|
assertTrue(event is BoardsUiEvent.ForceSignOut)
|
||||||
assertEquals("ws-1", sessionStore.getWorkspaceId())
|
assertEquals("ws-1", sessionStore.getWorkspaceId())
|
||||||
|
assertEquals(1, api.listBoardsCalls)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -364,6 +366,7 @@ class BoardsViewModelTest {
|
|||||||
|
|
||||||
assertEquals(null, sessionStore.getWorkspaceId())
|
assertEquals(null, sessionStore.getWorkspaceId())
|
||||||
assertEquals(null, viewModel.uiState.value.drawer.activeWorkspaceId)
|
assertEquals(null, viewModel.uiState.value.drawer.activeWorkspaceId)
|
||||||
|
assertEquals(1, api.listBoardsCalls)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun newViewModel(
|
private fun newViewModel(
|
||||||
|
|||||||
Reference in New Issue
Block a user