Phase 7: the client link
Staff make a link for a person (or "+ New client": a record with only the name they know, and its link); the client fills in their own record from their phone without a login, and presses Send. - Links (src/links.rs, migrations/0006): the table keeps the SHA-256 of the token only, as sessions do; the link is shown once, to copy, to email (mailto with the person's address) or as a QR code (qrcode crate, inline SVG). It is open 14 days, until Send, or until staff close it; a new link closes the earlier one. States open, opened, sent, closed, expired. - The client's pages at /c/<token> (src/web/client.rs, client_*.html in a frame of their own, phone first): About you, Passport (the photo reader; a zone fills in the personal details still empty), Address in Thailand, Contact, Documents, Send. Each part is saved on its own, straight into the record. Forms carry the link's own token plus the same-site check. A passport with the same number is changed; an address unlike the current one is added beside it, so the current one and its TM.30 receipt stay; a second save changes what the link added. Uploads (passport page, photo, visa, arrival stamp, TDAC, work permit, other) go through the same checks and encrypted store as staff uploads, tied to the person's newest record of their kind. - Audit: the client's views and changes carry the actor `link <id>`; actions send and close and entity link are new. The person's page shows the newest links, when they were opened and sent, and each record the client changed, with the fields, to check. - Demo data: Erika sent her link an hour ago (phone and email changed), Jane opened hers. - documents::read_upload returns why it refused, so the client's pages answer in their own words. Checks: fmt, clippy; 101 unit and 54 integration tests (tests/client.rs: the link shown once and kept as a hash, a new client, the whole client flow with the login on, forged, closed, expired and made-up links); layout check light/dark desk/phone on the client pages, the person page and the new client form: no problems; the camera reader on the client's passport page with a fake camera filled the form and Send closed the link.
This commit is contained in:
1 parent
a6ebdfc89c
commit
43ed75d81b
32 files changed
+2706
-40
No files matched your search
@@ -0,0 +1,45 @@
|
||||
-- visa.buildfor.life, phase 7: the client link (docs/PLAN.md "Phase 7").
|
||||
--
|
||||
-- Staff make a link for a person; the client fills in their details through
|
||||
-- it without a login. The table keeps the SHA-256 of the link's token, never
|
||||
-- the token, as `sessions` does: a dump of it opens no link. A link is open
|
||||
-- until it expires, the client presses Send, or staff close it; a new link
|
||||
-- closes the person's earlier one.
|
||||
|
||||
CREATE TABLE client_links (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
person_id BIGINT NOT NULL REFERENCES people (id),
|
||||
token_hash BYTEA NOT NULL UNIQUE,
|
||||
-- the link's own form token
|
||||
csrf TEXT NOT NULL,
|
||||
created_by TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
first_used_at TIMESTAMPTZ,
|
||||
last_used_at TIMESTAMPTZ,
|
||||
sent_at TIMESTAMPTZ,
|
||||
closed_at TIMESTAMPTZ,
|
||||
-- who closed it: a staff login, or 'client' when the client sent it
|
||||
closed_by TEXT NOT NULL DEFAULT '',
|
||||
CHECK (expires_at > created_at),
|
||||
CHECK (sent_at IS NULL OR closed_at IS NOT NULL)
|
||||
);
|
||||
CREATE INDEX client_links_person ON client_links (person_id, id);
|
||||
|
||||
-- The link in the audit log: made, sent and closed; the client's views and
|
||||
-- changes carry the actor `link <id>`.
|
||||
ALTER TABLE audit_log DROP CONSTRAINT audit_log_action_check;
|
||||
ALTER TABLE audit_log ADD CONSTRAINT audit_log_action_check CHECK (
|
||||
action IN (
|
||||
'view', 'create', 'update', 'delete', 'archive', 'restore', 'sign-in', 'sign-out',
|
||||
'download', 'send', 'close'
|
||||
)
|
||||
);
|
||||
ALTER TABLE audit_log DROP CONSTRAINT audit_log_entity_check;
|
||||
ALTER TABLE audit_log ADD CONSTRAINT audit_log_entity_check CHECK (
|
||||
entity IN (
|
||||
'person', 'passport', 'address', 'session', 'company', 'visa', 'arrival',
|
||||
'extension', 'reentry-permit', 'report', 'work-permit', 'document', 'form', 'link'
|
||||
)
|
||||
);
|
||||
CREATE INDEX audit_log_actor ON audit_log (actor, id);
|
||||
Reference in new issue
Block a user