diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-20 17:37:01 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-20 17:37:01 +0200 |
| commit | a1794d3087e6cbd228f3641e7313815d8c59695f (patch) | |
| tree | 85a9ac0c50faf47a33be57af818942b692530ffc /app/models/page.rb | |
| parent | 3e77e5fca9f66f5be9c12085fd68c4e9d0ba79be (diff) | |
Surface redirects in nodes#show, the action log and when publishing
Diffstat (limited to 'app/models/page.rb')
| -rw-r--r-- | app/models/page.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/app/models/page.rb b/app/models/page.rb index 5d3cb0aa..91b7e975 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -36,6 +36,7 @@ class Page < ApplicationRecord | |||
| 36 | belongs_to :parent_node, :class_name => "Node", :optional => true | 36 | belongs_to :parent_node, :class_name => "Node", :optional => true |
| 37 | belongs_to :user, optional: true | 37 | belongs_to :user, optional: true |
| 38 | belongs_to :editor, :class_name => "User", optional: true | 38 | belongs_to :editor, :class_name => "User", optional: true |
| 39 | belongs_to :redirect_node, :class_name => "Node", :optional => true | ||
| 39 | has_many :related_assets, :dependent => :destroy | 40 | has_many :related_assets, :dependent => :destroy |
| 40 | has_many :assets, -> { order("position ASC") }, :through => :related_assets | 41 | has_many :assets, -> { order("position ASC") }, :through => :related_assets |
| 41 | 42 | ||
| @@ -289,7 +290,11 @@ class Page < ApplicationRecord | |||
| 289 | changed: user_id != other.user_id }, | 290 | changed: user_id != other.user_id }, |
| 290 | tags: { added: tag_list.to_a - other.tag_list.to_a, removed: other.tag_list.to_a - tag_list.to_a }, | 291 | tags: { added: tag_list.to_a - other.tag_list.to_a, removed: other.tag_list.to_a - tag_list.to_a }, |
| 291 | template_name: { from: other.template_name, to: template_name, changed: template_name != other.template_name }, | 292 | template_name: { from: other.template_name, to: template_name, changed: template_name != other.template_name }, |
| 292 | assets: { added: assets.to_a - other.assets.to_a, removed: other.assets.to_a - assets.to_a } | 293 | assets: { added: assets.to_a - other.assets.to_a, removed: other.assets.to_a - assets.to_a }, |
| 294 | redirect: { from: other.redirect, to: redirect, | ||
| 295 | changed: redirect != other.redirect }, | ||
| 296 | redirect_node: { from: other.redirect_node, to: redirect_node, | ||
| 297 | changed: redirect_node_id != other.redirect_node_id } | ||
| 293 | ) | 298 | ) |
| 294 | end | 299 | end |
| 295 | 300 | ||
| @@ -326,9 +331,8 @@ class Page < ApplicationRecord | |||
| 326 | return nil if redirect.blank? | 331 | return nil if redirect.blank? |
| 327 | 332 | ||
| 328 | if redirect_node_id.present? | 333 | if redirect_node_id.present? |
| 329 | target = Node.find_by(:id => redirect_node_id) | 334 | return nil unless redirect_node&.head |
| 330 | return nil unless target&.head | 335 | return RedirectTarget.new(redirect_node, nil) |
| 331 | return RedirectTarget.new(target, nil) | ||
| 332 | end | 336 | end |
| 333 | 337 | ||
| 334 | return RedirectTarget.new(nil, external_url) if external_url.present? | 338 | return RedirectTarget.new(nil, external_url) if external_url.present? |
| @@ -345,6 +349,11 @@ class Page < ApplicationRecord | |||
| 345 | Node.where(:head_id => where(:redirect_node_id => node_id).select(:id)) | 349 | Node.where(:head_id => where(:redirect_node_id => node_id).select(:id)) |
| 346 | end | 350 | end |
| 347 | 351 | ||
| 352 | def redirect_differs_from? other | ||
| 353 | mine, theirs = redirect_target, other&.redirect_target | ||
| 354 | mine&.url != theirs&.url || mine&.node != theirs&.node | ||
| 355 | end | ||
| 356 | |||
| 348 | # The address this page will have once published. | 357 | # The address this page will have once published. |
| 349 | def prospective_unique_name | 358 | def prospective_unique_name |
| 350 | return nil if parent_node_id.nil? | 359 | return nil if parent_node_id.nil? |
