Download web/src/shell/ShareDialog.tsx from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 33.7 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/9291c0100f4e7b8da2efcbbf1ebdea72ee1663e7/web/src/shell/ShareDialog.tsx
- Command line
-
hf download hf://spaces/fsanyoto/loopable@9291c0100f4e7b8da2efcbbf1ebdea72ee1663e7/web/src/shell/ShareDialog.tsx
-
curl -L -o ShareDialog.tsx https://huggingface.co/spaces/fsanyoto/loopable/resolve/9291c0100f4e7b8da2efcbbf1ebdea72ee1663e7/web/src/shell/ShareDialog.tsx
33.7 kB
| // --------------------------------------------------------------------------- | |
| // shell/ShareDialog.tsx β WAVE 20 items 18 / 23 / 26 (R10, contract C-SHARE): | |
| // ONE dialog that shares a view, a folder or a database, and edits who already | |
| // has it. | |
| // | |
| // ONE dialog for three kinds is the ruling, not a convenience: R10 says folders | |
| // and databases share "with the SAME two-role vocabulary views use". Three | |
| // dialogs would drift into three vocabularies within a wave. | |
| // | |
| // It renders over the ALREADY-LOADED state and decides nothing itself β every | |
| // rule (what a junk entry means, who may administer, what the PUT carries) is in | |
| // `shareModel.ts`, where the access gate can run it. | |
| // --------------------------------------------------------------------------- | |
| import { useCallback, useEffect, useRef, useState } from "react"; | |
| import { API_V1, CREDENTIALS } from "../apiContract"; | |
| import PublishPanel from "../publish/PublishPanel"; | |
| import { useEscapeClose } from "../ui/useEscapeClose"; | |
| import { | |
| EVERYONE, | |
| EVERYONE_LABEL, | |
| SHARE_ROLES, | |
| addablePeople, | |
| parseShare, | |
| resolveShareRecipient, | |
| shareAccessStatus, | |
| sharePutBody, | |
| withEntry, | |
| withoutEntry, | |
| } from "./shareModel"; | |
| import type { ShareEntry, ShareKind, ShareRole, ShareState } from "./shareModel"; | |
| /** | |
| * ββ W39-T17 β THIS MAP DOES NOT DEGRADE, IT PRINTS THE WORD `undefined`. A kind with no entry | |
| * renders "Share undefined" in the heading AND "no longer has this undefined" in the revoke toast: | |
| * two live strings, not one. `Record<ShareKind, string>` is what stops that being a discovery β | |
| * add a member to `SHARE_KINDS` without one here and `tsc` names this line. | |
| */ | |
| const KIND_WORD: Record<ShareKind, string> = { | |
| view: "view", | |
| folder: "folder", | |
| database: "database", | |
| field: "field", | |
| workbook: "workbook", | |
| report: "report", | |
| }; | |
| // A newly-created field is posted through the standalone event queue. The | |
| // share dialog can open before that POST reaches the API, so give field lookups | |
| // a short, bounded chance to observe the definition before showing a 404. | |
| // | |
| // W50-T23 KEPT THIS DELIBERATELY, AND THE SERVER CHANGE IS WHAT SCOPED IT. | |
| // `GET /share/field/...` used to answer 404 for two different situations: a | |
| // column that does not exist yet (the create race above) and a column that | |
| // exists but is not this account's, which is far commoner. The route now | |
| // answers the second one with a 403 that names the column and its owner, so a | |
| // 404 on this kind means only "no definition in any stratum" -- which is the | |
| // race, and the one thing waiting can actually fix. Deleting the loop would | |
| // take the guard away from the race it was written for; the retry is now bounded | |
| // to that race by what the server can still answer, not by a client-side flag. | |
| const FIELD_SHARE_RETRY_MS = [150, 300, 600, 1000] as const; | |
| /** What each role MEANS on each kind, in the reader's own terms. A role picker | |
| * whose options are two nouns makes the reader guess; these sentences describe | |
| * the effective capability at the point where the role is chosen. */ | |
| const ROLE_BLURB: Record<ShareKind, Record<ShareRole, string>> = { | |
| view: { | |
| view: "Can open this view. Cannot rename, refilter or delete it.", | |
| edit: "Can change this view's filters, sorts and columns, then share it with other people.", | |
| }, | |
| folder: { | |
| view: "Can open the folder and the views inside it.", | |
| edit: "Can rename the folder and move views in and out of it.", | |
| }, | |
| database: { | |
| view: "Can open this database and read its records.", | |
| edit: "Can add, edit and delete its records.", | |
| }, | |
| field: { | |
| view: "Can see this column. Cannot change its values or field settings.", | |
| edit: "Can change this column's values and field settings when the view is editable.", | |
| }, | |
| /* R16, and the wording tracks the picker: a workbook's view role reads "View only", so the | |
| sentence under it says what "only" leaves out rather than restating the label. */ | |
| workbook: { | |
| view: "View only: can open this workbook and read every sheet in it. Cannot change a cell, a formula or a binding.", | |
| edit: "Can change this workbook's cells, formulas and bindings.", | |
| }, | |
| report: { | |
| view: "Can download this report.", | |
| edit: "Reports cannot be edited.", | |
| }, | |
| }; | |
| /** | |
| * ββ W51-T10 / R16 β WHAT A WORKBOOK SHARE ACTUALLY HANDS OVER, AND THE HALF NOBODY EXPECTS. | |
| * A workbook's cells are not all values: a bound cell is a QUERY, and it is run again under | |
| * whoever is reading. So two people can open one shared workbook and honestly see two different | |
| * numbers, and the person doing the sharing has to be told that before they share. | |
| * | |
| * β A `const`, NOT INLINE JSX, FOR THE REASON THIS FILE ALREADY RECORDS TWICE: `verify_prose`'s | |
| * JSX pass skips any run containing a newline, and a pinning regex cannot span a prettier line | |
| * wrap. `verify_wiring.py`'s W51-T10 section matches this literal. | |
| * | |
| * β IT RENDERS ABOVE THE ROLE PICKER RATHER THAN INSIDE IT. The picker's blurb only paints once | |
| * the GET has answered, and the workbook share routes do not exist yet, so a sentence that lived | |
| * there alone would be absent in the only case that exists today. | |
| */ | |
| const WORKBOOK_BOUND_CELLS = | |
| "Bound cells show what each person may see: every bound cell is read again under the reader's own scope, so one workbook can honestly show two people different numbers."; | |
| /** | |
| * ββ THE DEGRADE, AND IT IS KEYED ON A RANGE RATHER THAN ON A LIST OF CODES. `GET | |
| * /share/workbook/{id}` sits under a `/{kind}/{oid}` path param, so an id this account cannot | |
| * reach answers 404 while a shape the server dislikes can surface as 400, 405 or 500. A code | |
| * list would miss the very answer the server actually gives, and the reader would get the | |
| * generic "The server answered 405." instead: a status number, which is not a sentence and | |
| * tells them nothing they can act on. 403 stays on the ordinary path, because "you may not" is | |
| * a real answer about a route that exists. | |
| * | |
| * β THE SENTENCE CHANGED AT THE WAVE-51 GO-LIVE QA, AND THE OLD ONE WAS THE DEFECT. | |
| * It read *"Workbook sharing is still being built"*, which was true when W51-T10 shipped | |
| * against an unbuilt server half and FALSE the moment W51-T25 landed beside it in the combine. | |
| * The QA pass then found the real cause: `routes_shares.py::_owns_object` carried no | |
| * `workbook` branch, so the owner of an unshared workbook was answered `404 no_object` and this | |
| * copy explained a shipped feature away as unbuilt. The branch exists now; this string is the | |
| * ordinary degrade for a workbook that genuinely cannot be reached, and it no longer makes a | |
| * claim about the product's roadmap that only a code reader could falsify. | |
| * β NO EM DASH AND NO EN DASH: this reaches a screen (standing rule 2). | |
| */ | |
| const WORKBOOK_SHARE_UNREACHABLE = | |
| "This workbook's sharing list could not be loaded. Close and reopen the dialog; if it keeps failing, the workbook may have been deleted, or it may no longer be yours to share."; | |
| /** | |
| * ββ W42-T26 (owner instruction 8, R9, contract C7) β THE SHARER IS TOLD WHICH FIELDS TRAVEL. | |
| * Sharing a view grants every field the view NAMES, and until this landed the dialog said nothing | |
| * about fields at all. The trap the ticket names: T25 makes the behaviour correct and nothing on | |
| * screen changes, so the disclosure is the half that gets dropped. | |
| * | |
| * β THESE ARE CONSTANTS, NOT INLINE JSX TEXT, FOR TWO REASONS. (1) `verify_prose`'s JSX pass skips | |
| * any run containing a newline [[web-prose-blind-to-wrapped-jsx]], and this file's own comments | |
| * record that blind spot twice; a `const` string literal is seen by the gate whatever prettier does | |
| * to the markup around it. (2) `wiring_rows/wave42_g.py` pins this copy by regex, and a regex | |
| * cannot span a JSX line wrap. Standing rule 2: no em dash and no en dash below. | |
| */ | |
| const VIEW_FIELD_TRAVEL = | |
| "Sharing a view also shares the fields it uses: the columns it shows, and the columns it groups by, colors by and sorts by."; | |
| /** β ITS OWN SENTENCE ON PURPOSE, and the non-obvious half of the disclosure. A sharer reasons | |
| * about the columns they can SEE; a condition may name one they never put on screen, and the | |
| * grant covers it all the same. The done-when calls this clause out separately, so it has to be | |
| * readable on its own rather than being a word inside a list. | |
| * β Do NOT restate the literal below in prose here: `wave42_g.py` pins it, and the WIRINGS loop | |
| * matches raw file text (comments included), so a paraphrase close enough to match would let the | |
| * row pass off its own explanation. */ | |
| const VIEW_FILTER_FIELDS = | |
| "The filters count too. A filter can test a column that is not on screen, and sharing this view hands that column over as well."; | |
| /** β The grant is TOPIC-WIDE by construction (C7), so the dialog has to say so in the reader's | |
| * terms rather than let them assume it stops at this view. */ | |
| const VIEW_FIELD_TOPIC_WIDE = | |
| "Each of those fields then shows on every view of this database, not only on this one."; | |
| const VIEW_EDITOR_REDISTRIBUTION = | |
| "People with Can edit may share this View with others. They may include any field they can read."; | |
| export default function ShareDialog({ | |
| kind, | |
| id, | |
| label, | |
| topic, | |
| me, | |
| onClose, | |
| onToast, | |
| }: { | |
| kind: ShareKind; | |
| id: string; | |
| label: string; | |
| /** | |
| * β W33-T27 (item 8b, R5) β the DATABASE a shared VIEW belongs to, so the publish control can | |
| * address it as `(topic, view)`. Empty for a folder or a database share, and empty is honest: | |
| * the panel simply does not render, which is also what happens on a view the server refuses to | |
| * publish. β Supplied by `Shell` at the mount (`shareModel.ShareRequest.topic`), not by this | |
| * dialog β see that field's note for why it is optional and how the mount is asserted. | |
| */ | |
| topic?: string; | |
| /** The signed-in account's username, so the reader recognises themselves in the | |
| * list. `people` is deliberately the OTHER accounts (it is the add-picker's | |
| * source), so without this the owner row prints a raw login where every other | |
| * row prints a name. */ | |
| me: string; | |
| onClose: () => void; | |
| onToast: (message: string) => void; | |
| }) { | |
| const [state, setState] = useState<ShareState | null>(null); | |
| const [entries, setEntries] = useState<ShareEntry[]>([]); | |
| const [error, setError] = useState(""); | |
| const [busy, setBusy] = useState(false); | |
| const [recipientQuery, setRecipientQuery] = useState(""); | |
| const [pickRole, setPickRole] = useState<ShareRole>("view"); | |
| // The shared parser drops response extensions, so retain the server ceiling separately. | |
| const [maxGrantableRole, setMaxGrantableRole] = useState<ShareRole | null>(null); | |
| const dialogRef = useRef<HTMLDivElement>(null); | |
| const focusReturnRef = useRef<HTMLElement | null>(null); | |
| // W50-T23 / R7 -- the owner in the words a person reads, resolved by the server | |
| // through the account registry, with "System (Odoo)" standing in for a column | |
| // the connector wrote. `parseShare` builds a fixed five-key object and drops | |
| // everything else, so this display-only label rides off the raw body. | |
| const [ownerLabel, setOwnerLabel] = useState(""); | |
| const path = `${API_V1}/share/${encodeURIComponent(kind)}/${encodeURIComponent(id)}`; | |
| useEffect(() => { | |
| focusReturnRef.current = document.activeElement instanceof HTMLElement | |
| ? document.activeElement | |
| : null; | |
| dialogRef.current?.focus(); | |
| return () => { | |
| const opener = focusReturnRef.current; | |
| if (opener?.isConnected) opener.focus(); | |
| }; | |
| }, []); | |
| useEffect(() => { | |
| let dead = false; | |
| setState(null); | |
| setMaxGrantableRole(null); | |
| setPickRole("view"); | |
| setError(""); | |
| void (async () => { | |
| try { | |
| let res: Response; | |
| for (let attempt = 0; ; attempt += 1) { | |
| res = await fetch(path, { credentials: CREDENTIALS }); | |
| if ( | |
| res.status !== 404 || | |
| kind !== "field" || | |
| attempt >= FIELD_SHARE_RETRY_MS.length | |
| ) { | |
| break; | |
| } | |
| await new Promise<void>((resolve) => { | |
| window.setTimeout(resolve, FIELD_SHARE_RETRY_MS[attempt]); | |
| }); | |
| if (dead) return; | |
| } | |
| if (!res.ok) { | |
| // W51-T10: a workbook the server will not answer for. A sentence, never a status | |
| // number, and never a blank dialog. See `WORKBOOK_SHARE_UNREACHABLE` for why the | |
| // test is a RANGE rather than a code list. | |
| if (kind === "workbook" && res.status >= 400 && res.status !== 403) { | |
| if (!dead) setError(WORKBOOK_SHARE_UNREACHABLE); | |
| return; | |
| } | |
| // 4xx text is policy the reader needs; a 5xx's internals are not theirs. | |
| if (!dead) setError(res.status >= 500 | |
| ? "Something went wrong on our side. Try again in a moment." | |
| : `The server answered ${res.status}.`); | |
| return; | |
| } | |
| const body = (await res.json().catch(() => null)) as unknown; | |
| if (dead) return; | |
| const parsed = parseShare(body); | |
| const ceiling = body && typeof body === "object" | |
| ? (body as { maxGrantableRole?: unknown }).maxGrantableRole | |
| : null; | |
| setMaxGrantableRole(ceiling === "view" || ceiling === "edit" ? ceiling : null); | |
| setState(parsed); | |
| setEntries(parsed.entries); | |
| setOwnerLabel( | |
| body && typeof body === "object" | |
| && typeof (body as { ownerLabel?: unknown }).ownerLabel === "string" | |
| ? ((body as { ownerLabel?: string }).ownerLabel ?? "").trim() | |
| : "" | |
| ); | |
| } catch { | |
| if (!dead) setError("Cannot reach the server."); | |
| } | |
| })(); | |
| return () => { | |
| dead = true; | |
| }; | |
| }, [path]); | |
| // The Share modal joins the one overlay stack. A local key listener races any picker or | |
| // nested publish control mounted inside it and can close two surfaces from one Escape. | |
| useEscapeClose(true, () => { | |
| if (!busy) onClose(); | |
| }, { container: () => dialogRef.current }); | |
| const save = useCallback( | |
| async (next: ShareEntry[]) => { | |
| setBusy(true); | |
| setError(""); | |
| try { | |
| const res = await fetch(path, { | |
| method: "PUT", | |
| credentials: CREDENTIALS, | |
| headers: { "Content-Type": "application/json" }, | |
| // The WHOLE list, every time: the PUT replaces, so a body assembled from | |
| // a delta would revoke everyone it failed to mention. | |
| body: JSON.stringify(sharePutBody(next)), | |
| }); | |
| if (!res.ok) { | |
| const body = (await res.json().catch(() => null)) as | |
| | { error?: { code?: string; message?: string } } | |
| | null; | |
| setError( | |
| res.status >= 500 && body?.error?.code !== "view_share_failed" | |
| ? "Something went wrong on our side. Try again in a moment." | |
| : body?.error?.message || `The server answered ${res.status}.` | |
| ); | |
| return false; | |
| } | |
| const body = (await res.json().catch(() => null)) as unknown; | |
| // Re-read the SERVER's copy rather than trusting the draft: `_clean_entries` | |
| // drops what it will not store, and an editor that kept showing a row the | |
| // store rejected would be the "shared, silently inert" failure this feature | |
| // exists to avoid. | |
| // β Only `.entries` is consumed here β the PUT answers with the stored record | |
| // (`{owner, entries}`) and says nothing about this session's standing, so the | |
| // literal below feeds the parser's required field and is never read back. The | |
| // editor's `mayAdminister` stays the one the GET established; a save cannot | |
| // promote anybody, and this line must never be the reason it looks like it can. | |
| const saved = parseShare({ ...(body as object), mayAdminister: true }); | |
| setEntries(saved.entries); | |
| return true; | |
| } catch { | |
| setError("Cannot reach the server."); | |
| return false; | |
| } finally { | |
| setBusy(false); | |
| } | |
| }, | |
| [path] | |
| ); | |
| const mayAdminister = !!state?.mayAdminister; | |
| const grantableRoles = SHARE_ROLES.filter((role) => mayAdminister && (kind !== "report" || role === "view") && ( | |
| maxGrantableRole === "edit" || (maxGrantableRole === "view" && role === "view") | |
| )); | |
| const assign = useCallback(async (user: string) => { | |
| setBusy(true); setError(""); | |
| try { | |
| const res = await fetch(`${path}/assign`, { | |
| method: "POST", credentials: CREDENTIALS, | |
| headers: { "Content-Type": "application/json" }, body: JSON.stringify({ user }), | |
| }); | |
| if (!res.ok) { setError(`The server answered ${res.status}.`); return; } | |
| onToast(`${nameOf(user)} now has this assigned view.`); | |
| } catch { setError("Cannot reach the server."); } | |
| finally { setBusy(false); } | |
| }, [path, onToast]); | |
| const options = state ? addablePeople(state.people, entries) : []; | |
| const pick = state | |
| ? kind === "report" | |
| ? resolveShareRecipient(state.people, entries, recipientQuery, kind) | |
| : resolveShareRecipient(state.people, entries, recipientQuery) | |
| : null; | |
| const canAddEveryone = kind !== "report" && !entries.some((entry) => entry.user === EVERYONE); | |
| const nameOf = (user: string) => | |
| user === "*" | |
| ? "Everyone" | |
| : user && user === me.trim().toLowerCase() | |
| ? "You" | |
| : state?.people.find((p) => p.user === user)?.name ?? user; | |
| return ( | |
| <div className="shell-newdb-scrim"> | |
| <div | |
| ref={dialogRef} | |
| className="shell-newdb shell-share" | |
| role="dialog" | |
| aria-modal="true" | |
| aria-label={`Share ${label}`} | |
| tabIndex={-1} | |
| onClick={(e) => e.stopPropagation()} | |
| > | |
| <h2>Share {KIND_WORD[kind]}</h2> | |
| {/* ββ W33-T30 / audit S-8 β THIS SENTENCE WAS FALSE FOR ONE OF THE THREE KINDS. | |
| It read, unconditionally, "Sharing never widens past this workspace: everyone here | |
| can already open the surface it lives on." True for a VIEW or a FOLDER on a governed | |
| module, where the receiver's row scope and hidden-field closure run before any | |
| foreign view is merged. FALSE for a `database` grant on a `ut_*` table: no row filter | |
| and no hidden field can even be DECLARED there (`_PERM_MODULES` is two keys and | |
| `_clean_perms` 400s the rest), so the grant registry IS the only wall and the grant | |
| is all-or-nothing. The audit's fix is "say so at BOTH doors"; `core/shares.py` and | |
| `routes_shares.py` are the other two, and this is the one a PERSON reads. */} | |
| {/* β STANDING RULE 2 (D-490, W39-T17) β THIS LINE CARRIED AN EM DASH TO THE SCREEN AND | |
| `verify_prose.py` SCORED THE FILE ZERO. The prose run WRAPS, and the gate's JSX pass | |
| skips any run containing a newline [[web-prose-blind-to-wrapped-jsx]] β the same blind | |
| spot already recorded twenty lines below. REWRITTEN, not stripped: the question the | |
| dialog answers is now the sentence's subject, which needs no dash at all. */} | |
| <p className="shell-newdb-sub"> | |
| {kind !== "report" ? <>Who can reach <strong>{label}</strong>, and what they can do with it.{" "}</> : null} | |
| {kind === "workbook" | |
| ? WORKBOOK_BOUND_CELLS | |
| : kind === "database" | |
| ? "Sharing a database shares all of it: every record and every column. There is no per-row or per-column limit on a database grant." | |
| : kind === "field" | |
| ? "A shared column starts out hidden from everybody else on this database. This is what lets the people you choose see it and its values." | |
| : kind === "report" | |
| ? "Only the people you add here see this report." | |
| : "Sharing never widens past this workspace: everyone here can already open the surface it lives on."} | |
| </p> | |
| {kind === "view" ? ( | |
| <> | |
| <p className="shell-share-note"> | |
| View access is the general rule. A field's own Share field access takes precedence, so | |
| a field shared as Can view stays read-only even inside an editable view. | |
| </p> | |
| {/* ββ W42-T26 / C7 β WHICH FIELDS TRAVEL, and how far. Two paragraphs, not one and | |
| not four: the done-when reads for three statements (what travels, the FILTER's | |
| fields by name, and the topic-wide reach), and a sharer must be able to point at a | |
| sentence for each without reading an essay in a dialog subtitle. */} | |
| <p className="shell-share-note"> | |
| {VIEW_FIELD_TRAVEL} {VIEW_FIELD_TOPIC_WIDE} | |
| </p> | |
| <p className="shell-share-note">{VIEW_FILTER_FIELDS}</p> | |
| <p className="shell-share-note">{VIEW_EDITOR_REDISTRIBUTION}</p> | |
| </> | |
| ) : kind === "field" ? ( | |
| <p className="shell-share-note"> | |
| Field access takes precedence over the view. Can view keeps values and field settings | |
| read-only; Can edit allows changes when the view is editable. | |
| </p> | |
| ) : null} | |
| {!state && !error ? ( | |
| <div className="shell-share-wait"> | |
| <span className="lp-spin" role="status" aria-label="Loading" /> | |
| </div> | |
| ) : null} | |
| {state ? ( | |
| <> | |
| {/* THE MANAGE-ACCESS EDITOR (item 23): the list first, because the | |
| question people open this for is "who has this already" β with the | |
| one-line answer above it, since the fact that changes everything | |
| ("Everyone can edit") is the one a list of rows buries. */} | |
| <h3 className="shell-share-summary">Manage access</h3> | |
| <p className="shell-share-note"> | |
| Workspace access: {shareAccessStatus(entries)}. | |
| </p> | |
| <div className="shell-share-list"> | |
| {/* W50-T23 / R7 -- THE OWNER ROW IS NEVER BLANK AND NEVER ABSENT. Under R7 | |
| every editable field has an owner (its creator, else the tenant | |
| Administrator) and a connector column reads "System (Odoo)", so there is | |
| always something true to print. The old `: null` arm rendered NOTHING for | |
| a column whose owner the server could not name, which is how a member | |
| ended up being told to ask somebody the dialog never showed them. | |
| `ownerLabel` is preferred over `nameOf` only when `nameOf` could not | |
| resolve the username: a member gets `people: []`, so `nameOf` would print | |
| a raw login where the server already knows the real name. */} | |
| {state.owner || (kind === "field" && ownerLabel) ? ( | |
| <div className="shell-share-row is-owner"> | |
| <span className="shell-share-who"> | |
| {state.owner | |
| ? nameOf(state.owner) === state.owner | |
| ? ownerLabel || state.owner | |
| : nameOf(state.owner) | |
| : ownerLabel} | |
| </span> | |
| <span className="shell-share-role">Owner</span> | |
| </div> | |
| ) : null} | |
| {entries.length === 0 ? ( | |
| <div className="shell-share-empty"> | |
| Not shared with anyone yet. | |
| </div> | |
| ) : null} | |
| {entries.map((e) => ( | |
| <div className="shell-share-row" key={e.user}> | |
| <span className="shell-share-who">{nameOf(e.user)}</span> | |
| {grantableRoles.includes(e.role) ? <select | |
| className="shell-share-select" | |
| value={e.role} | |
| disabled={!mayAdminister || busy} | |
| aria-label={`Role for ${nameOf(e.user)}`} | |
| onChange={(ev) => { | |
| const role = ev.target.value as ShareRole; | |
| if (!grantableRoles.includes(role)) return; | |
| const next = withEntry(entries, e.user, role); | |
| void save(next); | |
| }} | |
| > | |
| {/* β W51-T10 / R16 β THE LABEL IS PER KIND, exactly as `KIND_WORD` and | |
| `ROLE_BLURB` are. A workbook's read role is "View only" (the ruling's own | |
| words); the other four kinds keep "Can view" byte for byte, because | |
| re-wording one label across a shared control is a repo-wide gate grep. */} | |
| {grantableRoles.map((r) => ( | |
| <option key={r} value={r}> | |
| {r === "edit" | |
| ? "Can edit" | |
| : kind === "report" ? "Can download" : kind === "workbook" ? "View only" : "Can view"} | |
| </option> | |
| ))} | |
| </select> : ( | |
| // Existing grants above the ceiling stay unchanged in every replacing PUT. | |
| <span className="shell-share-role"> | |
| {e.role === "edit" ? "Can edit" : kind === "report" ? "Can download" : kind === "workbook" ? "View only" : "Can view"} | |
| </span> | |
| )} | |
| <button | |
| type="button" | |
| className="shell-share-revoke" | |
| disabled={!mayAdminister || busy} | |
| onClick={() => { | |
| const next = withoutEntry(entries, e.user); | |
| void save(next).then((ok) => { | |
| if (ok) onToast(`${nameOf(e.user)} no longer has this ${KIND_WORD[kind]}.`); | |
| }); | |
| }} | |
| > | |
| Remove | |
| </button> | |
| {kind === "view" && mayAdminister && e.user !== "*" ? ( | |
| <button type="button" className="shell-share-revoke" disabled={busy} | |
| onClick={() => void assign(e.user)}> | |
| Assign | |
| </button> | |
| ) : null} | |
| </div> | |
| ))} | |
| </div> | |
| {mayAdminister ? ( | |
| <div className="shell-share-add"> | |
| <input | |
| className="shell-share-select" | |
| type="search" | |
| list="shell-share-recipient-options" | |
| value={recipientQuery} | |
| disabled={busy} | |
| aria-label="Search people to share with" | |
| placeholder="Search people" | |
| autoFocus | |
| onChange={(e) => setRecipientQuery(e.target.value)} | |
| /> | |
| <datalist id="shell-share-recipient-options"> | |
| {canAddEveryone ? <option value={EVERYONE_LABEL} /> : null} | |
| {options.map((p) => ( | |
| <option key={p.user} value={`${p.name} (${p.user})`} /> | |
| ))} | |
| </datalist> | |
| <select | |
| className="shell-share-select" | |
| value={pickRole} | |
| disabled={busy || !grantableRoles.length} | |
| aria-label="Role for the person being added" | |
| onChange={(e) => { | |
| const role = e.target.value as ShareRole; | |
| if (grantableRoles.includes(role)) setPickRole(role); | |
| }} | |
| > | |
| {/* The add-person picker says the same words the row picker says. */} | |
| {grantableRoles.map((r) => ( | |
| <option key={r} value={r}> | |
| {r === "edit" | |
| ? "Can edit" | |
| : kind === "report" ? "Can download" : kind === "workbook" ? "View only" : "Can view"} | |
| </option> | |
| ))} | |
| </select> | |
| <button | |
| type="button" | |
| className="login-submit shell-share-grant" | |
| disabled={busy || !pick || !grantableRoles.includes(pickRole)} | |
| onClick={() => { | |
| if (!pick || !grantableRoles.includes(pickRole)) return; | |
| const next = withEntry(entries, pick, pickRole); | |
| void save(next).then((ok) => { | |
| if (ok) { | |
| onToast( | |
| kind === "field" | |
| ? `${nameOf(pick)} can now ${pickRole === "edit" ? "edit" : "view"} this field.` | |
| : kind === "report" | |
| ? `${nameOf(pick)} can now download this report.` | |
| : `${nameOf(pick)} can now ${pickRole} this ${KIND_WORD[kind]}.` | |
| ); | |
| setRecipientQuery(""); | |
| } | |
| }); | |
| }} | |
| > | |
| Send | |
| </button> | |
| <p className="shell-share-blurb">{ROLE_BLURB[kind][pickRole]}</p> | |
| {/* β W33-T30 / audit S-5 β `*` + `edit` IS A TENANT-WIDE WRITE GRANT AND LOOKED | |
| LIKE ANY OTHER ROW. Two ordinary choices β a population and a role, each | |
| unremarkable alone β combine into "anybody here may change this", and the | |
| dialog said nothing at the point where the two meet. The audit's fix is | |
| "make the population legible at the point of choice": one sentence, only on | |
| the combination, in the words of the consequence rather than of the setting. | |
| β It is NOT a confirm step. The capability is real and deliberate; a person | |
| choosing it on purpose should not be interrogated, only told what it means. */} | |
| {/* β `shell-share-note`, the class the refusal below already uses, rather than a | |
| new `shell-share-warn`: `index.css` is B's file this wave (contract C4), and a | |
| new class with no rule renders as unstyled body text β which for a sentence | |
| whose whole job is to be NOTICED is worse than reusing a quiet one. */} | |
| {/* β STANDING RULE 2 (wave-36 QA) β the sentence below carried an em dash and | |
| `web_prose` scored this file 0 findings: the prose run WRAPS, and the gate's | |
| JSX pass skips any run containing a newline [[web-prose-blind-to-wrapped-jsx]]. | |
| REWRITTEN, not merely stripped β the comma keeps the contrast the sentence | |
| exists to draw. */} | |
| {pick === EVERYONE && pickRole === "edit" ? ( | |
| <p className="shell-share-note"> | |
| Everyone in this workspace will be able to change this {KIND_WORD[kind]}, | |
| not just open it. | |
| </p> | |
| ) : null} | |
| </div> | |
| ) : ( | |
| // β NOT A HIDDEN EDITOR β a stated refusal. A collaborator who can | |
| // change this object's CONTENT still cannot change who else reaches | |
| // it (the server's rule; this is the courtesy half). Saying why beats | |
| // greying three controls and letting the reader guess. | |
| // β STANDING RULE 2 (W39-T17) β TWO em dashes, live on screen, and `verify_prose` | |
| // green over both for the wrapped-JSX reason recorded above. NOT a pre-existing | |
| // violation this ticket may leave alone: adding `field` to `KIND_WORD` is what | |
| // brings this sentence to a NEW surface, so it ships the dash rather than merely | |
| // inheriting it. Rewritten with the owner in the subject, so no aside is needed. | |
| <p className="shell-share-note"> | |
| {kind === "report" | |
| ? "Only workspace administrators can change who this report is shared with." | |
| : <>Only this {KIND_WORD[kind]}'s owner and workspace administrators can change who | |
| it is shared with. You can still use it as your role allows.</>} | |
| </p> | |
| )} | |
| </> | |
| ) : null} | |
| {/* ββ W33-T27 (item 8b, R5) β PUBLISH, below the grant editor and inside the same | |
| dialog, because this is where a person comes to ask "who can reach this?". | |
| β IT IS NOT A FOURTH ROLE IN THE LIST ABOVE, and the panel says so in its own | |
| words: a published link names nobody, creates no grant and is revoked by replacing | |
| the link rather than by removing a person. Folding it into the entries list would | |
| have made "the public" look like a grantee β which is precisely the conflation the | |
| sharing audit's S-4 row is about (two systems already answer "is this shared"; this | |
| is a third thing). | |
| β ONLY FOR A VIEW, and only when the shell knew which database it belongs to. The | |
| panel then asks the SERVER whether this particular view may be published and renders | |
| nothing if not β so "absent on non-interface views" is one evaluator, not two. */} | |
| {kind === "view" && topic ? <PublishPanel topic={topic} view={id} /> : null} | |
| {error ? <p className="shell-newdb-err" role="alert">{error}</p> : null} | |
| <div className="shell-newdb-actions"> | |
| <button type="button" disabled={busy} onClick={onClose}>Close</button> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |