Roles and permissions
Restrict editor capabilities per participant or per document.
A mode (editing, suggesting, viewing) can be switched at runtime; a role constrains which modes and actions are allowed and cannot be escalated from inside the editor.
TSX
<ReviseEditor
role="suggester"
initialDocuments={[
{ id: "contract-1", source: file },
{ id: "exhibit-a", source: exhibit, role: "viewer" }, // per-document override
]}
/>| Role | Edits | Direct edits | Accept / reject | Comments |
|---|---|---|---|---|
editor (default) | Yes | Yes | Yes | Yes |
suggester | Tracked suggestions only | No | No | Yes |
viewer | No | No | No | No |
suggester cannot accept or reject suggestions (accepting a suggestion applies a direct edit). Suggesters can still navigate review, preview accept/reject, and comment.
Enforcement#
- Modes & toolbar:
setDocumentMode()clamps to allowed modes (requesting"editing"as asuggestersets"suggesting"and reports it toonDocumentModeChange). - Built-in chrome: Hides the mode toggle when only one mode is allowed, omits accept/reject buttons from the ribbon, and hides inline suggestion tooltips.
- Handle:
review.accept*()/reject*()returnfalseor mark all IDsunresolved. Comment mutations no-op forviewer. - Agent tools:
tools.execute()returns{ ok: false, error: { code: "role_not_permitted" } }for mutations disallowed byviewerand fordirectMode: truecalls undersuggester(withoutdirectMode, the call produces a tracked suggestion). Delegatedagent.run()validates before starting and throwsReviseRoleError.
TypeScript
import { ReviseRoleError } from "revise";
const result = await editor.tools.execute("replace", input, { directMode: true });
if (!result.ok && result.error.code === "role_not_permitted") {
// Direct edits are rejected for suggesters.
}
try {
await editor.agent.run(task, { directMode: true });
} catch (error) {
if (error instanceof ReviseRoleError) {
// error.role === "suggester", error.action === "apply changes directly"
}
}Read the role#
TypeScript
editor.getRole(); // active document
editor.getRole("exhibit-a"); // specific documentRoles are client-side UI and API guardrails, not authorization. In a collaborative room, assign roles on your server and reject unauthorized writes at your sync transport.