docbrown/lib/data_update_scripts/20201001173841_add_navigation_links.rb
Ridhwana 19c78d6072
[deploy] Prepare the database for the configurable navigation items (#10662)
* feat: add the order of the navigational items to the database + admin interface

* refactor: rename :display_when_signed_in to :display_only_when_signed_in

* chore: rename all instances of display_when_signed_in to display_only_when_signed_in

* feat: add a data script that will setup the base urls

* feat: add a temporary rake file that will allow us to seed prod db's

* chore: oops rename file

* chore: remove the index for now

* chore: remove validation

* feat: change the order field to position and add an index o the name and url

* feat: update everything that uses order to position

* refactor: order by name as a secondary attr
2020-10-07 11:20:32 -04:00

26 lines
1.7 KiB
Ruby

module DataUpdateScripts
class AddNavigationLinks
PROTOCOL = ApplicationConfig["APP_PROTOCOL"].freeze
DOMAIN = Rails.application&.initialized? ? SiteConfig.app_domain : ApplicationConfig["APP_DOMAIN"]
BASE_URL = "#{PROTOCOL}#{DOMAIN}".freeze
READING_ICON = File.read(Rails.root.join("app/assets/images/twemoji/drawer.svg")).freeze
THUMB_UP_ICON = File.read(Rails.root.join("app/assets/images/twemoji/thumb-up.svg")).freeze
SMART_ICON = File.read(Rails.root.join("app/assets/images/twemoji/smart.svg")).freeze
LOOK_ICON = File.read(Rails.root.join("app/assets/images/twemoji/look.svg")).freeze
CONTACT_ICON = File.read(Rails.root.join("app/assets/images/twemoji/contact.svg")).freeze
def run
NavigationLink.where(name: "Reading List", url: "#{BASE_URL}/readinglist", icon: READING_ICON,
display_only_when_signed_in: true, position: 0).first_or_create
NavigationLink.where(name: "Code of Conduct", url: "#{BASE_URL}/code-of-conduct", icon: THUMB_UP_ICON,
display_only_when_signed_in: false, position: 1).first_or_create
NavigationLink.where(name: "Privacy Policy", url: "#{BASE_URL}/privacy", icon: SMART_ICON,
display_only_when_signed_in: false, position: 2).first_or_create
NavigationLink.where(name: "Terms of use", url: "#{BASE_URL}/terms", icon: LOOK_ICON,
display_only_when_signed_in: false, position: 3).first_or_create
NavigationLink.where(name: "Contact", url: "#{BASE_URL}/contact", icon: CONTACT_ICON,
display_only_when_signed_in: false, position: 4).first_or_create
end
end
end