diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-07 06:15:14 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-07 06:15:14 +0200 |
| commit | f4ddfff03ca9f25d50f39a1971877362d85eb9cb (patch) | |
| tree | 31e6774fd4cf2b579a9622277be150417a2fa48e /app/models/page.rb | |
| parent | 02a4ea750428aa1a9c9e7f2680553c0ce4ef1fec (diff) | |
Move the pending address from the node onto the draft
Diffstat (limited to 'app/models/page.rb')
| -rw-r--r-- | app/models/page.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/page.rb b/app/models/page.rb index 8313b1d4..4635f1b4 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -20,9 +20,13 @@ 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_format_of :slug, :with => /\A[A-Za-z0-9][A-Za-z0-9_-]*\z/, | ||
| 24 | :unless => -> { slug.blank? } | ||
| 25 | validate :page_slug_not_reserved | ||
| 23 | 26 | ||
| 24 | # Associations | 27 | # Associations |
| 25 | belongs_to :node, optional: true | 28 | belongs_to :node, optional: true |
| 29 | belongs_to :parent_node, :class_name => "Node", :optional => true | ||
| 26 | belongs_to :user, optional: true | 30 | belongs_to :user, optional: true |
| 27 | belongs_to :editor, :class_name => "User", optional: true | 31 | belongs_to :editor, :class_name => "User", optional: true |
| 28 | has_many :related_assets, :dependent => :destroy | 32 | has_many :related_assets, :dependent => :destroy |
| @@ -202,6 +206,8 @@ class Page < ApplicationRecord | |||
| 202 | page.translations.reload | 206 | page.translations.reload |
| 203 | 207 | ||
| 204 | # Clone untranslated attributes | 208 | # Clone untranslated attributes |
| 209 | self.slug = page.slug | ||
| 210 | self.parent_node_id = page.parent_node_id | ||
| 205 | self.tag_list = page.tag_list | 211 | self.tag_list = page.tag_list |
| 206 | self.template_name ||= page.template_name | 212 | self.template_name ||= page.template_name |
| 207 | self.published_at = page.published_at | 213 | self.published_at = page.published_at |
| @@ -292,6 +298,20 @@ class Page < ApplicationRecord | |||
| 292 | published_at.nil? ? true : published_at < Time.now | 298 | published_at.nil? ? true : published_at < Time.now |
| 293 | end | 299 | end |
| 294 | 300 | ||
| 301 | # The address this page will have once published. | ||
| 302 | def prospective_unique_name | ||
| 303 | return nil if parent_node_id.nil? | ||
| 304 | |||
| 305 | parent = Node.find_by(:id => parent_node_id) | ||
| 306 | return nil unless parent | ||
| 307 | |||
| 308 | [parent.unique_name.presence, slug].compact.join("/") | ||
| 309 | end | ||
| 310 | |||
| 311 | def parent_node_missing? | ||
| 312 | parent_node_id.present? && !Node.exists?(:id => parent_node_id) | ||
| 313 | end | ||
| 314 | |||
| 295 | def effective_lang | 315 | def effective_lang |
| 296 | if translated_locales.empty? | 316 | if translated_locales.empty? |
| 297 | return 'de' | 317 | return 'de' |
| @@ -333,6 +353,14 @@ class Page < ApplicationRecord | |||
| 333 | end | 353 | end |
| 334 | end | 354 | end |
| 335 | 355 | ||
| 356 | def page_slug_not_reserved | ||
| 357 | return unless slug == CccConventions::TRASH_SLUG | ||
| 358 | return if node&.trash_node? | ||
| 359 | return unless parent_node_id && Node.find_by(:id => parent_node_id)&.root? | ||
| 360 | |||
| 361 | errors.add(:slug, :reserved_for_trash) | ||
| 362 | end | ||
| 363 | |||
| 336 | # Installs (or re-installs) the trigger that keeps page_translations' | 364 | # Installs (or re-installs) the trigger that keeps page_translations' |
| 337 | # search_vector in sync. Idempotent, safe to call on every boot. | 365 | # search_vector in sync. Idempotent, safe to call on every boot. |
| 338 | # search_vector is populated by a raw Postgres trigger, not anything | 366 | # search_vector is populated by a raw Postgres trigger, not anything |
