Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ What the app is and how to run it: [`README.md`](README.md). UI rules: [`docs/de
PDFs, `regulations:rectify` rettifiche and Deleghe. Per-draft access (viewer, commenter, editor) and deleghe are
backend data: `regulations.me.get` admits an account without `admin:access` to Regolamenti › Bozze only, draft-scoped
server functions use `regulationsAssigneeMiddleware`, and pages act on the document's `editable` and the draft's `can`
from the backend. Every PDF opens in `PdfDialog`. The editor connects to the collab service with a single-use ticket
from the backend. A secret draft (`secret`) is seen only by its creator and the members they add, permissions
notwithstanding, and its procedure stays closed until the creator makes it visible (`drafts.reveal`, for good). Every PDF opens in `PdfDialog`. The editor connects to the collab service with a single-use ticket
from a server function, never a token. UI copy is Italian. Details: `docs/regulations/README.md`.
- **Shared UI**: `src/components/shell`, `src/components/primitives`, `src/components/ui`.

Expand Down
10 changes: 9 additions & 1 deletion docs/regulations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ Every section but Bozze also needs `admin:access`, like the rest of the dashboar
editor, and a delega lets anyone rectify. `loadAccess` admits a user without `admin:access` or `people:self` when
`regulations.me.get` reports an assignment or a delega; `/dashboard` then shows them only Regolamenti › Bozze
(`peopleRoles.regulations`, the `regulations` section role in `nav.ts`), and the logo leads there.
- **Secret drafts.** "Nuova bozza" asks who sees it: "Visibile" (`regulations:read` and the members) or "Segreta"
(`secret: true`): only its creator and the members they add, whatever their IdP permissions, with the role given in
the members dialog (a Direttivo member too); not even `regulations:write` or `:manage` see it, in lists or counts.
Only the creator manages members, deletes it and makes it visible ("Rendi visibile" on the procedure page,
`drafts.reveal`, for good). Until then its procedure is closed: the steps show disabled with the backend's reason, and
the page says why once. A draft from a secret draft is secret too. Lists and headers mark it "Segreta"
(`DraftSecretMark`).
- **Middleware** (`src/server/auth.middleware.ts`): `regulationsReadMiddleware`, `regulationsWriteMiddleware`,
`regulationsManageMiddleware` and `regulationsRectifyMiddleware` check the permission; draft-scoped calls (collab
ticket, comments, snapshots, rename and delete, rettifiche) use `regulationsAssigneeMiddleware`, which admits any
Expand All @@ -71,7 +78,7 @@ Every section but Bozze also needs `admin:access`, like the rest of the dashboar

`src/features/regulations/regulations.contract.ts` is a verbatim copy of the backend's `src/regulations/contract.ts`
(PoliNetworkOrg/backend#110); `regulations.api.server.ts` maps one method to each procedure and parses every response.
Procedures: `me.get`, `documents.list|get|sync|create|upload`, `templates.list`, `versions.list|pdf|upload`, `drafts.list|get|files|create|rename|delete|transition`,
Procedures: `me.get`, `documents.list|get|sync|create|upload`, `templates.list`, `versions.list|pdf|upload`, `drafts.list|get|files|create|rename|delete|reveal|transition`,
`assignments.list|set|remove`, `users.search`, `collabTicket`, `compile.status|pdf`, `snapshots.list|get|create|restore`,
`comments.list|create|reply|resolve|reopen|delete`, `merge.preview|execute`, `diff.get|regenerate|pdf`,
`emanation.get|start|retry`, `deleghe.list|create|revoke`. Files (PDFs) come back as `{ fileName, contentType, base64 }`
Expand Down Expand Up @@ -110,6 +117,7 @@ one. Logic: `editor/draft-files.ts`.
`regulations.fixtures.server.ts`: the RRI with three drafts, two versions, the older one an untagged import labelled as
the backend labels it, `import d08cb57`, a delega, a comment; the Guida della Matricola, a documento generale with a
published draft and an open one; a private document from the generale template; an uploaded PDF with two versions;
two secret RRI drafts, the agent's (shared with one Socio) and the Presidente's, which the agent never sees;
Statuto and Regolamento Elettorale, sola consultazione; a repository document "In creazione" and one whose pull request
was closed). A repository document created in agent mode turns active 20 s later, as if its pull request merged; a
private documento publishes at once. Version PDFs are compiled from their sources (stand-ins for the `polinetwork-regolamento` and `polinetwork` classes),
Expand Down
3 changes: 2 additions & 1 deletion src/features/regulations/document-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { NewDraftDialog, type NewDraftTarget } from "./new-draft-dialog"
import { downloadPdf, PdfDialog, usePdfDialog } from "./pdf-dialog"
import { baseLabel, formatDay, versionOrigin } from "./regulations-format"
import { failureMessage } from "./regulations-hooks"
import { DraftKindMark, DraftStateBadge } from "./regulations-ui"
import { DraftKindMark, DraftSecretMark, DraftStateBadge } from "./regulations-ui"
import type { DocumentInfo, DraftSummary, VersionSummary } from "./regulations.contract"
import { getVersionPdf } from "./regulations.functions"
import { UploadVersionDialog } from "./upload-version-dialog"
Expand Down Expand Up @@ -165,6 +165,7 @@ export function DocumentPage({
<span className="truncate font-medium">{draft.title}</span>
</Hint>
<DraftKindMark kind={draft.kind} />
<DraftSecretMark secret={draft.secret} />
</span>
),
},
Expand Down
3 changes: 2 additions & 1 deletion src/features/regulations/drafts-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Button } from "@/components/ui/button"

import { NewDraftDialog, type NewDraftTarget } from "./new-draft-dialog"
import { baseLabel, formatDay, isFinalState, ROLE_LABELS } from "./regulations-format"
import { DraftKindMark, DraftStateBadge } from "./regulations-ui"
import { DraftKindMark, DraftSecretMark, DraftStateBadge } from "./regulations-ui"
import type { DocumentInfo, DraftSummary, Me } from "./regulations.contract"

type Filter = "open" | "closed"
Expand Down Expand Up @@ -57,6 +57,7 @@ export function DraftsPage({ drafts, me, documents }: { drafts: DraftSummary[];
<span className="flex min-w-0 items-center gap-2">
<span className="truncate font-medium">{draft.title}</span>
<DraftKindMark kind={draft.kind} />
<DraftSecretMark secret={draft.secret} />
</span>
<span className="truncate text-xs text-(--pn-fg-muted)">di {draft.createdBy.name}</span>
</span>
Expand Down
3 changes: 2 additions & 1 deletion src/features/regulations/editor/editor-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { cn } from "@/lib/utils"
import { parseDocument, type StructureNode } from "../latex-structure"
import { MembersDialog } from "../members-dialog"
import { downloadPdf, PdfDialog, usePdfDialog } from "../pdf-dialog"
import { DraftKindMark, DraftStateBadge } from "../regulations-ui"
import { DraftKindMark, DraftSecretMark, DraftStateBadge } from "../regulations-ui"
import type {
Assignment,
CommentThread,
Expand Down Expand Up @@ -431,6 +431,7 @@ export function EditorPage({ draft, members }: { draft: Draft; members: Assignme
<h1 className="min-w-0 truncate text-[22px]/8 font-semibold tracking-[-0.01em]">{draft.title}</h1>
<DraftStateBadge state={draft.state} label={stateLabel} />
<DraftKindMark kind={draft.kind} />
<DraftSecretMark secret={draft.secret} />
<ConnectionState status={collab.status} />
{collab.peers.length > 0 ? (
<AvatarGroup
Expand Down
72 changes: 42 additions & 30 deletions src/features/regulations/members-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function Person({ user }: { user: UserMatch }) {
/**
* Who works on a draft, Google-Docs style: any PoliNetwork account (not only Soci) as viewer, commenter or editor.
* Each change is saved at once. Assignments are backend data, not IdP roles: an assignment alone lets someone into
* the dashboard, where they see only Regolamenti and their drafts.
* the dashboard, where they see only Regolamenti and their drafts. In a secret draft the members are the only ones who
* see it, with the role given here even if they are in the Direttivo, and its creator stays editor.
*/
export function MembersDialog({
open,
Expand All @@ -62,7 +63,7 @@ export function MembersDialog({
}: {
open: boolean
onOpenChange: (open: boolean) => void
draft: { id: string; title: string }
draft: { id: string; title: string; secret: boolean; createdBy: { id: string } }
members: Assignment[]
}) {
const search = useServerFn(searchRegulationUsers)
Expand Down Expand Up @@ -161,10 +162,17 @@ export function MembersDialog({
size="lg"
title="Membri della bozza"
description={
<>
Chi aggiungi vede «{draft.title}» in Regolamenti › Bozze, anche senza altro accesso alla dashboard. Il
Direttivo legge e modifica sempre ogni bozza.
</>
draft.secret ? (
<>
«{draft.title}» è segreta: la vedono solo i membri, in Regolamenti › Bozze, con il ruolo che scegli qui,
anche se sono nel Direttivo.
</>
) : (
<>
Chi aggiungi vede «{draft.title}» in Regolamenti › Bozze, anche senza altro accesso alla dashboard. Il
Direttivo legge e modifica sempre ogni bozza.
</>
)
}
noun="membri"
dirty={false}
Expand Down Expand Up @@ -247,31 +255,35 @@ export function MembersDialog({
{members.map((member) => (
<li key={member.user.id} className="flex flex-wrap items-center justify-between gap-3 px-3 py-2">
<Person user={member.user} />
<span className="flex items-center gap-1">
{busy === `role:${member.user.id}` ? <Spinner className="size-4" /> : null}
<div className="w-44">
<label htmlFor={`member-role-${member.user.id}`} className="sr-only">
Ruolo di {member.user.name}
</label>
<SelectField
id={`member-role-${member.user.id}`}
value={member.role}
options={ROLE_OPTIONS}
onChange={(role) => changeRole(member, role)}
{draft.secret && member.user.id === draft.createdBy.id ? (
<span className="text-[13px] text-(--pn-fg-muted)">Editor, l'ha creata</span>
) : (
<span className="flex items-center gap-1">
{busy === `role:${member.user.id}` ? <Spinner className="size-4" /> : null}
<div className="w-44">
<label htmlFor={`member-role-${member.user.id}`} className="sr-only">
Ruolo di {member.user.name}
</label>
<SelectField
id={`member-role-${member.user.id}`}
value={member.role}
options={ROLE_OPTIONS}
onChange={(role) => changeRole(member, role)}
/>
</div>
<IconButton
label="Rimuovi"
ariaLabel={`Rimuovi ${member.user.name}`}
icon={UserMinus}
tone="danger"
disabled={busy !== null}
onClick={() => {
setRemoving(member)
setRemoveOpen(true)
}}
/>
</div>
<IconButton
label="Rimuovi"
ariaLabel={`Rimuovi ${member.user.name}`}
icon={UserMinus}
tone="danger"
disabled={busy !== null}
onClick={() => {
setRemoving(member)
setRemoveOpen(true)
}}
/>
</span>
</span>
)}
</li>
))}
</ul>
Expand Down
29 changes: 27 additions & 2 deletions src/features/regulations/new-draft-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function NewDraftDialog({
target.kind === "modifica" && target.from ? `${target.from.kind}:${target.from.id}` : null
)
const [title, setTitle] = useState(rettifica ? `Rettifica del ${formatDay(todayInRome())}` : "")
const [secret, setSecret] = useState(false)
const [submitted, setSubmitted] = useState(false)

// A rettifica starts from the latest version, which `me.rectifiable` names; a modifica lists versions and drafts.
Expand Down Expand Up @@ -98,6 +99,8 @@ export function NewDraftDialog({
? `version:${latest.latestVersionId}`
: null
: (from ?? bases[0]?.value ?? null)
// A draft from a secret draft carries its text: the backend makes it secret too.
const fromSecret = !rettifica && data?.drafts.some((draft) => chosen === `draft:${draft.id}` && draft.secret)
const titleError = submitted && !title.trim() ? "Scrivi un titolo." : undefined

async function submit() {
Expand All @@ -108,7 +111,7 @@ export function NewDraftDialog({
const base = kind === "draft" ? { kind: "draft" as const, id } : { kind: "version" as const, id }
let created: { id: string }
try {
const input = { documentKey, title: title.trim(), from: base }
const input = { documentKey, title: title.trim(), from: base, secret: secret || fromSecret === true }
created = rettifica
? await rectify({ data: { ...input, kind: "rettifica" } })
: await create({ data: { ...input, kind: "modifica" } })
Expand All @@ -117,7 +120,7 @@ export function NewDraftDialog({
throw new Error(failureMessage(caught, "Non è stato possibile creare la bozza. Riprova."), { cause: caught })
}
onOpenChange(false)
appToast.success(rettifica ? "Rettifica creata." : "Bozza creata.")
appToast.success(rettifica ? "Rettifica creata." : secret || fromSecret ? "Bozza segreta creata." : "Bozza creata.")
await navigate({ to: "/dashboard/regulations/drafts/$draftId", params: { draftId: created.id } })
}

Expand Down Expand Up @@ -183,6 +186,28 @@ export function NewDraftDialog({
))}
</RadioCardGroup>
)}
{fromSecret ? (
<p className="text-[13px] text-(--pn-fg-muted)">
Parte da una bozza segreta, quindi è segreta anche lei: la vedete solo tu e i membri che aggiungi.
</p>
) : (
<RadioCardGroup
label="Chi la vede"
value={secret ? "secret" : "visible"}
onValueChange={(value) => setSecret(value === "secret")}
>
<RadioCard
value="visible"
label="Visibile"
description="Chi ha accesso ai Regolamenti (il Direttivo) e i membri che aggiungi."
/>
<RadioCard
value="secret"
label="Segreta"
description="Solo tu e i membri che aggiungi. La procedura parte quando la rendi visibile, e non torna segreta."
/>
</RadioCardGroup>
)}
</div>
</FormDialog>
)
Expand Down
Loading
Loading