summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/node.rb20
-rw-r--r--app/models/node_action.rb1
2 files changed, 21 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.
diff --git a/app/models/node_action.rb b/app/models/node_action.rb
index bfa469b1..f1e4eaea 100644
--- a/app/models/node_action.rb
+++ b/app/models/node_action.rb
@@ -134,6 +134,7 @@ class NodeAction < ApplicationRecord
134 # from the node verbs' "tags", which is a pair, 134 # from the node verbs' "tags", which is a pair,
135 # so one renderer cannot mistake the other. 135 # so one renderer cannot mistake the other.
136 # "path" -- the node's unique_name, when it has a node 136 # "path" -- the node's unique_name, when it has a node
137 # "external_url" -- pair
137 # 138 #
138 # On "event_update" only, and only when something changed -- an 139 # On "event_update" only, and only when something changed -- an
139 # update that changes nothing records no entry at all: 140 # update that changes nothing records no entry at all: