Files
NightSpire/web-next/lib/forum-perm.ts
T
Inna 1a45d48412 Admin: corregir columnas de account_access + enlace al panel en la cuenta
- Este build de AzerothCore usa account_access(AccountID, SecurityLevel), no el
  clásico (id, gmlevel). Se corrigen las 4 consultas (admin.ts, forum-perm.ts,
  forum.ts, admin-users.ts) -> isAdmin/forumIsModerator/gmlevel ahora funcionan.
- account page: enlace destacado al Panel de administración, visible solo si isAdmin.
- i18n es/en: Account.adminPanel.

Verificado: build OK; cuenta de prueba con SecurityLevel 3 (>= ADMIN_GMLEVEL) es admin.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-13 01:42:04 +00:00

38 lines
1.3 KiB
TypeScript

import type { RowDataPacket } from 'mysql2'
import { db, DB } from './db'
import type { SessionData } from './session'
/** Nivel GM mínimo para moderar el foro (equivale a FORUM_MOD_GMLEVEL en Django). */
const MOD_GMLEVEL = Number(process.env.FORUM_MOD_GMLEVEL || 2)
/** Nivel GM máximo de una cuenta (acore_auth.account_access). 0 si no tiene. */
export async function getGmlevel(accountId: number | undefined): Promise<number> {
if (!accountId) return 0
try {
const [rows] = await db(DB.auth).query<RowDataPacket[]>(
'SELECT MAX(SecurityLevel) AS lvl FROM account_access WHERE AccountID = ?',
[accountId],
)
return rows[0] && rows[0].lvl != null ? Number(rows[0].lvl) : 0
} catch {
return 0
}
}
/** ¿El usuario puede moderar el foro? */
export async function forumIsModerator(session: SessionData): Promise<boolean> {
if (!session.accountId) return false
return (await getGmlevel(session.accountId)) >= MOD_GMLEVEL
}
/** Puede editar/borrar un post: su autor o un moderador. */
export function canEditPost(
session: SessionData,
isMod: boolean,
posterId: number | null | undefined,
): boolean {
if (!session.accountId) return false
if (posterId != null && Number(posterId) === Number(session.accountId)) return true
return isMod
}