diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 1e0cc646ed83c7b29d4171b56d700aa9bbf04a7d..fd2e655c6bf4f43d00358009e22c9fe847c56833 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -92,7 +92,7 @@ class Communication::Website::Page < ApplicationRecord git_block_dependencies + type_git_dependencies dependencies += [parent] if has_parent? - dependencies.flatten + dependencies.flatten.compact end def git_destroy_dependencies(website) diff --git a/app/models/communication/website/page/administrator.rb b/app/models/communication/website/page/administrator.rb index 90e37781efe8f33afd6858ff351bcb457ef83d09..8a63c70da1726381c9e5a4c6d12e30a232d12a0b 100644 --- a/app/models/communication/website/page/administrator.rb +++ b/app/models/communication/website/page/administrator.rb @@ -48,7 +48,7 @@ class Communication::Website::Page::Administrator < Communication::Website::Page def type_git_dependencies [ website.config_default_permalinks, - website.website.administrators.map(&:administrator) + website&.administrators&.map(&:administrator) ] end end diff --git a/app/models/communication/website/page/author.rb b/app/models/communication/website/page/author.rb index 10e663553134a9de887aafbf42a7ea72616d5adc..5e7cda9b79ae6ada45eee93ebb90a02819efb110 100644 --- a/app/models/communication/website/page/author.rb +++ b/app/models/communication/website/page/author.rb @@ -48,7 +48,7 @@ class Communication::Website::Page::Author < Communication::Website::Page def type_git_dependencies [ website.config_default_permalinks, - website.website.authors.map(&:author) + website&.authors&.map(&:author) ] end end diff --git a/app/models/communication/website/page/education_diploma.rb b/app/models/communication/website/page/education_diploma.rb index cec9c8b2a7067a975bd0168ee1851301d4106a4d..b864ec7c549337edfc9dc23814567c6b3c1f9eda 100644 --- a/app/models/communication/website/page/education_diploma.rb +++ b/app/models/communication/website/page/education_diploma.rb @@ -41,6 +41,10 @@ # class Communication::Website::Page::EducationDiploma < Communication::Website::Page + def is_necessary_for_website? + website.about && website.about&.respond_to(:education_diplomas) + end + def full_width true end diff --git a/app/models/communication/website/page/education_program.rb b/app/models/communication/website/page/education_program.rb index 87e0bb52ced13dd054dcb49c0ddfe52854560222..1f9334d375839283c04fce42fd4f4f73b5e359b4 100644 --- a/app/models/communication/website/page/education_program.rb +++ b/app/models/communication/website/page/education_program.rb @@ -41,6 +41,10 @@ # class Communication::Website::Page::EducationProgram < Communication::Website::Page + def is_necessary_for_website? + website.about && website.about&.respond_to(:education_programs) + end + def full_width true end diff --git a/app/models/communication/website/page/research_paper.rb b/app/models/communication/website/page/research_paper.rb index 5e1669fdb4db19854599764c6dfca46ca2a3d000..1497d4cfa46814006a31e2a59be77284205f6242 100644 --- a/app/models/communication/website/page/research_paper.rb +++ b/app/models/communication/website/page/research_paper.rb @@ -41,6 +41,10 @@ # class Communication::Website::Page::ResearchPaper < Communication::Website::Page + def is_necessary_for_website? + website.about && website.about&.respond_to(:research_papers) + end + def current_git_path "#{git_path_prefix}papers/_index.html" end diff --git a/app/models/communication/website/page/research_volume.rb b/app/models/communication/website/page/research_volume.rb index 11d4d39a5488347822710654c91e5e4446fa19d4..3aca8617bd8cf3c76eefdb0689e5de56998de9d3 100644 --- a/app/models/communication/website/page/research_volume.rb +++ b/app/models/communication/website/page/research_volume.rb @@ -41,6 +41,10 @@ # class Communication::Website::Page::ResearchVolume < Communication::Website::Page + def is_necessary_for_website? + website.about && website.about&.respond_to(:research_volumes) + end + def current_git_path "#{git_path_prefix}volumes/_index.html" end diff --git a/app/models/communication/website/page/researcher.rb b/app/models/communication/website/page/researcher.rb index b3e33978429a9a3e341bfb05ec5a5e6f45a28b05..b098fb254868b6413c48224b4c4102f722fd3403 100644 --- a/app/models/communication/website/page/researcher.rb +++ b/app/models/communication/website/page/researcher.rb @@ -48,7 +48,7 @@ class Communication::Website::Page::Researcher < Communication::Website::Page def type_git_dependencies [ website.config_default_permalinks, - website.website.researchers.map(&:researcher) + website&.researchers&.map(&:researcher) ] end end diff --git a/app/models/communication/website/page/teacher.rb b/app/models/communication/website/page/teacher.rb index 20541510407c4d33fc533c1d10df035de3033122..f3ca0a2f4fdff4d6963e4353bda24cbef250bd98 100644 --- a/app/models/communication/website/page/teacher.rb +++ b/app/models/communication/website/page/teacher.rb @@ -48,7 +48,7 @@ class Communication::Website::Page::Teacher < Communication::Website::Page def type_git_dependencies [ website.config_default_permalinks, - website.website.teachers.map(&:teacher) + website&.teachers&.map(&:teacher) ].flatten end end diff --git a/app/models/communication/website/page/with_type.rb b/app/models/communication/website/page/with_type.rb index 27f32f5121d92b89f713835e900433387fd2198c..a2ef3eaee71f906b8c7b34cc71f25b0b63e26bef 100644 --- a/app/models/communication/website/page/with_type.rb +++ b/app/models/communication/website/page/with_type.rb @@ -3,7 +3,26 @@ module Communication::Website::Page::WithType included do - HOME_TYPE = '::Communication::Website::Page::Home' + HOME_TYPE = 'Communication::Website::Page::Home' + + TYPES = [ + Communication::Website::Page::Home, # Always start with home + Communication::Website::Page::Accessibility, + Communication::Website::Page::Administrator, + Communication::Website::Page::Author, + Communication::Website::Page::CommunicationPost, + Communication::Website::Page::EducationDiploma, + Communication::Website::Page::EducationProgram, + Communication::Website::Page::LegalTerm, + Communication::Website::Page::Organization, + Communication::Website::Page::Person, + Communication::Website::Page::PrivacyPolicy, + Communication::Website::Page::ResearchPaper, + Communication::Website::Page::ResearchVolume, + Communication::Website::Page::Researcher, + Communication::Website::Page::Sitemap, + Communication::Website::Page::Teacher + ] scope :home, -> { where(type: HOME_TYPE) } end diff --git a/app/models/communication/website/with_dependencies.rb b/app/models/communication/website/with_dependencies.rb index e303cb563f3ab715cdfb6ee7c9f56cca18214990..e1fb3f03d330b4fdc40aa14bc1a5f7fb8b277dab 100644 --- a/app/models/communication/website/with_dependencies.rb +++ b/app/models/communication/website/with_dependencies.rb @@ -61,15 +61,15 @@ module Communication::Website::WithDependencies end def administrators - about.administrators + about&.administrators end def researchers - about.researchers + about&.researchers end def teachers - about.teachers + about&.teachers end def people_in_blocks diff --git a/app/models/communication/website/with_special_pages.rb b/app/models/communication/website/with_special_pages.rb index e9014e6000d8ae8d2e630dabd373e6c729257a98..b64c850512cc4a2d0d2ccc5e9fdebe289db12f3b 100644 --- a/app/models/communication/website/with_special_pages.rb +++ b/app/models/communication/website/with_special_pages.rb @@ -2,79 +2,31 @@ module Communication::Website::WithSpecialPages extend ActiveSupport::Concern included do - - # first level pages with test - SPECIAL_PAGES_WITH_TEST = [ - 'legal_terms', - 'sitemap', - 'privacy_policy', - 'accessibility', - 'communication_posts', - 'education_programs', - 'education_diplomas', - 'research_papers', - 'research_volumes', - 'organizations' - ] - - # team pages - SPECIAL_PAGES_FOR_PERSONS = [ - 'administrators', - 'authors', - 'researchers', - 'teachers' - ] - after_create :create_missing_special_pages - after_touch :create_missing_special_pages, :manage_special_pages_publication - - def special_page(kind) - pages.where(kind: kind).first - end - - def create_missing_special_pages - homepage = create_special_page('home') - SPECIAL_PAGES_WITH_TEST.each do |kind| - create_special_page(kind, homepage.id) if public_send("has_#{kind}?") - end - if has_persons? - persons = create_special_page('persons', homepage.id) - SPECIAL_PAGES_FOR_PERSONS.each do |kind| - create_special_page(kind, persons.id) if public_send("has_#{kind}?") - end - end - end + after_touch :create_missing_special_pages + end - def manage_special_pages_publication - special_pages_keys.each do |kind| - published = public_send("has_#{kind}?") - special_page(kind).update(published: published) - end + def create_missing_special_pages + home = nil + special_pages = Communication::Website::Page::TYPES.each do |page_class| + page = create_special_page page_class, home + home = page if home.nil? end - end - private + protected - def create_special_page(kind, parent_id = nil) - i18n_key = "communication.website.pages.defaults.#{kind}" - page = pages.where(kind: kind).first_or_initialize( - title: I18n.t("#{i18n_key}.title"), - slug: I18n.t("#{i18n_key}.slug"), - description_short: I18n.t("#{i18n_key}.description_short"), - parent_id: parent_id, - published: true, - university_id: university_id - ) + def create_special_page(page_class, parent) + page = page_class.where(website: self, university: university).first_or_initialize if page.new_record? - # This is a bit brutal, as it might generate several syncs at the same time - page.save_and_sync + i18n_key = "communication.website.pages.defaults.#{page.type_key}" + page.title = I18n.t("#{i18n_key}.title") + page.slug = I18n.t("#{i18n_key}.slug") + page.parent = parent + page.full_width = page.full_width_by_default? + page.published = page.published_by_default? + page.save_and_sync if page.is_necessary_for_website? end page end - - def special_pages_keys - @special_pages_keys ||= pages.where.not(kind: nil).pluck(:kind).uniq - end - end diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index 6324ffc3bc2092f055200286888f4af743e93271..3d2e0425fd4a06d4cf0d69c33d50701c09e8c32c 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -10,7 +10,7 @@ namespace :app do task fix: :environment do Communication::Website::Page.find_each do |page| if page.kind - type = "::Communication::Website::Page::#{page.kind.to_s.classify}" + type = "Communication::Website::Page::#{page.kind.to_s.classify}" page.update_column :type, type end end