summaryrefslogtreecommitdiff
path: root/app/controllers/shared_previews_controller.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-06 13:52:28 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-06 13:52:28 +0200
commit889e15eabbe107d2642fdd8aa3f03821058c00dc (patch)
tree5016fbf2fd673063c90608ae36406bd350dd34a2 /app/controllers/shared_previews_controller.rb
parent9e63a6bec1b4ccc45dd684f7b6a941b75f9b9cf0 (diff)
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.
Diffstat (limited to 'app/controllers/shared_previews_controller.rb')
-rw-r--r--app/controllers/shared_previews_controller.rb9
1 files changed, 7 insertions, 2 deletions
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 @@
1class SharedPreviewsController < ApplicationController 1class SharedPreviewsController < ApplicationController
2 def show 2 def show
3 @page = Page.find_by!(preview_token: params[:token]) 3 @page = Page.find_by!(preview_token: params[:token])
4 node = @page.node
4 5
5 if @page.node && @page.node.head_id == @page.id 6 was_published = @page.published_at.present?
6 redirect_to node_path(@page.node) 7 superseded = was_published && node && node.head_id != @page.id
8 currently_public = was_published && node && node.head_id == @page.id && @page.public?
9
10 if superseded || currently_public
11 redirect_to node_path(node)
7 return 12 return
8 end 13 end
9 14