Skip to content

Commit 2b813db

Browse files
authored
allow slug for draft l10ns in slugs_with_ancestor_slugs (#3916)
1 parent a2d5703 commit 2b813db

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

app/models/communication/website/permalink.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Communication::Website::Permalink < ApplicationRecord
3838

3939
validates :path, presence: true
4040
validates :path, uniqueness: { scope: :website_id }, unless: :is_current
41+
# TODO: validate :root_path_is_reserved_for_home
4142

4243
before_validation :set_university, on: :create
4344
# We should not sync the about object whenever we do something with the permalink, as they can be changed during a sync.
@@ -187,4 +188,9 @@ def regenerate_website_hosting_config
187188
return unless website.persisted?
188189
website.regenerate_hosting_config!
189190
end
191+
192+
def root_path_is_reserved_for_home
193+
return unless path == "/"
194+
errors.add(:path, :reserved_for_home) unless about.about.is_a?(Communication::Website::Page::Home)
195+
end
190196
end

app/models/concerns/as_localization.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ def localize_in!(language)
6767
def slug_with_ancestors_slugs
6868
about.ancestors_and_self.map { |ancestor|
6969
l10n = ancestor.localization_for(language)
70-
if l10n.nil? || l10n.try(:draft?)
71-
# If l10n is nil or draft, no slug
72-
nil
73-
else
74-
# otherwise (published or no publication state) we return the slug
75-
l10n.slug
76-
end
70+
# If l10n is nil, no slug
71+
# otherwise (published or not) we return the slug
72+
l10n.try(:slug)
7773
}.compact_blank.join('/')
7874
end
7975

config/locales/communication/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ en:
361361
path:
362362
blank: must be correct, as defined by RFC2396
363363
not_unique: already used by another alias
364+
reserved_for_home: is reserved for the home page
364365
models:
365366
communication/block:
366367
one: Content block

config/locales/communication/fr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ fr:
360360
path:
361361
blank: doit être un chemin correct, comme défini par la RFC2396
362362
not_unique: déjà utilisé par un autre alias
363+
reserved_for_home: est réservé pour la page d'accueil
363364
models:
364365
communication/block:
365366
one: Bloc de contenu

0 commit comments

Comments
 (0)