From 889e15eabbe107d2642fdd8aa3f03821058c00dc Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 6 Jul 2026 13:52:28 +0200 Subject: Fix shared preview links breaking after a second publish A token's page could stop being node.head_id (superseded by a newer draft) while still being published_at.present? - the old check only compared against the current head, so a superseded page fell through to direct rendering instead of redirecting, serving a stale frozen snapshot indefinitely instead of the current live content. Also handles scheduled publishing correctly: a page can be head_id but not yet public? (published_at in the future) - that case must still render directly, not redirect into a 404 on the not-yet-live public URL. --- app/controllers/shared_previews_controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app/controllers/shared_previews_controller.rb') diff --git a/app/controllers/shared_previews_controller.rb b/app/controllers/shared_previews_controller.rb index a8a540f..d482466 100644 --- a/app/controllers/shared_previews_controller.rb +++ b/app/controllers/shared_previews_controller.rb @@ -1,9 +1,14 @@ class SharedPreviewsController < ApplicationController def show @page = Page.find_by!(preview_token: params[:token]) + node = @page.node - if @page.node && @page.node.head_id == @page.id - redirect_to node_path(@page.node) + was_published = @page.published_at.present? + superseded = was_published && node && node.head_id != @page.id + currently_public = was_published && node && node.head_id == @page.id && @page.public? + + if superseded || currently_public + redirect_to node_path(node) return end -- cgit v1.3