summaryrefslogtreecommitdiff
path: root/app/models/node.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-08-06 13:30:38 +0200
committererdgeist <erdgeist@erdgeist.org>2026-08-06 13:30:38 +0200
commit5644fffbc3c58e6dd7e3c4103c28bad8f4c0bbc6 (patch)
treebc58310f60ac37c5d6927177d5d09a28a05a2b3b /app/models/node.rb
parent2da0ce9f3c4bdbe12a80a0d28e964e9658c53f31 (diff)
Let editors set a node external homepage, gated and witnessed
Diffstat (limited to 'app/models/node.rb')
-rw-r--r--app/models/node.rb20
1 files changed, 20 insertions, 0 deletions
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
42 :inclusion => { :in => ->(_) { Page.custom_templates } }, 42 :inclusion => { :in => ->(_) { Page.custom_templates } },
43 :allow_blank => true, 43 :allow_blank => true,
44 :if => :default_template_name_changed? 44 :if => :default_template_name_changed?
45 validates :external_url, :format => { :with => %r{\Ahttps?://}i,
46 :allow_blank => true,
47 :message => :must_be_http }
45 48
46 # Everything outside the Trash subtree, the Trash node included. 49 # Everything outside the Trash subtree, the Trash node included.
47 # Relies on unique_name being authoritative for tree position -- 50 # Relies on unique_name being authoritative for tree position --
@@ -605,6 +608,23 @@ class Node < ApplicationRecord
605 self.created_at < new_id_format_date ? unique_path : id 608 self.created_at < new_id_format_date ? unique_path : id
606 end 609 end
607 610
611 def update_external_url!(url, current_user = nil)
612 normalised = url.presence
613 return false if normalised == external_url
614
615 guard_live_change!(current_user)
616 previous = external_url
617
618 transaction do
619 update!(:external_url => normalised)
620 NodeAction.record!(:node => self, :user => current_user,
621 :action => "node_external_url",
622 :path => unique_name,
623 :external_url => { "from" => previous, "to" => normalised })
624 end
625 true
626 end
627
608 # Full-text search across all locale translations using PostgreSQL tsvector. 628 # Full-text search across all locale translations using PostgreSQL tsvector.
609 # Uses 'simple' dictionary (no stemming, no stopwords) so queries work 629 # Uses 'simple' dictionary (no stemming, no stopwords) so queries work
610 # across German and English content without language detection. 630 # across German and English content without language detection.