mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:39:43 +08:00
The unified new view change replaced the top menu presence validator and allowed blank values. This let an admin clear the setting, causing homepage resolution to fail because it expects a first menu item. Reject blank top menus again while preserving the unified new validation for the removed unread item.
36 lines
854 B
Ruby
Vendored
36 lines
854 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class TopMenuValidator
|
|
def initialize(opts = {})
|
|
@opts = opts
|
|
end
|
|
|
|
def valid_value?(val)
|
|
@error_message = "site_settings.errors.invalid_string"
|
|
|
|
if val.blank?
|
|
@error_message = "site_settings.errors.must_include_latest"
|
|
return false
|
|
end
|
|
|
|
val_choices = val.split("|").map(&:strip).compact
|
|
|
|
if val_choices.include?("unread") && UpcomingChanges.enabled?(:enable_unified_new)
|
|
@error_message = "site_settings.errors.top_menu_unread_not_allowed_with_unified_new"
|
|
return false
|
|
end
|
|
|
|
return false if !val_choices.all? { |choice| TopMenu.choices.include?(choice) }
|
|
|
|
if !val_choices.include?("latest")
|
|
@error_message = "site_settings.errors.must_include_latest"
|
|
return false
|
|
end
|
|
|
|
true
|
|
end
|
|
|
|
def error_message
|
|
I18n.t(@error_message)
|
|
end
|
|
end
|