// glossary-ignore-file: the page is for the superadmin only (accounts, repositories, Gitea spaces). import Link from "next/link"; import { notFound } from "next/navigation"; import { isSuperadmin, maskIin, mergePlan, PeppaError } from "@peppa/core"; import { Hidden } from "@/components/cards"; import { Flash, Notice, PageHeader, Section } from "@/components/common"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Workspace } from "@/components/Workspace"; import { requireUser } from "@/lib/auth"; import { db } from "@/lib/db"; import { getT } from "@/lib/i18n"; import { mergeAccountsAction } from "../../actions"; /** PEP-204: what moves from the old account to the main one — confirmed before anything changes. Superadmin only. */ export default async function MergeAccounts({ searchParams }: { searchParams: Promise<{ from?: string; to?: string; error?: string }> }) { const me = await requireUser(); if (!(await isSuperadmin(db, me))) notFound(); const t = await getT(); const { from, to, error } = await searchParams; const plan = await mergePlan(db, Number(from), Number(to)).catch((e) => { if (e instanceof PeppaError) notFound(); throw e; }); const back = `/users/merge?from=${plan.from.id}&to=${plan.to.id}`; const who = (u: typeof plan.from) => ( {u.login} {u.name && · {u.name}} {u.egovIin && · eGov {maskIin(u.egovIin)}} {(u.googleEmail || u.email) && · {u.googleEmail ?? u.email}} ); const rows: [string, string[]][] = [ [t("Проекты"), plan.projects.map((p) => `${p.key} «${p.name}»`)], [t("Участие в проектах"), plan.memberships.map((p) => `${p.key} «${p.name}»`)], [t("Приглашения"), plan.invites ? [String(plan.invites)] : []], [t("Подписки"), plan.subscriptions], [t("Пулы подписок"), plan.pools], [t("Чаты"), [...(plan.masterChat ? [t("личный чат")] : []), ...(plan.groups ? [t("Telegram-группы: {n}", { n: plan.groups })] : [])]], [t("Telegram"), plan.telegram ? [t("привязка")] : []], [t("Свой бот"), plan.bot ? [`@${plan.bot}`] : []], [t("Способы входа"), [...(plan.egov ? ["eGov"] : []), ...(plan.google ? [`Google ${plan.google}`] : [])]], ]; const moving = rows.filter(([, v]) => v.length); const personal = plan.projects.filter((p) => p.personalRepo); return (
{t("Пользователи")}} title={t("Объединить учётки")}> {t("Всё, с чем человек работает, переедет со старой учётки на главную. Старая учётка будет отключена.")}
{t("Старая учётка:")} {who(plan.from)}
{t("Главная учётка (куда переносим):")} {who(plan.to)}
{plan.refusal ? ( {t.text(plan.refusal)} ) : ( <>
{moving.length === 0 ? (

{t("Переносить нечего — старая учётка будет просто отключена.")}

) : (
    {moving.map(([k, v]) => (
  • {k}: {v.join(", ")}
  • ))}
)}
  • {t("История (журнал, комментарии, ответы) — под старым логином {login}.", { login: plan.from.login })}
  • {plan.projects.map((p) => (
  • {t("Репозиторий {key}: {repo}", { key: p.key, repo: p.repo })} {p.personalRepo && — {t("лежит в личном пространстве старой учётки Gitea; остаётся там, агенты работают с ним через peppa-bot")}}
  • ))}
{personal.length > 0 && {t("Перенос репозиториев между пространствами Gitea не выполняется.")}}
{plan.adminConfirm && ( )}
)}
); }