diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-08 02:46:06 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-08 02:46:06 +0200 |
| commit | 1a037ac6fab34c5f65ed0f37ed603b88e7b02fd1 (patch) | |
| tree | 48af0eab79ea64c9ca92833d415483773e665305 /app/models | |
| parent | 5699572861085bfb0b375f44e2f35ee8eee3f8c6 (diff) | |
Move the external homepage onto the draft
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/node.rb | 22 | ||||
| -rw-r--r-- | app/models/node_action.rb | 6 | ||||
| -rw-r--r-- | app/models/page.rb | 4 |
3 files changed, 11 insertions, 21 deletions
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 | |||
| 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 } | ||
| 48 | 45 | ||
| 49 | # Everything outside the Trash subtree, the Trash node included. | 46 | # Everything outside the Trash subtree, the Trash node included. |
| 50 | # Relies on unique_name being authoritative for tree position -- | 47 | # Relies on unique_name being authoritative for tree position -- |
| @@ -260,6 +257,8 @@ class Node < ApplicationRecord | |||
| 260 | self.slug = self.head.slug | 257 | self.slug = self.head.slug |
| 261 | end | 258 | end |
| 262 | 259 | ||
| 260 | self.external_url = self.head.external_url | ||
| 261 | |||
| 263 | if self.head.parent_node_id && self.head.parent_node_id != parent_id | 262 | if self.head.parent_node_id && self.head.parent_node_id != parent_id |
| 264 | new_parent = Node.find_by(:id => self.head.parent_node_id) | 263 | new_parent = Node.find_by(:id => self.head.parent_node_id) |
| 265 | 264 | ||
| @@ -604,23 +603,6 @@ class Node < ApplicationRecord | |||
| 604 | self.created_at < new_id_format_date ? unique_path : id | 603 | self.created_at < new_id_format_date ? unique_path : id |
| 605 | end | 604 | end |
| 606 | 605 | ||
| 607 | def update_external_url!(url, current_user = nil) | ||
| 608 | normalised = url.presence | ||
| 609 | return false if normalised == external_url | ||
| 610 | |||
| 611 | guard_live_change!(current_user) | ||
| 612 | previous = external_url | ||
| 613 | |||
| 614 | transaction do | ||
| 615 | update!(:external_url => normalised) | ||
| 616 | NodeAction.record!(:node => self, :user => current_user, | ||
| 617 | :action => "node_external_url", | ||
| 618 | :path => unique_name, | ||
| 619 | :external_url => { "from" => previous, "to" => normalised }) | ||
| 620 | end | ||
| 621 | true | ||
| 622 | end | ||
| 623 | |||
| 624 | # Full-text search across all locale translations using PostgreSQL tsvector. | 606 | # Full-text search across all locale translations using PostgreSQL tsvector. |
| 625 | # Uses 'simple' dictionary (no stemming, no stopwords) so queries work | 607 | # Uses 'simple' dictionary (no stemming, no stopwords) so queries work |
| 626 | # across German and English content without language detection. | 608 | # 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 | |||
| 35 | # "title" -- pair, always; "from" null on first publish | 35 | # "title" -- pair, always; "from" null on first publish |
| 36 | # "author" -- pair, when the byline changed (incl. first publish) | 36 | # "author" -- pair, when the byline changed (incl. first publish) |
| 37 | # "tags" -- pair of arrays, when changed | 37 | # "tags" -- pair of arrays, when changed |
| 38 | # "external_url" -- pair, when a chapter's homepage changed | ||
| 38 | # "assets" -- {"added" => [asset names], "removed" => [asset names]}, | 39 | # "assets" -- {"added" => [asset names], "removed" => [asset names]}, |
| 39 | # keys only when any; a delta, not a pair. The event IS | 40 | # keys only when any; a delta, not a pair. The event IS |
| 40 | # the delta, full sets would bloat every entry. Changed | 41 | # the delta, full sets would bloat every entry. Changed |
| @@ -134,7 +135,6 @@ class NodeAction < ApplicationRecord | |||
| 134 | # from the node verbs' "tags", which is a pair, | 135 | # from the node verbs' "tags", which is a pair, |
| 135 | # so one renderer cannot mistake the other. | 136 | # so one renderer cannot mistake the other. |
| 136 | # "path" -- the node's unique_name, when it has a node | 137 | # "path" -- the node's unique_name, when it has a node |
| 137 | # "external_url" -- pair | ||
| 138 | # | 138 | # |
| 139 | # On "event_update" only, and only when something changed -- an | 139 | # On "event_update" only, and only when something changed -- an |
| 140 | # update that changes nothing records no entry at all: | 140 | # update that changes nothing records no entry at all: |
| @@ -199,12 +199,16 @@ class NodeAction < ApplicationRecord | |||
| 199 | "to" => title_of.call(new_page) } } | 199 | "to" => title_of.call(new_page) } } |
| 200 | unless old_page | 200 | unless old_page |
| 201 | diff[:author] = { "from" => nil, "to" => new_page.user&.login } if new_page.user | 201 | diff[:author] = { "from" => nil, "to" => new_page.user&.login } if new_page.user |
| 202 | diff[:external_url] = { "from" => nil, "to" => new_page.external_url } if new_page.external_url.present? | ||
| 202 | return diff | 203 | return diff |
| 203 | end | 204 | end |
| 204 | 205 | ||
| 205 | old_author, new_author = old_page.user&.login, new_page.user&.login | 206 | old_author, new_author = old_page.user&.login, new_page.user&.login |
| 206 | diff[:author] = { "from" => old_author, "to" => new_author } if old_author != new_author | 207 | diff[:author] = { "from" => old_author, "to" => new_author } if old_author != new_author |
| 207 | 208 | ||
| 209 | old_url, new_url = old_page.external_url, new_page.external_url | ||
| 210 | diff[:external_url] = { "from" => old_url, "to" => new_url } if old_url != new_url | ||
| 211 | |||
| 208 | old_tags, new_tags = old_page.tag_list.sort, new_page.tag_list.sort | 212 | old_tags, new_tags = old_page.tag_list.sort, new_page.tag_list.sort |
| 209 | diff[:tags] = { "from" => old_tags, "to" => new_tags } if old_tags != new_tags | 213 | diff[:tags] = { "from" => old_tags, "to" => new_tags } if old_tags != new_tags |
| 210 | 214 | ||
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 | |||
| 20 | :inclusion => { :in => ->(_) { Page.custom_templates } }, | 20 | :inclusion => { :in => ->(_) { Page.custom_templates } }, |
| 21 | :allow_blank => true, | 21 | :allow_blank => true, |
| 22 | :if => :template_name_changed? | 22 | :if => :template_name_changed? |
| 23 | validates :external_url, :format => { :with => %r{\Ahttps?://}i, | ||
| 24 | :allow_blank => true, | ||
| 25 | :message => :must_be_http } | ||
| 23 | validates_format_of :slug, :with => /\A[A-Za-z0-9][A-Za-z0-9_-]*\z/, | 26 | validates_format_of :slug, :with => /\A[A-Za-z0-9][A-Za-z0-9_-]*\z/, |
| 24 | :unless => -> { slug.blank? } | 27 | :unless => -> { slug.blank? } |
| 25 | validate :page_slug_not_reserved | 28 | validate :page_slug_not_reserved |
| @@ -208,6 +211,7 @@ class Page < ApplicationRecord | |||
| 208 | # Clone untranslated attributes | 211 | # Clone untranslated attributes |
| 209 | self.slug = page.slug | 212 | self.slug = page.slug |
| 210 | self.parent_node_id = page.parent_node_id | 213 | self.parent_node_id = page.parent_node_id |
| 214 | self.external_url = page.external_url | ||
| 211 | self.tag_list = page.tag_list | 215 | self.tag_list = page.tag_list |
| 212 | self.template_name ||= page.template_name | 216 | self.template_name ||= page.template_name |
| 213 | self.published_at = page.published_at | 217 | self.published_at = page.published_at |
