Top Menu Removal Crashes Site

Being able to empty the settings field and the app logic relying on at least one value being present is most definitely a bug as it renders the site inaccessible (at least the index, that is)!

I emptied the settings field and upon the next login was greeted with just an HTTP500 error with no clue on how to resolve this. Only after digging through the logs of the Docker container, finding this:

Redirected to https://discourse.example.com/
Completed 302 Found in 18ms (ActiveRecord: 4.6ms)
Started GET "/" for xxx.xxx.xxx.xxx at 2017-01-26 12:39:52 +0000
NoMethodError (undefined method `name' for nil:NilClass)
/var/www/discourse/app/models/site_setting.rb:65:in `homepage'

and reading up on in in the source code on GitHub

def self.top_menu_items
 top_menu.split('|').map { |menu_item| TopMenuItem.new(menu_item) }
end

def self.homepage
  top_menu_items[0].name
end

then I tried to open up the admin panel and was able to set a default value for top_menu_items again.

There needs to be a way to prevent the user from deleting all top_menu_items or a check for an empty setting so that the site keeps being functional.

「いいね!」 2