Foro: restaurar posts y temas borrados (moderadores)
- lib/forum.ts: getTopic/getPosts/countPosts aceptan includeDeleted (mods ven lo borrado); Post.deleted y TopicFull.deleted. - API: PUT /api/forum/post restaura post (mod-only); moderate action 'restore' restaura tema (usa includeDeleted al leer el tema). - UI: posts borrados atenuados con badge y botón Restaurar (PostActions); TopicModBar muestra banner + Restaurar tema cuando el tema está borrado. - i18n es/en: Forum.restore, restoreTopic, deletedMark. Verificado: build OK, PUT post y moderate restore 401 sin sesión, /forum 200. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import { getTopic, getForum } from '@/lib/forum'
|
||||
import { setTopicFlag, moveTopic } from '@/lib/forum-write'
|
||||
import { forumIsModerator } from '@/lib/forum-perm'
|
||||
|
||||
type Action = 'lock' | 'unlock' | 'sticky' | 'unsticky' | 'delete' | 'move'
|
||||
type Action = 'lock' | 'unlock' | 'sticky' | 'unsticky' | 'delete' | 'restore' | 'move'
|
||||
|
||||
/** Moderación de temas: bloquear, fijar, borrar. Solo moderadores. */
|
||||
export async function POST(request: Request) {
|
||||
@@ -17,7 +17,7 @@ export async function POST(request: Request) {
|
||||
const action = String(b.action ?? '') as Action
|
||||
if (!topicId) return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
|
||||
|
||||
const topic = await getTopic(topicId)
|
||||
const topic = await getTopic(topicId, true) // incluye borrados (ya verificado que es mod)
|
||||
if (!topic) return Response.json({ success: false, error: 'topicNotFound' }, { status: 404 })
|
||||
|
||||
switch (action) {
|
||||
@@ -36,6 +36,9 @@ export async function POST(request: Request) {
|
||||
case 'delete':
|
||||
await setTopicFlag(topicId, 'deleted', true)
|
||||
return Response.json({ success: true, forumId: topic.forum_id })
|
||||
case 'restore':
|
||||
await setTopicFlag(topicId, 'deleted', false)
|
||||
break
|
||||
case 'move': {
|
||||
const newForumId = Number(b.forumId)
|
||||
if (!newForumId || newForumId === topic.forum_id) {
|
||||
|
||||
@@ -6,6 +6,21 @@ import { plainLength } from '@/lib/forum-sanitize'
|
||||
|
||||
const MIN_TEXT_LEN = 5
|
||||
|
||||
/** Restaurar un post borrado. Solo moderadores. */
|
||||
export async function PUT(request: Request) {
|
||||
const session = await getSession()
|
||||
if (!session.accountId) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
|
||||
if (!(await forumIsModerator(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
|
||||
|
||||
let b: Record<string, string> = {}
|
||||
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
|
||||
const postId = Number(b.postId)
|
||||
if (!postId) return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
|
||||
|
||||
await setPostDeleted(postId, false)
|
||||
return Response.json({ success: true })
|
||||
}
|
||||
|
||||
/** Editar el texto de un post propio (o cualquiera si es moderador). */
|
||||
export async function PATCH(request: Request) {
|
||||
const session = await getSession()
|
||||
|
||||
Reference in New Issue
Block a user