diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 17:09:45 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 17:09:45 +0200 |
| commit | 40adeec1bcc6fa276d765e3b9c37e781c64a48c1 (patch) | |
| tree | f5fadc4a3edee53b5338b428f0a106036f32d76d /app | |
| parent | aa14587b052a0aa7884aaf27183981975168ab14 (diff) | |
Fix shared preview redirecting to admin for an ordinary new draft
superseded/currently_public used published_at presence as a proxy
for page-row relevance, but published_at is carried forward onto
every new draft descended from previously-published content
(Page#clone_attributes_from, Node#save_draft!) -- so it read true
for any draft on an already-published node, whether or not that
specific draft had ever gone live itself. Compare draft_id/head_id
identity directly instead; no timestamp involved. A stale
(superseded) link now redirects to the live public page rather than
an admin URL an anonymous holder can't reach anyway.
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/shared_previews_controller.rb | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/app/controllers/shared_previews_controller.rb b/app/controllers/shared_previews_controller.rb index d482466..f6fb45a 100644 --- a/app/controllers/shared_previews_controller.rb +++ b/app/controllers/shared_previews_controller.rb | |||
| @@ -3,13 +3,17 @@ class SharedPreviewsController < ApplicationController | |||
| 3 | @page = Page.find_by!(preview_token: params[:token]) | 3 | @page = Page.find_by!(preview_token: params[:token]) |
| 4 | node = @page.node | 4 | node = @page.node |
| 5 | 5 | ||
| 6 | was_published = @page.published_at.present? | 6 | if node |
| 7 | superseded = was_published && node && node.head_id != @page.id | 7 | is_head = node.head_id == @page.id |
| 8 | currently_public = was_published && node && node.head_id == @page.id && @page.public? | 8 | is_draft = node.draft_id == @page.id |
| 9 | 9 | ||
| 10 | if superseded || currently_public | 10 | currently_public = is_head && @page.public? |
| 11 | redirect_to node_path(node) | 11 | superseded = !is_head && !is_draft |
| 12 | return | 12 | |
| 13 | if superseded || currently_public | ||
| 14 | redirect_to @page.public_link | ||
| 15 | return | ||
| 16 | end | ||
| 13 | end | 17 | end |
| 14 | 18 | ||
| 15 | response.headers['X-Robots-Tag'] = 'noindex' | 19 | response.headers['X-Robots-Tag'] = 'noindex' |
