From 2f6f86e3013c6850fadcce28b0a183e444f5dcca Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Tue, 3 Jan 2023 16:46:31 +0100
Subject: [PATCH] dependencies

---
 .../communication/websites/pages_controller.rb    |  2 +-
 app/models/communication/website/page.rb          | 13 ++++---------
 .../communication/website/page/administrator.rb   |  4 ++--
 app/models/communication/website/page/author.rb   |  4 ++--
 .../website/page/communication_post.rb            |  4 ++--
 .../website/page/education_diploma.rb             |  4 ++--
 .../website/page/education_program.rb             |  4 ++--
 app/models/communication/website/page/home.rb     |  4 ++++
 .../communication/website/page/organization.rb    |  4 ++--
 app/models/communication/website/page/person.rb   |  4 ++--
 .../communication/website/page/research_paper.rb  |  4 ++--
 .../communication/website/page/research_volume.rb |  4 ++--
 .../communication/website/page/researcher.rb      |  5 ++---
 app/models/communication/website/page/teacher.rb  |  2 +-
 .../communication/website/page/with_type.rb       | 15 +++++++++++++++
 .../communication/websites/pages/_form.html.erb   |  8 ++++----
 .../websites/pages/_treebranch.html.erb           |  2 +-
 17 files changed, 50 insertions(+), 37 deletions(-)

diff --git a/app/controllers/admin/communication/websites/pages_controller.rb b/app/controllers/admin/communication/websites/pages_controller.rb
index 84085d6ac..dfb92df94 100644
--- a/app/controllers/admin/communication/websites/pages_controller.rb
+++ b/app/controllers/admin/communication/websites/pages_controller.rb
@@ -3,7 +3,7 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We
                               through: :website
 
   def index
-    @homepage = @website.pages.kind_home.first
+    @homepage = @website.pages.home.first
     @first_level_pages = @homepage.children.ordered
     breadcrumb
   end
diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb
index ed3728c73..1e0cc646e 100644
--- a/app/models/communication/website/page.rb
+++ b/app/models/communication/website/page.rb
@@ -89,9 +89,9 @@ class Communication::Website::Page < ApplicationRecord
                     descendants +
                     active_storage_blobs +
                     siblings +
-                    git_block_dependencies
+                    git_block_dependencies +
+                    type_git_dependencies
     dependencies += [parent] if has_parent?
-    dependencies += special_page_git_dependencies(website) if is_special_page?
     dependencies.flatten
   end
 
@@ -113,24 +113,19 @@ class Communication::Website::Page < ApplicationRecord
     page
   end
 
-  def full_width
-    kind_home?  ? true
-                : attributes['full_width']
-  end
-
   def to_s
     "#{title}"
   end
 
   def best_featured_image
     # we don't want to fallback on homepage featured_image
-    return featured_image if featured_image.attached? || kind_home? || parent&.kind_home?
+    return featured_image if featured_image.attached? || is_home? || parent&.is_home?
     parent&.best_featured_image
   end
 
   def best_bodyclass
     return bodyclass if bodyclass.present?
-    parent&.best_bodyclass unless kind_home? || parent&.kind_home?
+    parent&.best_bodyclass unless is_home? || parent&.is_home?
   end
 
   def siblings
diff --git a/app/models/communication/website/page/administrator.rb b/app/models/communication/website/page/administrator.rb
index 169e5ad82..90e37781e 100644
--- a/app/models/communication/website/page/administrator.rb
+++ b/app/models/communication/website/page/administrator.rb
@@ -45,10 +45,10 @@ class Communication::Website::Page::Administrator < Communication::Website::Page
     "#{git_path_prefix}administrators/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.website.administrators.map(&:administrator)
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/author.rb b/app/models/communication/website/page/author.rb
index 2ef31f8af..10e663553 100644
--- a/app/models/communication/website/page/author.rb
+++ b/app/models/communication/website/page/author.rb
@@ -45,10 +45,10 @@ class Communication::Website::Page::Author < Communication::Website::Page
     "#{git_path_prefix}authors/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.website.authors.map(&:author)
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/communication_post.rb b/app/models/communication/website/page/communication_post.rb
index 10a7bba96..708bd5524 100644
--- a/app/models/communication/website/page/communication_post.rb
+++ b/app/models/communication/website/page/communication_post.rb
@@ -45,12 +45,12 @@ class Communication::Website::Page::CommunicationPost < Communication::Website::
     "#{git_path_prefix}posts/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.categories,
       website.authors.map(&:author),
       website.posts
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/education_diploma.rb b/app/models/communication/website/page/education_diploma.rb
index 62f304cb8..5603a78e1 100644
--- a/app/models/communication/website/page/education_diploma.rb
+++ b/app/models/communication/website/page/education_diploma.rb
@@ -45,10 +45,10 @@ class Communication::Website::Page::EducationDiploma < Communication::Website::P
     "#{git_path_prefix}diplomas/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.education_diplomas
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/education_program.rb b/app/models/communication/website/page/education_program.rb
index d06340d9a..be2cdf123 100644
--- a/app/models/communication/website/page/education_program.rb
+++ b/app/models/communication/website/page/education_program.rb
@@ -45,10 +45,10 @@ class Communication::Website::Page::EducationProgram < Communication::Website::P
     "#{git_path_prefix}programs/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.education_programs
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/home.rb b/app/models/communication/website/page/home.rb
index 032a599c3..754a7a00c 100644
--- a/app/models/communication/website/page/home.rb
+++ b/app/models/communication/website/page/home.rb
@@ -45,6 +45,10 @@ class Communication::Website::Page::Home < Communication::Website::Page
     "#{git_path_prefix}_index.html"
   end
 
+  def full_width
+    true
+  end
+
   def draftable?
     false
   end
diff --git a/app/models/communication/website/page/organization.rb b/app/models/communication/website/page/organization.rb
index 179fc2a57..f31d856ce 100644
--- a/app/models/communication/website/page/organization.rb
+++ b/app/models/communication/website/page/organization.rb
@@ -45,10 +45,10 @@ class Communication::Website::Page::Organization < Communication::Website::Page
     "#{git_path_prefix}organizations/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.organizations
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/person.rb b/app/models/communication/website/page/person.rb
index 7777925ac..6572ece24 100644
--- a/app/models/communication/website/page/person.rb
+++ b/app/models/communication/website/page/person.rb
@@ -45,10 +45,10 @@ class Communication::Website::Page::Person < Communication::Website::Page
     "#{git_path_prefix}persons/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.people_with_facets
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/research_paper.rb b/app/models/communication/website/page/research_paper.rb
index f3c75ad19..5e1669fdb 100644
--- a/app/models/communication/website/page/research_paper.rb
+++ b/app/models/communication/website/page/research_paper.rb
@@ -45,10 +45,10 @@ class Communication::Website::Page::ResearchPaper < Communication::Website::Page
     "#{git_path_prefix}papers/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.research_papers
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/research_volume.rb b/app/models/communication/website/page/research_volume.rb
index 5d5f124bd..11d4d39a5 100644
--- a/app/models/communication/website/page/research_volume.rb
+++ b/app/models/communication/website/page/research_volume.rb
@@ -45,10 +45,10 @@ class Communication::Website::Page::ResearchVolume < Communication::Website::Pag
     "#{git_path_prefix}volumes/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.research_volumes
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/researcher.rb b/app/models/communication/website/page/researcher.rb
index 14ac41857..b3e339784 100644
--- a/app/models/communication/website/page/researcher.rb
+++ b/app/models/communication/website/page/researcher.rb
@@ -45,11 +45,10 @@ class Communication::Website::Page::Researcher < Communication::Website::Page
     "#{git_path_prefix}researchers/_index.html"
   end
 
-
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.website.researchers.map(&:researcher)
-    ].flatten
+    ]
   end
 end
diff --git a/app/models/communication/website/page/teacher.rb b/app/models/communication/website/page/teacher.rb
index 7a36cc769..205415104 100644
--- a/app/models/communication/website/page/teacher.rb
+++ b/app/models/communication/website/page/teacher.rb
@@ -45,7 +45,7 @@ class Communication::Website::Page::Teacher < Communication::Website::Page
     "#{git_path_prefix}teachers/_index.html"
   end
 
-  def git_dependencies(website)
+  def type_git_dependencies
     [
       website.config_default_permalinks,
       website.website.teachers.map(&:teacher)
diff --git a/app/models/communication/website/page/with_type.rb b/app/models/communication/website/page/with_type.rb
index 52c0df179..8600451a5 100644
--- a/app/models/communication/website/page/with_type.rb
+++ b/app/models/communication/website/page/with_type.rb
@@ -1,12 +1,23 @@
 module Communication::Website::Page::WithType
   extend ActiveSupport::Concern
 
+  
+  included do
+    HOME_TYPE = '::Communication::Website::Page::Home'
+
+    scope :home, -> { where(type: HOME_TYPE) }
+  end
+
   # Communication::Website::Page::CommunicationPosts -> communication_posts
   # Used for i18n
   def type_key
     type.demodulize.underscore
   end
 
+  def is_home?
+    type == HOME_TYPE
+  end
+
   def is_special_page?
     type.present?
   end
@@ -36,4 +47,8 @@ module Communication::Website::Page::WithType
   def deletable?
     is_regular_page?
   end
+
+  def type_git_dependencies
+    []
+  end
 end
\ No newline at end of file
diff --git a/app/views/admin/communication/websites/pages/_form.html.erb b/app/views/admin/communication/websites/pages/_form.html.erb
index 81496623e..21bcb9fac 100644
--- a/app/views/admin/communication/websites/pages/_form.html.erb
+++ b/app/views/admin/communication/websites/pages/_form.html.erb
@@ -30,20 +30,20 @@ url = page.new_record?  ? admin_communication_website_pages_path
       </div>
     </div>
     <div class="col-md-4">
-      <% unless page.kind_home? %>
+      <% unless page.is_home? %>
         <div class="card flex-fill w-100">
           <div class="card-header">
             <h5 class="card-title mb-0"><%= t('metadata') %></h5>
           </div>
           <div class="card-body">
-            <%= f.input :published if page.is_regular_page? %>
+            <%= f.input :published if page.draftable? %>
             <%= f.input :slug,
                         as: :string,
                         required: true,
                         input_html: page.persisted? ? {} : {
                           class: 'js-slug-input',
                           data: { source: '#communication_website_page_title' }
-                        } unless page.kind_home? %>
+                        } unless page.is_home? %>
             <% if @website.languages.many? %>
               <%= f.input :language_id, collection: @website.languages, include_blank: false %>
             <% elsif @website.languages.any? %>
@@ -53,7 +53,7 @@ url = page.new_record?  ? admin_communication_website_pages_path
                               collection: collection_tree(@website.pages, page),
                               include_blank: false,
                               label_method: ->(p) { sanitize p[:label] },
-                              value_method: ->(p) { p[:id] } unless page.kind_home? %>
+                              value_method: ->(p) { p[:id] } unless page.is_home? %>
             <%= f.input :bodyclass if can?(:edit, @website) %>
             <%= f.input :full_width %>
           </div>
diff --git a/app/views/admin/communication/websites/pages/_treebranch.html.erb b/app/views/admin/communication/websites/pages/_treebranch.html.erb
index 8f92b6e49..1f5598eb6 100644
--- a/app/views/admin/communication/websites/pages/_treebranch.html.erb
+++ b/app/views/admin/communication/websites/pages/_treebranch.html.erb
@@ -15,7 +15,7 @@
       <%= link_to page,
                   admin_communication_website_page_path(website_id: page.website.id, id: page.id),
                   class: "#{'draft' unless page.published?}" %>
-      <% unless page.kind_home? %>
+      <% unless page.is_home? %>
         <span class="move_btn py-2 ps-2"><i class="fas fa-sort"></i></span>
       <% end %>
       <%= link_to children_admin_communication_website_page_path(website_id: page.website.id, id: page.id),
-- 
GitLab