Skip to content

[WHIT-3020] Make preview token generation opt-in#11542

Open
TonyGDS wants to merge 1 commit into
whit-3020-deletable-preview-tokensfrom
whit-3020-opt-in-preview-tokens
Open

[WHIT-3020] Make preview token generation opt-in#11542
TonyGDS wants to merge 1 commit into
whit-3020-deletable-preview-tokensfrom
whit-3020-opt-in-preview-tokens

Conversation

@TonyGDS

@TonyGDS TonyGDS commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Part 3 of 3 for WHIT-3020. Stacked on #11543

Jira

What

Makes preview-token generation opt-in. Previously every draft edition was auto-assigned a JWT auth-bypass token on creation, and the draft Content Store evaluates that token before access limits — granting access and skipping the allow-list if a token is present — so a document locked to named users was still viewable by anyone holding the share link. This removes the auto-generation, so a draft has no token until a publisher generates one (the generate/delete UI landed in #11543).

How

  • Remove the before_create :set_auth_bypass_id callback on Edition — a new draft no longer gets a token, and none is sent to the Publishing API.
  • Exclude auth_bypass_id from the attributes Edition#create_draft copies, so redrafting a published document no longer carries its token forward — the new draft starts token-less.
  • Move the factory's auth_bypass_id into a :with_auth_bypass_id trait so test editions match production (no token by default), applying it only where a token must be present.
  • Update the affected tests for the token-less default (presenter payloads assert an empty auth_bypass_ids array; dedicated presence tests cover the token case).

Acceptance criteria

Screenshots

Before — a brand-new draft auto-shows a generated preview link

Screenshot 2026-06-10 at 11 50 35

After — a brand-new draft shows the empty state

Screenshot 2026-06-09 at 16 23 36

Test plan

Run against integration with two sessions: a signed-in publisher and a signed-out browser (incognito) for the preview links. "403" below means the signed-out browser is refused.

A. Token lifecycle (once, on a Publication — representative of all types)

  1. Create a new draft → the share section shows only "Generate link" (no link, no Copy/Delete). (opt-in default)
  2. Click Generate link → a copy box with a preview link appears, plus Generate new link and Delete link.
  3. Open the link signed-out → the draft renders. (token grants preview)
  4. Click Generate new link, copy the new link. Old link signed-out → 403; new link → renders. (regenerate supersedes)
  5. Click Delete link → back to the empty state. Previous link signed-out → 403. (delete revokes)

B. Document-type coverage (section renders + generate/delete behave as in A)

  • Publication
  • Speech
  • Consultation
  • Call for evidence
  • Detailed guide
  • Document collection
  • Fatality notice
  • Statistical data set
  • Corporate information page
  • Plan for change page
  • Standard edition
  • Worldwide organisation

C. Access limiting

  1. Create an access-limited draft (limited to an org you are not in) with no token → a user outside the org / signed-out cannot preview it.
  2. Generate a token, then delete it → the old link 403s and access limiting is back in force.

D. Asset propagation (upload to a draft with a token, then delete the token and re-check signed-out)

  • File attachment — gated (draft: true): with a token, signed-out can fetch the asset; after delete → 403. (token enforced)
  • HTML attachment — inherits the edition's token: with a token renders the attachment; after delete → 403.
  • Consultation / call-for-evidence response form — live asset (draft: false): confirm the token (or []) is sent to Asset Manager, but see the limitation below.
  • Edition image (Images tab) — live asset (draft: false): as above.
  • Featured image / organisation logo — default storage, no token applied (always live).

⚠️ Known limitation (WHIT-3580): edition images and response documents are stored as live assets (draft: false), so the preview token is sent but not enforced — they stay reachable signed-out regardless of the token. Verify the payloads carry the right auth_bypass_ids, but do not expect a 403 on these until the live-asset ticket is fixed.

E. Other checks

  • After regenerate/delete, confirm the Publishing API draft and Asset Manager assets carry the updated auth_bypass_ids ([token] or []).
  • Redraft a published document that had a preview link → the new draft starts in the empty state (no token, no copyable link).

Follow-ups (separate tickets/stories)

  • Images & response documents are stored as live assets even for draft editions, so the preview token doesn't gate them (WHIT-3580).
  • Drop auth_bypass_ids on publish — Currently if an edition has an auth_bypass_id it is propagated when the Edition is published. Once published the auth_bypass_id has no effect on the display of the content. Therefore auth_bypass_id should be removed from the edition and downstream services when the edition is published. (WHIT-3585)

@TonyGDS TonyGDS changed the title [WHIT-3020] Make shareable preview tokens opt-in [WHIT-3020] Make preview token generation opt-in Jun 9, 2026
@TonyGDS TonyGDS changed the base branch from main to whit-3020-deletable-preview-tokens June 9, 2026 13:25
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from 5aba05f to 176854d Compare June 9, 2026 13:48
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from 1951e36 to e81735c Compare June 9, 2026 13:48
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from 176854d to 7b71ef9 Compare June 9, 2026 13:59
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from e81735c to eadfa72 Compare June 9, 2026 13:59
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from 7b71ef9 to dc3e859 Compare June 9, 2026 15:16
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch 4 times, most recently from 63bdfd2 to 8d87f89 Compare June 9, 2026 15:46
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from dc3e859 to c2e1e13 Compare June 9, 2026 16:35
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch 2 times, most recently from 5e9c977 to b484ac4 Compare June 10, 2026 08:51
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from c2e1e13 to 9163764 Compare June 10, 2026 09:51
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from b484ac4 to 6762146 Compare June 10, 2026 09:56
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from 9163764 to f642e3e Compare June 10, 2026 10:18
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from 6762146 to 8da762a Compare June 10, 2026 10:18
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from f642e3e to d35f18e Compare June 10, 2026 10:42
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from 8da762a to ba50c8f Compare June 10, 2026 10:42
@TonyGDS TonyGDS marked this pull request as ready for review June 10, 2026 12:01
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from d35f18e to 719aeea Compare June 10, 2026 15:08
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch 4 times, most recently from 7491e19 to e6b1009 Compare June 11, 2026 17:09
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch 2 times, most recently from 92202fe to 381379d Compare June 12, 2026 13:34
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from e6b1009 to f7bdde1 Compare June 12, 2026 13:34
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from 381379d to b25327c Compare June 12, 2026 13:38
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from f7bdde1 to d6c67cb Compare June 12, 2026 13:38
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from b25327c to 729c9eb Compare June 12, 2026 15:08
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from d6c67cb to 06ac55d Compare June 12, 2026 15:08
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from 729c9eb to 30f8365 Compare June 12, 2026 15:18
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from 06ac55d to e90b442 Compare June 12, 2026 15:18
Remove the before_create callback that assigned every edition an
auth_bypass_id, making preview token generation opt-in: a draft has no
token until a publisher generates one. Redrafting no longer carries the
previous edition's token forward either — auth_bypass_id is excluded
from the attributes create_draft copies — so a new draft also starts
token-less.

Editions now have no token by default: the factory carries a
:with_auth_bypass_id trait for the cases that still need one, and the
tests assert the empty-token default (presenter payloads serialise an
empty auth_bypass_ids array).
@TonyGDS TonyGDS force-pushed the whit-3020-deletable-preview-tokens branch from 30f8365 to 192753b Compare June 12, 2026 15:48
@TonyGDS TonyGDS force-pushed the whit-3020-opt-in-preview-tokens branch from e90b442 to 0dd17f3 Compare June 12, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant