From 5644fffbc3c58e6dd7e3c4103c28bad8f4c0bbc6 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Thu, 6 Aug 2026 13:30:38 +0200 Subject: Let editors set a node external homepage, gated and witnessed --- app/models/node.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'app/models/node.rb') diff --git a/app/models/node.rb b/app/models/node.rb index f8c29b48..4b7c9772 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -42,6 +42,9 @@ class Node < ApplicationRecord :inclusion => { :in => ->(_) { Page.custom_templates } }, :allow_blank => true, :if => :default_template_name_changed? + validates :external_url, :format => { :with => %r{\Ahttps?://}i, + :allow_blank => true, + :message => :must_be_http } # Everything outside the Trash subtree, the Trash node included. # Relies on unique_name being authoritative for tree position -- @@ -605,6 +608,23 @@ class Node < ApplicationRecord self.created_at < new_id_format_date ? unique_path : id end + def update_external_url!(url, current_user = nil) + normalised = url.presence + return false if normalised == external_url + + guard_live_change!(current_user) + previous = external_url + + transaction do + update!(:external_url => normalised) + NodeAction.record!(:node => self, :user => current_user, + :action => "node_external_url", + :path => unique_name, + :external_url => { "from" => previous, "to" => normalised }) + end + true + end + # Full-text search across all locale translations using PostgreSQL tsvector. # Uses 'simple' dictionary (no stemming, no stopwords) so queries work # across German and English content without language detection. -- cgit v1.3