feat(android): Admin Quarantine is Reports, with the web's two removals
release / android (push) Canceled after 0s
release / govulncheck (push) Canceled after 0s
release / Build signed APK (push) Canceled after 0s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / web (push) Canceled after 11s
release / integration (push) Canceled after 11s
release / go (push) Canceled after 12s

The Admin card is Reports ("Tracks listeners flagged"). Each report
offers Resolve, Remove the file (the file goes and the track waits for a
good copy, with its likes and plays) and Remove from library (track,
file and history). Both removals now ask first; Delete file used to
delete on the tap.

They stay online-only: each deletes a file for good against a live
queue, so a replay hours later could act on a decision another admin
has since made. Offline they fail with the reason and the row returns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 19:11:00 -05:00
co-authored by Claude Opus 5.5
parent f52eb1a6fa
commit 51afbb8df5
7 changed files with 156 additions and 31 deletions
@@ -11,9 +11,10 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
/** /**
* Read-through accessor for the admin quarantine queue. No Room cache: * Read-through accessor for the admin Reports queue. No Room cache: it is an
* it is an admin's live work list, read fresh each time. Three resolution * admin's live work list, read fresh each time, and its actions go straight
* actions all delete the row from the queue once the server accepts them. * to the server, so offline they fail with the reason rather than queueing.
* Each action takes the row off the queue once the server accepts it.
*/ */
@Singleton @Singleton
class AdminQuarantineRepository @Inject constructor( class AdminQuarantineRepository @Inject constructor(
@@ -25,6 +26,8 @@ class AdminQuarantineRepository @Inject constructor(
suspend fun resolve(trackId: String) = api.resolve(trackId) suspend fun resolve(trackId: String) = api.resolve(trackId)
suspend fun removeFile(trackId: String) = api.removeFile(trackId)
suspend fun deleteFile(trackId: String) = api.deleteFile(trackId) suspend fun deleteFile(trackId: String) = api.deleteFile(trackId)
} }
@@ -148,8 +148,8 @@ private fun SectionList(counts: AdminCounts, navController: NavHostController) {
item { item {
SectionCard( SectionCard(
icon = Lucide.TriangleAlert, icon = Lucide.TriangleAlert,
title = "Quarantine", title = "Reports",
subtitle = "Resolve scan failures", subtitle = "Tracks listeners flagged",
count = counts.quarantine, count = counts.quarantine,
onClick = { navController.navigate(AdminQuarantine) }, onClick = { navController.navigate(AdminQuarantine) },
) )
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.AssistChip import androidx.compose.material3.AssistChip
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.HorizontalDivider
@@ -21,7 +22,9 @@ import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
@@ -56,7 +59,7 @@ fun AdminQuarantineScreen(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
topBar = { topBar = {
MinstrelTopAppBar( MinstrelTopAppBar(
title = "Admin · Quarantine", title = "Admin · Reports",
navController = navController, navController = navController,
currentRouteName = AdminQuarantine::class.qualifiedName, currentRouteName = AdminQuarantine::class.qualifiedName,
onBack = { navController.popBackStack() }, onBack = { navController.popBackStack() },
@@ -71,9 +74,9 @@ fun AdminQuarantineScreen(
when (val s = state) { when (val s = state) {
AdminQuarantineUiState.Loading -> LoadingCentered() AdminQuarantineUiState.Loading -> LoadingCentered()
AdminQuarantineUiState.Empty -> EmptyState( AdminQuarantineUiState.Empty -> EmptyState(
title = "Queue is empty", title = "No reports",
body = "When users flag tracks as bad rips, wrong tags, or " + body = "When listeners flag a track as a bad rip, wrong tags or " +
"duplicates, their reports get aggregated and surfaced here.", "a duplicate, their reports gather here.",
) )
is AdminQuarantineUiState.Error -> ErrorRetry( is AdminQuarantineUiState.Error -> ErrorRetry(
title = "Couldn't load queue", title = "Couldn't load queue",
@@ -83,6 +86,7 @@ fun AdminQuarantineScreen(
is AdminQuarantineUiState.Success -> QueueList( is AdminQuarantineUiState.Success -> QueueList(
rows = s.rows, rows = s.rows,
onResolve = viewModel::resolve, onResolve = viewModel::resolve,
onRemoveFile = viewModel::removeFile,
onDeleteFile = viewModel::deleteFile, onDeleteFile = viewModel::deleteFile,
) )
} }
@@ -90,28 +94,91 @@ fun AdminQuarantineScreen(
} }
} }
/** A confirm asked of the admin before a removal: which one, and of which track. */
private enum class Removal { File, Library }
private data class PendingRemoval(val row: AdminQuarantineItemRef, val kind: Removal)
@Composable @Composable
private fun QueueList( private fun QueueList(
rows: List<AdminQuarantineItemRef>, rows: List<AdminQuarantineItemRef>,
onResolve: (String) -> Unit, onResolve: (String) -> Unit,
onRemoveFile: (String) -> Unit,
onDeleteFile: (String) -> Unit, onDeleteFile: (String) -> Unit,
) { ) {
var pending by remember { mutableStateOf<PendingRemoval?>(null) }
LazyColumn(modifier = Modifier.fillMaxSize()) { LazyColumn(modifier = Modifier.fillMaxSize()) {
items(items = rows, key = { it.trackId }) { row -> items(items = rows, key = { it.trackId }) { row ->
QuarantineRow( QuarantineRow(
row = row, row = row,
onResolve = { onResolve(row.trackId) }, onResolve = { onResolve(row.trackId) },
onDeleteFile = { onDeleteFile(row.trackId) }, onRemoveFile = { pending = PendingRemoval(row, Removal.File) },
onDeleteFile = { pending = PendingRemoval(row, Removal.Library) },
) )
HorizontalDivider() HorizontalDivider()
} }
} }
pending?.let { p ->
RemovalConfirm(
pending = p,
onConfirm = {
pending = null
when (p.kind) {
Removal.File -> onRemoveFile(p.row.trackId)
Removal.Library -> onDeleteFile(p.row.trackId)
}
},
onDismiss = { pending = null },
)
}
}
/**
* Both removals delete the file, so each asks first. Remove the file keeps the
* track waiting for a good copy, with its likes and plays; Remove from library
* takes the track and its history too.
*/
@Composable
private fun RemovalConfirm(
pending: PendingRemoval,
onConfirm: () -> Unit,
onDismiss: () -> Unit,
) {
val title = pending.row.trackTitle
val (heading, body, action) = when (pending.kind) {
Removal.File -> Triple(
"Remove the file?",
"Delete the file of \u201c$title\u201d and keep the track. It waits, with its likes " +
"and plays, and takes over a good copy when one is in the library. Its reports are cleared.",
"Remove the file",
)
Removal.Library -> Triple(
"Remove from library?",
"Remove \u201c$title\u201d and its file for good, with its likes, plays and playlist " +
"places. To keep the track for a good copy, remove the file instead.",
"Remove from library",
)
}
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(heading) },
text = {
Text(
text = body,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
},
confirmButton = { TextButton(onClick = onConfirm) { Text(action) } },
dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
)
} }
@Composable @Composable
private fun QuarantineRow( private fun QuarantineRow(
row: AdminQuarantineItemRef, row: AdminQuarantineItemRef,
onResolve: () -> Unit, onResolve: () -> Unit,
onRemoveFile: () -> Unit,
onDeleteFile: () -> Unit, onDeleteFile: () -> Unit,
) { ) {
Column( Column(
@@ -160,6 +227,7 @@ private fun QuarantineRow(
} }
ActionButtons( ActionButtons(
onResolve = onResolve, onResolve = onResolve,
onRemoveFile = onRemoveFile,
onDeleteFile = onDeleteFile, onDeleteFile = onDeleteFile,
) )
} }
@@ -168,6 +236,7 @@ private fun QuarantineRow(
@Composable @Composable
private fun ActionButtons( private fun ActionButtons(
onResolve: () -> Unit, onResolve: () -> Unit,
onRemoveFile: () -> Unit,
onDeleteFile: () -> Unit, onDeleteFile: () -> Unit,
) { ) {
Row( Row(
@@ -175,6 +244,7 @@ private fun ActionButtons(
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End), horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
) { ) {
TextButton(onClick = onResolve) { Text("Resolve") } TextButton(onClick = onResolve) { Text("Resolve") }
OutlinedButton(onClick = onDeleteFile) { Text("Delete file") } TextButton(onClick = onDeleteFile) { Text("Remove from library") }
OutlinedButton(onClick = onRemoveFile) { Text("Remove the file") }
} }
} }
@@ -39,9 +39,8 @@ class AdminQuarantineViewModel @Inject constructor(
/** /**
* One-shot messages for the screen's snackbar. A failed action has to say * One-shot messages for the screen's snackbar. A failed action has to say
* why: the row quietly reappearing reads as a glitch, and for a Delete * why: the row quietly reappearing reads as a glitch, and for a removal
* file refused by a read-only library it hides the one thing an * refused by a read-only library it hides the one thing an admin can fix.
* admin can fix.
*/ */
private val transientMessagesChannel = Channel<String>(Channel.BUFFERED) private val transientMessagesChannel = Channel<String>(Channel.BUFFERED)
val transientMessages: Flow<String> = transientMessagesChannel.receiveAsFlow() val transientMessages: Flow<String> = transientMessagesChannel.receiveAsFlow()
@@ -81,6 +80,7 @@ class AdminQuarantineViewModel @Inject constructor(
} }
fun resolve(trackId: String) = act(trackId) { repository.resolve(it) } fun resolve(trackId: String) = act(trackId) { repository.resolve(it) }
fun removeFile(trackId: String) = act(trackId) { repository.removeFile(it) }
fun deleteFile(trackId: String) = act(trackId) { repository.deleteFile(it) } fun deleteFile(trackId: String) = act(trackId) { repository.deleteFile(it) }
private fun act(trackId: String, action: suspend (String) -> Unit) { private fun act(trackId: String, action: suspend (String) -> Unit) {
@@ -8,9 +8,11 @@ import retrofit2.http.Path
/** /**
* Retrofit interface for `/api/admin/quarantine`. * Retrofit interface for `/api/admin/quarantine`.
* *
* Two resolution endpoints: * Three resolution endpoints:
* - `resolve` → admin reviewed, no action taken (clears flags). * - `resolve` → admin reviewed, no action taken (clears the reports).
* - `delete-file` → delete the track's file and row. * - `remove-file` → delete the track's file and keep the track, which waits
* for a good copy with its likes and plays.
* - `delete-file` → remove the track from the library, file and history.
*/ */
interface AdminQuarantineApi { interface AdminQuarantineApi {
@GET("api/admin/quarantine") @GET("api/admin/quarantine")
@@ -19,6 +21,9 @@ interface AdminQuarantineApi {
@POST("api/admin/quarantine/{trackId}/resolve") @POST("api/admin/quarantine/{trackId}/resolve")
suspend fun resolve(@Path("trackId") trackId: String) suspend fun resolve(@Path("trackId") trackId: String)
@POST("api/admin/quarantine/{trackId}/remove-file")
suspend fun removeFile(@Path("trackId") trackId: String)
@POST("api/admin/quarantine/{trackId}/delete-file") @POST("api/admin/quarantine/{trackId}/delete-file")
suspend fun deleteFile(@Path("trackId") trackId: String) suspend fun deleteFile(@Path("trackId") trackId: String)
} }
@@ -0,0 +1,61 @@
package com.fabledsword.minstrel.admin.ui
import com.fabledsword.minstrel.admin.data.AdminQuarantineRepository
import com.fabledsword.minstrel.connectivity.NetworkStatusController
import com.fabledsword.minstrel.connectivity.ServerHealth
import com.fabledsword.minstrel.events.EventsStream
import com.fabledsword.minstrel.events.LiveEvent
import com.fabledsword.minstrel.models.AdminQuarantineItemRef
import com.fabledsword.minstrel.testutil.MainDispatcherExtension
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import kotlin.test.assertEquals
/** Reports' two removals each reach their own endpoint, and either takes the row off the queue. */
@ExtendWith(MainDispatcherExtension::class)
class AdminQuarantineViewModelTest {
private val row = AdminQuarantineItemRef(
trackId = "t1",
trackTitle = "Roygbiv",
artistName = "Boards of Canada",
albumTitle = "Geogaddi",
albumId = "al1",
reportCount = 1,
)
private val repository: AdminQuarantineRepository = mockk(relaxed = true) {
coEvery { list() } returns listOf(row)
}
private val eventsStream: EventsStream = mockk {
every { events } returns MutableSharedFlow<LiveEvent>()
}
private val network: NetworkStatusController = mockk {
every { state } returns MutableStateFlow(ServerHealth.Healthy)
}
// Lazy: built inside each test, after the extension has swapped in the test Main dispatcher.
private val viewModel by lazy { AdminQuarantineViewModel(repository, eventsStream, network) }
@Test
fun `remove the file keeps the track and clears the row`() {
viewModel.removeFile("t1")
coVerify(exactly = 1) { repository.removeFile("t1") }
coVerify(exactly = 0) { repository.deleteFile(any()) }
assertEquals(AdminQuarantineUiState.Empty, viewModel.uiState.value)
}
@Test
fun `remove from library is the separate full removal`() {
viewModel.deleteFile("t1")
coVerify(exactly = 1) { repository.deleteFile("t1") }
coVerify(exactly = 0) { repository.removeFile(any()) }
assertEquals(AdminQuarantineUiState.Empty, viewModel.uiState.value)
}
}
-14
View File
@@ -1,14 +0,0 @@
package api
import (
"context"
"testing"
)
// resetRequests clears requests rows between tests.
func resetRequests(t *testing.T, h *handlers) {
t.Helper()
if _, err := h.pool.Exec(context.Background(), "DELETE FROM requests"); err != nil {
t.Fatalf("resetRequests: %v", err)
}
}