- project_members / project_invites; owner adds people by Gitea login, invitations are applied at first login; members get the owner's access except member management; a member can leave - access everywhere via projectForUser / userProjectIds (owner or member): web inbox, sessions, project pages, MCP - shareProject / unshareProject: login checked in Gitea, repo collaborator (write) added by the owner's client or peppa-bot; missing admin rights don't block membership (repoAccess flag) - web: Members block on the project page, 'shared' badge; MCP: list_members, add_member, remove_member; Help updated - tests: 5 sharing journeys on mock-gitea (64 e2e total, green); test DB now also clears users and OAuth clients between files - OpenSpec: pep-12 archived (project-sharing, web-auth) Co-Authored-By: Claude <noreply@anthropic.com>
126 lines
5.9 KiB
TypeScript
126 lines
5.9 KiB
TypeScript
import { notFound } from "next/navigation";
|
||
import { loadEnv } from "@peppa/shared";
|
||
import { AutoRefresh } from "@/components/AutoRefresh";
|
||
import { Flash, SessionCard } from "@/components/ui";
|
||
import { Board, type Card } from "@/components/Board";
|
||
import { columnOf } from "@peppa/runner";
|
||
import { requireUser } from "@/lib/auth";
|
||
import { board, projectForUserByKey, projectSessions } from "@/lib/queries";
|
||
import { listMembers } from "@peppa/core";
|
||
import { db } from "@/lib/db";
|
||
import { addGoal, addProjectMember, addTask, removeProjectMember } from "../../actions";
|
||
|
||
export default async function ProjectPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string }> }) {
|
||
const user = await requireUser();
|
||
const { key } = await params;
|
||
const { error } = await searchParams;
|
||
const p = await projectForUserByKey(user.id, key).catch(() => null);
|
||
if (!p) notFound();
|
||
const [{ goals, tasks }, sessions, team] = await Promise.all([board(p.id), projectSessions(p.id), listMembers(db, p)]);
|
||
const isOwner = p.ownerId === user.id;
|
||
const back = `/p/${p.key}`;
|
||
const groups = [...goals.map((g) => ({ goal: g })), { goal: null }];
|
||
const goalTitle = new Map(goals.map((g) => [g.id, g.title]));
|
||
const cards: Card[] = tasks.map((t) => ({
|
||
key: `${p.key}-${t.number}`,
|
||
title: t.title,
|
||
status: t.status,
|
||
column: columnOf(t.status),
|
||
goal: t.goalId ? (goalTitle.get(t.goalId) ?? null) : null,
|
||
}));
|
||
return (
|
||
<>
|
||
<AutoRefresh />
|
||
<Flash error={error} />
|
||
<h1>
|
||
<span className="mono">{p.key}</span> {p.name}
|
||
</h1>
|
||
<p className="muted">
|
||
<a href={`${loadEnv().GITEA_URL}/${p.giteaOwner}/${p.giteaRepo}`}>{p.giteaOwner}/{p.giteaRepo}</a> · <span className="mono">{p.workspacePath}</span>
|
||
</p>
|
||
|
||
<Board cards={cards} back={back} />
|
||
|
||
{groups.map(({ goal }) => (
|
||
<details key={goal?.id ?? "none"} className="add">
|
||
<summary>+ Задача{goal ? ` · 🎯 ${goal.title}` : " без цели"}</summary>
|
||
<form action={addTask} className="stack">
|
||
<input type="hidden" name="projectId" value={p.id} />
|
||
<input type="hidden" name="back" value={back} />
|
||
{goal && <input type="hidden" name="goalId" value={goal.id} />}
|
||
<input type="text" name="title" required placeholder="Что сделать" aria-label="Название задачи" />
|
||
<textarea name="description" rows={3} placeholder="Описание: контекст, критерии готовности" aria-label="Описание задачи" />
|
||
<button className="primary">Создать задачу</button>
|
||
</form>
|
||
</details>
|
||
))}
|
||
|
||
<section>
|
||
<details>
|
||
<summary>+ Цель</summary>
|
||
<form action={addGoal} className="stack">
|
||
<input type="hidden" name="projectId" value={p.id} />
|
||
<input type="hidden" name="back" value={back} />
|
||
<input type="text" name="title" required placeholder="Верхнеуровневая цель" aria-label="Название цели" />
|
||
<textarea name="description" rows={3} placeholder="Зачем и какой результат" aria-label="Описание цели" />
|
||
<button className="primary">Создать цель</button>
|
||
</form>
|
||
</details>
|
||
</section>
|
||
|
||
<section>
|
||
<h2>Участники</h2>
|
||
<ul className="members">
|
||
<li>
|
||
<span><b>{team.owner?.login ?? "—"}</b> <span className="muted">владелец · агенты работают на его подписке Claude</span></span>
|
||
</li>
|
||
{team.members.map((m) => (
|
||
<li key={m.id}>
|
||
<span>{m.login} <span className="muted">участник</span></span>
|
||
{(isOwner || m.id === user.id) && (
|
||
<form action={removeProjectMember}>
|
||
<input type="hidden" name="projectId" value={p.id} />
|
||
<input type="hidden" name="login" value={m.login} />
|
||
<input type="hidden" name="back" value={back} />
|
||
<button className="small danger">{m.id === user.id ? "Выйти из проекта" : "Убрать"}</button>
|
||
</form>
|
||
)}
|
||
</li>
|
||
))}
|
||
{team.invites.map((login) => (
|
||
<li key={login}>
|
||
<span>{login} <span className="muted">приглашён · появится после первого входа в Пеппу</span></span>
|
||
{isOwner && (
|
||
<form action={removeProjectMember}>
|
||
<input type="hidden" name="projectId" value={p.id} />
|
||
<input type="hidden" name="login" value={login} />
|
||
<input type="hidden" name="back" value={back} />
|
||
<button className="small danger">Отозвать</button>
|
||
</form>
|
||
)}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
{isOwner && (
|
||
<form action={addProjectMember} className="row">
|
||
<input type="hidden" name="projectId" value={p.id} />
|
||
<input type="hidden" name="back" value={back} />
|
||
<input type="text" name="login" required placeholder="Логин в Gitea" aria-label="Логин участника в Gitea" />
|
||
<button>Добавить участника</button>
|
||
</form>
|
||
)}
|
||
{isOwner && (
|
||
<p className="muted">
|
||
Участник видит доску и входящие, двигает карточки и отвечает агентам; получает доступ на запись к репозиторию.
|
||
</p>
|
||
)}
|
||
</section>
|
||
|
||
<section>
|
||
<h2>Сессии</h2>
|
||
{sessions.length === 0 ? <p className="empty">Сессий ещё не было.</p> : sessions.map((s) => <SessionCard key={s.id} s={s} back={back} />)}
|
||
</section>
|
||
</>
|
||
);
|
||
}
|