diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 06:09:21 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 06:09:21 +0200 |
| commit | 9e63a6bec1b4ccc45dd684f7b6a941b75f9b9cf0 (patch) | |
| tree | 8c7842b3703ad2224deace37f9bd48df3374349b /app/controllers/shared_previews_controller.rb | |
| parent | b547decd1f85b43d5fb9e86cd7462b455059b1d1 (diff) | |
Add public preview links for drafts
Lets editors share a draft with people outside the admin system, via a
random per-page token rather than an enumerable id - /preview/<token>.
shared_previews#show is intentionally unauthenticated. Redirects to the
real public URL once the page is published. Surfaced on nodes#show
(Admin Preview + Public Preview, next to Public Link) as generate/revoke
buttons.
Diffstat (limited to 'app/controllers/shared_previews_controller.rb')
| -rw-r--r-- | app/controllers/shared_previews_controller.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/controllers/shared_previews_controller.rb b/app/controllers/shared_previews_controller.rb new file mode 100644 index 0000000..a8a540f --- /dev/null +++ b/app/controllers/shared_previews_controller.rb | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | class SharedPreviewsController < ApplicationController | ||
| 2 | def show | ||
| 3 | @page = Page.find_by!(preview_token: params[:token]) | ||
| 4 | |||
| 5 | if @page.node && @page.node.head_id == @page.id | ||
| 6 | redirect_to node_path(@page.node) | ||
| 7 | return | ||
| 8 | end | ||
| 9 | |||
| 10 | response.headers['X-Robots-Tag'] = 'noindex' | ||
| 11 | render template: @page.valid_template, layout: "application" | ||
| 12 | end | ||
| 13 | end | ||
