- users.password_hash/password_set_at/disabled_at (migration 0002_local_users) - core/local-users.ts: scrypt, passwordLogin with attempt limits, create/reset/disable - isSuperadmin(db, user) = platform.admins; isUserAllowed honours disabled_at - web: /auth/password + login form, /users for superadmins, Settings → password - Gitea login with a local user's login is refused (giteaLoginRefusal) - local users: projects in peppa-bot namespace, members without Gitea collaboration - CLI: peppa user add|passwd|disable|enable; tests in testkit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
82 lines
4.6 KiB
TypeScript
82 lines
4.6 KiB
TypeScript
"use client";
|
||
|
||
import Link from "next/link";
|
||
import { usePathname } from "next/navigation";
|
||
import { Bot, FolderKanban, House, LifeBuoy, LogOut, Settings, Users, type LucideIcon } from "lucide-react";
|
||
import { Brand } from "@/components/Brand";
|
||
import { ThemeToggle } from "@/components/ThemeToggle";
|
||
import { Button } from "@/components/ui/button";
|
||
import { cn } from "@/lib/utils";
|
||
|
||
interface Item {
|
||
href: string;
|
||
label: string;
|
||
icon: LucideIcon;
|
||
match: (p: string) => boolean;
|
||
count?: "questions" | "waitingRunners";
|
||
/** Superadmin only (PEP-68); desktop panel only — on phones it is linked from Settings. */
|
||
admin?: boolean;
|
||
}
|
||
|
||
const ITEMS: Item[] = [
|
||
{ href: "/", label: "Главная", icon: House, match: (p) => p === "/", count: "questions" },
|
||
{ href: "/projects", label: "Проекты", icon: FolderKanban, match: (p) => p.startsWith("/projects") || p.startsWith("/p/") || p.startsWith("/t/") },
|
||
{ href: "/runners", label: "Раннеры", icon: Bot, match: (p) => p.startsWith("/runners"), count: "waitingRunners" },
|
||
{ href: "/help", label: "Помощь", icon: LifeBuoy, match: (p) => p.startsWith("/help") },
|
||
{ href: "/users", label: "Пользователи", icon: Users, match: (p) => p.startsWith("/users"), admin: true },
|
||
{ href: "/settings", label: "Настройки", icon: Settings, match: (p) => p.startsWith("/settings") },
|
||
];
|
||
const COUNT_TITLE = { questions: "вопросов ждут тебя", waitingRunners: "раннеров ждут тебя" };
|
||
|
||
/** Left panel on desktop; on phones a top bar plus a bottom tab bar (PEP-38): sections with «ждут тебя» counters, theme, user. */
|
||
export function Sidebar({ login, avatarUrl, counts, superadmin = false }: { login: string; avatarUrl: string | null; counts: Record<"questions" | "waitingRunners", number>; superadmin?: boolean }) {
|
||
const path = usePathname();
|
||
return (
|
||
<header className="sticky top-0 z-30 flex h-14 items-center gap-2 border-b bg-sidebar px-3 md:h-dvh md:flex-col md:items-stretch md:gap-1 md:border-r md:border-b-0 md:px-3 md:py-4">
|
||
<Link href="/" className="flex shrink-0 items-center gap-2 rounded-md px-1 text-foreground hover:no-underline md:mb-4 md:px-2">
|
||
<Brand />
|
||
<span className="hidden font-mono text-[11px] text-muted-foreground md:inline">фабрика</span>
|
||
</Link>
|
||
<nav
|
||
aria-label="Разделы"
|
||
className="fixed inset-x-0 bottom-0 z-30 grid grid-cols-5 border-t bg-sidebar/95 pb-[env(safe-area-inset-bottom)] backdrop-blur md:static md:flex md:flex-col md:gap-0.5 md:border-0 md:bg-transparent md:pb-0 md:backdrop-blur-none"
|
||
>
|
||
{ITEMS.filter((i) => !i.admin || superadmin).map((i) => {
|
||
const active = i.match(path);
|
||
const n = i.count ? counts[i.count] : 0;
|
||
return (
|
||
<Link
|
||
key={i.href}
|
||
href={i.href}
|
||
aria-current={active ? "page" : undefined}
|
||
className={cn(
|
||
i.admin && "max-md:hidden",
|
||
"relative flex flex-col items-center gap-0.5 px-1 pt-2 pb-1.5 text-[10px] text-muted-foreground transition-colors hover:text-foreground hover:no-underline md:flex-row md:gap-2 md:rounded-md md:px-2.5 md:py-1.5 md:text-sm md:hover:bg-accent",
|
||
active && "font-medium text-foreground md:bg-accent md:before:absolute md:before:inset-y-1.5 md:before:-left-3 md:before:w-0.5 md:before:rounded-full md:before:bg-primary",
|
||
)}
|
||
>
|
||
<i.icon className={cn("size-5 md:size-4", active && "text-primary")} />
|
||
<span>{i.label}</span>
|
||
{n > 0 && (
|
||
<span title={`${n} ${COUNT_TITLE[i.count!]}`} className="absolute top-1 left-[calc(50%+6px)] min-w-4 rounded-full bg-primary px-1 text-center font-mono text-[10px] font-semibold leading-4 text-primary-foreground tabular-nums md:static md:ml-auto md:min-w-5 md:px-1.5 md:text-[11px] md:leading-5">
|
||
{n}
|
||
</span>
|
||
)}
|
||
</Link>
|
||
);
|
||
})}
|
||
</nav>
|
||
<div className="ml-auto flex shrink-0 items-center gap-1 md:mt-auto md:ml-0 md:border-t md:pt-3">
|
||
{avatarUrl && <img src={avatarUrl} alt="" width={24} height={24} className="hidden size-6 rounded-full md:block" />}
|
||
<span className="hidden min-w-0 flex-1 truncate text-sm md:block" title={login}>{login}</span>
|
||
<ThemeToggle />
|
||
<form action="/logout" method="post">
|
||
<Button variant="ghost" size="icon-sm" aria-label="Выйти" title="Выйти">
|
||
<LogOut />
|
||
</Button>
|
||
</form>
|
||
</div>
|
||
</header>
|
||
);
|
||
}
|