import { notFound } from "next/navigation"; import Link from "next/link"; import { canLogIn, isLocalUser, isSuperadmin, listUsers, maskIin, mergeHints, platformAdmins } from "@peppa/core"; import { Hidden } from "@/components/cards"; import { ago, Flash, PageHeader, Section } from "@/components/common"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { NativeSelect } from "@/components/ui/input"; import { Workspace } from "@/components/Workspace"; import { requireUser } from "@/lib/auth"; import { db } from "@/lib/db"; import { getT } from "@/lib/i18n"; import { setSuperadminAction, setUserDisabledAction } from "../actions"; const back = { back: "/users" }; /** Superadmin only (PEP-68/71): who is registered, disable / enable. */ export default async function Users({ searchParams }: { searchParams: Promise<{ error?: string }> }) { const me = await requireUser(); if (!(await isSuperadmin(db, me))) notFound(); const t = await getT(); const { error } = await searchParams; const all = await listUsers(db); const admins = new Set(await platformAdmins(db)); const hints = await mergeHints(db, all); const mains = all.filter((u) => !u.disabledAt && canLogIn(u)); return (
{t( "Вход только через eGov: первый вход по QR сам создаёт учётку по ИИН. Доступ к проектам — приглашением владельца; агенты проекта нового пользователя работают только на пуле подписок. Отключённый пользователь сразу теряет сессии веба и MCP.", )}
{all.map((u) => { const local = isLocalUser(u); const hint = hints.get(u.id); const targets = mains.filter((v) => v.id !== u.id); const isAdmin = admins.has(u.login.toLowerCase()); return (
{u.login} {u.name && {u.name}} {!local && Gitea} {isAdmin && {t("суперадмин")}} {u.disabledAt && {t("отключён")}} {u.egovIin && eGov {maskIin(u.egovIin)}} {u.googleSub && Google {u.googleEmail}} {!canLogIn(u) && !hint?.stranded && {t("без eGov и Google — не войдёт")}} {hint?.stranded && {t("Есть проекты — войти нельзя")}} {u.lastLoginAt ? t("вход {ago}", { ago: ago(u.lastLoginAt, t) }) : t("ещё не входил")}
{hint?.candidate && ( )} {u.id !== me.id && targets.length > 0 && (
{targets.map((v) => ( ))}
)} {u.id !== me.id && (isAdmin || !u.disabledAt) && (
)} {u.id !== me.id && (
)}
); })}
); }