Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 16x 16x 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 3x 3x 3x 3x 3x 3x 3x 3x 3x 9x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 2x 63x 63x 37x 37x 63x 4x 4x 22x 22x 63x 63x 63x 63x 63x 63x 63x 63x 63x 1x | <template>
<div>
<div class="flex flex-wrap justify-between items-center gap-3 mb-6">
<div>
<h2 class="text-xl font-bold text-fg">Content Reports</h2>
<p class="text-sm text-fg-muted">
Live chat messages users reported. Reporting also blocked the author
for the reporter.
</p>
</div>
<div class="flex items-center gap-3">
<span class="text-sm text-fg-muted" data-testid="pending-count">
<span class="font-medium">{{ pendingCount }}</span> pending
</span>
<select
v-model="statusFilter"
data-testid="report-status-filter"
class="px-3 py-2 bg-card text-fg border border-line rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-brand-500"
@change="fetchReports"
>
<option value="">All (pending first)</option>
<option value="pending">Pending</option>
<option value="actioned">Actioned</option>
<option value="dismissed">Dismissed</option>
</select>
</div>
</div>
<div v-if="loading" class="text-center py-8">
<div
class="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600"
></div>
<p class="mt-2 text-fg-muted">Loading reports...</p>
</div>
<div
v-else-if="error"
class="bg-red-50 dark:bg-red-500/10 border border-red-200 dark:border-red-500/30 rounded-md p-4"
data-testid="reports-error"
>
<p class="text-red-800 dark:text-red-300">{{ error }}</p>
<button
class="mt-2 text-sm text-red-600 hover:text-red-800 underline"
@click="fetchReports"
>
Try again
</button>
</div>
<div
v-else-if="reports.length === 0"
class="text-center py-12"
data-testid="reports-empty"
>
<h3 class="text-lg font-medium text-fg mb-2">No content reports</h3>
<p class="text-fg-muted">
{{
statusFilter
? 'No reports match this filter.'
: 'Nobody has reported a chat message.'
}}
</p>
</div>
<ul v-else class="space-y-3" data-testid="reports-list">
<li
v-for="report in reports"
:key="report.id"
class="bg-card border border-line rounded-lg p-4"
:data-testid="`report-${report.id}`"
>
<div class="flex flex-wrap items-center gap-2 mb-2 text-sm">
<span
class="px-2 py-0.5 text-xs font-medium rounded-full"
:class="statusBadgeClass(report.status)"
>
{{ report.status }}
</span>
<span class="font-medium text-fg">
{{ REPORT_REASON_LABELS[report.reason] || report.reason }}
</span>
<span class="text-fg-muted">·</span>
<span class="text-fg-muted">
{{ report.reported_username || 'Deleted account' }}
</span>
<span class="text-fg-muted">·</span>
<span class="text-fg-muted">match {{ report.match_id }}</span>
<span class="text-fg-muted ml-auto">
{{ formatDate(report.created_at) }}
</span>
</div>
<blockquote
class="border-l-4 border-line pl-3 text-fg whitespace-pre-wrap break-words"
>
{{ report.message_text }}
</blockquote>
<p v-if="report.details" class="mt-2 text-sm text-fg-muted">
Reporter's note: {{ report.details }}
</p>
<div
v-if="report.status === 'pending'"
class="flex flex-wrap gap-2 mt-3"
>
<button
type="button"
class="px-3 py-1.5 text-sm font-medium rounded-md bg-surface-alt text-fg hover:bg-line disabled:opacity-50"
:disabled="acting === report.id"
:data-testid="`dismiss-${report.id}`"
@click="act(report, 'dismiss')"
>
Dismiss
</button>
<button
type="button"
class="px-3 py-1.5 text-sm font-medium rounded-md bg-amber-600 text-white hover:bg-amber-700 disabled:opacity-50"
:disabled="acting === report.id"
:data-testid="`delete-message-${report.id}`"
@click="confirmAction(report, 'delete_message')"
>
Delete message
</button>
<button
v-if="report.reported_user_id"
type="button"
class="px-3 py-1.5 text-sm font-medium rounded-md bg-red-600 text-white hover:bg-red-700 disabled:opacity-50"
:disabled="acting === report.id"
:data-testid="`ban-user-${report.id}`"
@click="confirmAction(report, 'ban_user')"
>
Delete & ban from chat
</button>
</div>
<p
v-else-if="report.action"
class="mt-3 text-xs text-fg-muted"
data-testid="report-resolution"
>
{{ ACTION_LABELS[report.action] || report.action }}
<template v-if="report.resolved_at">
· {{ formatDate(report.resolved_at) }}
</template>
</p>
</li>
</ul>
<ConfirmModal
:show="!!pending"
:title="
pending?.action === 'ban_user' ? 'Ban from chat?' : 'Delete message?'
"
:message="confirmMessage"
:confirm-text="pending?.action === 'ban_user' ? 'Delete & ban' : 'Delete'"
:loading="acting !== null"
variant="danger"
@confirm="runPending"
@cancel="pending = null"
/>
</div>
</template>
<script setup>
import { computed, onMounted, ref } from 'vue';
import { useAuthStore } from '@/stores/auth';
import { getApiBaseUrl } from '@/config/api';
import ConfirmModal from '@/components/ConfirmModal.vue';
import {
REPORT_REASON_LABELS,
sortReportsPendingFirst,
} from '@/utils/chatSafety';
// Admin review queue for reported chat messages (SB-1324).
// Backend: GET / PATCH /api/admin/content-reports (backend/api/moderation.py).
const ACTION_LABELS = {
dismiss: 'Dismissed',
delete_message: 'Message deleted',
ban_user: 'Message deleted, author banned from chat',
};
const authStore = useAuthStore();
const reports = ref([]);
const loading = ref(false);
const error = ref('');
const statusFilter = ref('');
const acting = ref(null);
// { report, action } awaiting confirmation.
const pending = ref(null);
const pendingCount = computed(
() => reports.value.filter(r => r.status === 'pending').length
);
const confirmMessage = computed(() => {
if (!pending.value) return '';
const who = pending.value.report.reported_username || 'this user';
return pending.value.action === 'ban_user'
? `The message is deleted and ${who} can no longer post in chat. There is no unban yet.`
: 'The message is removed from the live chat for everyone.';
});
async function fetchReports() {
loading.value = true;
error.value = '';
try {
const query = statusFilter.value ? `?status=${statusFilter.value}` : '';
const rows = await authStore.apiRequest(
`${getApiBaseUrl()}/api/admin/content-reports${query}`
);
reports.value = sortReportsPendingFirst(Array.isArray(rows) ? rows : []);
} catch (e) {
error.value = e.message || 'Failed to load reports';
} finally {
loading.value = false;
}
}
async function act(report, action) {
acting.value = report.id;
error.value = '';
try {
const updated = await authStore.apiRequest(
`${getApiBaseUrl()}/api/admin/content-reports/${report.id}`,
{ method: 'PATCH', body: JSON.stringify({ action }) }
);
const next = reports.value.map(r =>
r.id === report.id ? { ...r, ...(updated || {}) } : r
);
reports.value = sortReportsPendingFirst(
statusFilter.value
? next.filter(r => r.status === statusFilter.value)
: next
);
} catch (e) {
error.value = e.message || 'Failed to update report';
} finally {
acting.value = null;
}
}
function confirmAction(report, action) {
pending.value = { report, action };
}
async function runPending() {
const { report, action } = pending.value;
await act(report, action);
pending.value = null;
}
function statusBadgeClass(status) {
if (status === 'pending') {
return 'bg-yellow-100 text-yellow-800 dark:bg-yellow-500/15 dark:text-yellow-300';
}
if (status === 'actioned') {
return 'bg-red-100 text-red-800 dark:bg-red-500/15 dark:text-red-300';
}
return 'bg-surface-alt text-fg-muted';
}
function formatDate(value) {
if (!value) return '';
return new Date(value).toLocaleString([], {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
});
}
onMounted(fetchReports);
</script>
|