From 1a037ac6fab34c5f65ed0f37ed603b88e7b02fd1 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sat, 8 Aug 2026 02:46:06 +0200 Subject: Move the external homepage onto the draft --- app/models/node.rb | 22 ++-------------------- app/models/node_action.rb | 6 +++++- app/models/page.rb | 4 ++++ 3 files changed, 11 insertions(+), 21 deletions(-) (limited to 'app/models') diff --git a/app/models/node.rb b/app/models/node.rb index 5c28a786..f5b76b45 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -42,9 +42,6 @@ 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 -- @@ -260,6 +257,8 @@ class Node < ApplicationRecord self.slug = self.head.slug end + self.external_url = self.head.external_url + if self.head.parent_node_id && self.head.parent_node_id != parent_id new_parent = Node.find_by(:id => self.head.parent_node_id) @@ -604,23 +603,6 @@ 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. diff --git a/app/models/node_action.rb b/app/models/node_action.rb index f1e4eaea..1e64861e 100644 --- a/app/models/node_action.rb +++ b/app/models/node_action.rb @@ -35,6 +35,7 @@ class NodeAction < ApplicationRecord # "title" -- pair, always; "from" null on first publish # "author" -- pair, when the byline changed (incl. first publish) # "tags" -- pair of arrays, when changed + # "external_url" -- pair, when a chapter's homepage changed # "assets" -- {"added" => [asset names], "removed" => [asset names]}, # keys only when any; a delta, not a pair. The event IS # the delta, full sets would bloat every entry. Changed @@ -134,7 +135,6 @@ class NodeAction < ApplicationRecord # from the node verbs' "tags", which is a pair, # so one renderer cannot mistake the other. # "path" -- the node's unique_name, when it has a node - # "external_url" -- pair # # On "event_update" only, and only when something changed -- an # update that changes nothing records no entry at all: @@ -199,12 +199,16 @@ class NodeAction < ApplicationRecord "to" => title_of.call(new_page) } } unless old_page diff[:author] = { "from" => nil, "to" => new_page.user&.login } if new_page.user + diff[:external_url] = { "from" => nil, "to" => new_page.external_url } if new_page.external_url.present? return diff end old_author, new_author = old_page.user&.login, new_page.user&.login diff[:author] = { "from" => old_author, "to" => new_author } if old_author != new_author + old_url, new_url = old_page.external_url, new_page.external_url + diff[:external_url] = { "from" => old_url, "to" => new_url } if old_url != new_url + old_tags, new_tags = old_page.tag_list.sort, new_page.tag_list.sort diff[:tags] = { "from" => old_tags, "to" => new_tags } if old_tags != new_tags diff --git a/app/models/page.rb b/app/models/page.rb index bba7e6bc..3240057f 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -20,6 +20,9 @@ class Page < ApplicationRecord :inclusion => { :in => ->(_) { Page.custom_templates } }, :allow_blank => true, :if => :template_name_changed? + validates :external_url, :format => { :with => %r{\Ahttps?://}i, + :allow_blank => true, + :message => :must_be_http } validates_format_of :slug, :with => /\A[A-Za-z0-9][A-Za-z0-9_-]*\z/, :unless => -> { slug.blank? } validate :page_slug_not_reserved @@ -208,6 +211,7 @@ class Page < ApplicationRecord # Clone untranslated attributes self.slug = page.slug self.parent_node_id = page.parent_node_id + self.external_url = page.external_url self.tag_list = page.tag_list self.template_name ||= page.template_name self.published_at = page.published_at -- cgit v1.3