Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Lock the settings row on every save, alert each administrator, keep Part 11 controls reachable
Claudef08c5f2d873d
diff --git a/src/components/settings/people-panel.tsx b/src/components/settings/people-panel.tsxindex 08d6c05..f34f485 100644--- a/src/components/settings/people-panel.tsx+++ b/src/components/settings/people-panel.tsx@@ -296,25 +296,32 @@ export function PeoplePanel({ part11Mode = false }: { part11Mode?: boolean }) {<span className="pill pill-danger">Signing locked</span>) : null}</div>- {part11Mode ? (+ {/* Envelopes sent in Part 11 mode keep its rules after it is+ turned off, so an existing confirmation or lock can+ still be changed then. */}+ {part11Mode ||+ person.identityVerifiedAt !== null ||+ person.signingLockedAt !== null ? (<div className="flex flex-wrap gap-2 pt-1">{person.identityVerifiedAt === null ? (- <button- aria-label={`Confirm ${person.name}'s identity`}- className="btn-quiet"- disabled={- pendingId !== null ||- !person.emailVerified ||- verifyingId === person.id- }- onClick={() => {- setVerifyingId(person.id);- setVerificationNote("");- }}- type="button"- >- Confirm identity- </button>+ part11Mode ? (+ <button+ aria-label={`Confirm ${person.name}'s identity`}+ className="btn-quiet"+ disabled={+ pendingId !== null ||+ !person.emailVerified ||+ verifyingId === person.id+ }+ onClick={() => {+ setVerifyingId(person.id);+ setVerificationNote("");+ }}+ type="button"+ >+ Confirm identity+ </button>+ ) : null) : (<buttonaria-label={`Take back ${person.name}'s identity confirmation`}diff --git a/src/components/signing/signing-live-shell.tsx b/src/components/signing/signing-live-shell.tsxindex 3f38151..e36ca2b 100644--- a/src/components/signing/signing-live-shell.tsx+++ b/src/components/signing/signing-live-shell.tsx@@ -2076,7 +2076,10 @@ function DialogFrame({}) {return (<Dialog open onOpenChange={(open) => !open && onClose()}>- <DialogContent className="max-w-[600px] p-0" showCloseButton={false}>+ <DialogContent+ className="max-h-[calc(100dvh-2rem)] max-w-[600px] overflow-y-auto p-0"+ showCloseButton={false}+ ><div><DialogHeader className="space-y-2 px-6 pt-6 sm:px-8 sm:pt-8"><DialogTitle>{title}</DialogTitle>diff --git a/src/lib/part11.ts b/src/lib/part11.tsindex 1cca82c..8751296 100644--- a/src/lib/part11.ts+++ b/src/lib/part11.ts@@ -504,13 +504,18 @@ async function alertAdministrators("If this was not them, someone may be trying to sign in their name. Check with them before unlocking.",].join("\n");+ // One failed delivery must not keep the alert from the others.for (const admin of admins) {- await service.send({- subject: `Signing locked for ${person.name}`,- template: "signing_lock_alert",- textBody,- to: admin.email,- });+ try {+ await service.send({+ subject: `Signing locked for ${person.name}`,+ template: "signing_lock_alert",+ textBody,+ to: admin.email,+ });+ } catch (error) {+ console.error("Failed to send a signing lock alert:", error);+ }}} catch (error) {// The lock is in place and in the audit trail; the email is a courtesy.diff --git a/src/lib/settings.ts b/src/lib/settings.tsindex 302ada0..f1d8f17 100644--- a/src/lib/settings.ts+++ b/src/lib/settings.ts@@ -1,5 +1,11 @@import { buildBranding, type Branding } from "./branding.ts";-import { getDb, queryOne, type DbExecutor } from "./db/connection.ts";+import {+ type DbExecutor,+ type DbPool,+ getDb,+ queryOne,+ withTransaction,+} from "./db/connection.ts";import {evaluateSignup,type SignupDecision,@@ -320,6 +326,25 @@ export async function saveSettings(update: SettingsUpdate,database: DbExecutor = getDb(),): Promise<AppSettings> {+ // Read and write under the row's lock, so a save of some fields never+ // writes back a stale value of another (Part 11 mode above all) that a+ // different writer changed in between.+ if ("connect" in database && "totalCount" in database) {+ return withTransaction(+ (client) => saveSettingsLocked(update, client),+ database as DbPool,+ );+ }++ return saveSettingsLocked(update, database);+}++async function saveSettingsLocked(+ update: SettingsUpdate,+ database: DbExecutor,+): Promise<AppSettings> {+ await database.query(`SELECT id FROM app_settings WHERE id FOR UPDATE`);+const current = (await readStoredSettings(database)) ?? {...UNSET_SETTINGS,// A row that is being created is a decision about this install, and the