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

---
 .../website/page/administrator.rb             |  6 +++
 .../communication/website/page/author.rb      |  6 +++
 .../website/page/education_diploma.rb         |  6 +++
 .../website/page/education_program.rb         |  6 +++
 app/models/communication/website/page/home.rb |  4 ++
 .../website/page/organization.rb              |  6 +++
 .../communication/website/page/person.rb      |  6 +++
 .../website/page/research_paper.rb            |  6 +++
 .../website/page/research_volume.rb           |  6 +++
 .../communication/website/page/researcher.rb  |  7 +++
 .../communication/website/page/teacher.rb     |  6 +++
 .../communication/website/page/with_kind.rb   | 47 ++-----------------
 .../communication/website/page/with_type.rb   |  3 +-
 13 files changed, 70 insertions(+), 45 deletions(-)

diff --git a/app/models/communication/website/page/administrator.rb b/app/models/communication/website/page/administrator.rb
index 93fed5bbc..169e5ad82 100644
--- a/app/models/communication/website/page/administrator.rb
+++ b/app/models/communication/website/page/administrator.rb
@@ -45,4 +45,10 @@ class Communication::Website::Page::Administrator < Communication::Website::Page
     "#{git_path_prefix}administrators/_index.html"
   end
 
+  def git_dependencies(website)
+    [
+      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 e04954cf0..2ef31f8af 100644
--- a/app/models/communication/website/page/author.rb
+++ b/app/models/communication/website/page/author.rb
@@ -45,4 +45,10 @@ class Communication::Website::Page::Author < Communication::Website::Page
     "#{git_path_prefix}authors/_index.html"
   end
 
+  def git_dependencies(website)
+    [
+      website.config_default_permalinks,
+      website.website.authors.map(&:author)
+    ].flatten
+  end
 end
diff --git a/app/models/communication/website/page/education_diploma.rb b/app/models/communication/website/page/education_diploma.rb
index 5c05e798f..62f304cb8 100644
--- a/app/models/communication/website/page/education_diploma.rb
+++ b/app/models/communication/website/page/education_diploma.rb
@@ -45,4 +45,10 @@ class Communication::Website::Page::EducationDiploma < Communication::Website::P
     "#{git_path_prefix}diplomas/_index.html"
   end
 
+  def git_dependencies(website)
+    [
+      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 298a0a325..d06340d9a 100644
--- a/app/models/communication/website/page/education_program.rb
+++ b/app/models/communication/website/page/education_program.rb
@@ -45,4 +45,10 @@ class Communication::Website::Page::EducationProgram < Communication::Website::P
     "#{git_path_prefix}programs/_index.html"
   end
 
+  def git_dependencies(website)
+    [
+      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 a5b816619..032a599c3 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 draftable?
+    false
+  end
+
   protected 
 
   def set_slug
diff --git a/app/models/communication/website/page/organization.rb b/app/models/communication/website/page/organization.rb
index b67936691..179fc2a57 100644
--- a/app/models/communication/website/page/organization.rb
+++ b/app/models/communication/website/page/organization.rb
@@ -45,4 +45,10 @@ class Communication::Website::Page::Organization < Communication::Website::Page
     "#{git_path_prefix}organizations/_index.html"
   end
 
+  def git_dependencies(website)
+    [
+      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 2f3baf146..7777925ac 100644
--- a/app/models/communication/website/page/person.rb
+++ b/app/models/communication/website/page/person.rb
@@ -45,4 +45,10 @@ class Communication::Website::Page::Person < Communication::Website::Page
     "#{git_path_prefix}persons/_index.html"
   end
 
+  def git_dependencies(website)
+    [
+      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 8692c5e79..f3c75ad19 100644
--- a/app/models/communication/website/page/research_paper.rb
+++ b/app/models/communication/website/page/research_paper.rb
@@ -45,4 +45,10 @@ class Communication::Website::Page::ResearchPaper < Communication::Website::Page
     "#{git_path_prefix}papers/_index.html"
   end
 
+  def git_dependencies(website)
+    [
+      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 06113453e..5d5f124bd 100644
--- a/app/models/communication/website/page/research_volume.rb
+++ b/app/models/communication/website/page/research_volume.rb
@@ -45,4 +45,10 @@ class Communication::Website::Page::ResearchVolume < Communication::Website::Pag
     "#{git_path_prefix}volumes/_index.html"
   end
 
+  def git_dependencies(website)
+    [
+      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 184ffc29f..14ac41857 100644
--- a/app/models/communication/website/page/researcher.rb
+++ b/app/models/communication/website/page/researcher.rb
@@ -45,4 +45,11 @@ class Communication::Website::Page::Researcher < Communication::Website::Page
     "#{git_path_prefix}researchers/_index.html"
   end
 
+
+  def git_dependencies(website)
+    [
+      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 5461b31bc..7a36cc769 100644
--- a/app/models/communication/website/page/teacher.rb
+++ b/app/models/communication/website/page/teacher.rb
@@ -45,4 +45,10 @@ class Communication::Website::Page::Teacher < Communication::Website::Page
     "#{git_path_prefix}teachers/_index.html"
   end
 
+  def git_dependencies(website)
+    [
+      website.config_default_permalinks,
+      website.website.teachers.map(&:teacher)
+    ].flatten
+  end
 end
diff --git a/app/models/communication/website/page/with_kind.rb b/app/models/communication/website/page/with_kind.rb
index 36d449b37..67460dbb1 100644
--- a/app/models/communication/website/page/with_kind.rb
+++ b/app/models/communication/website/page/with_kind.rb
@@ -2,7 +2,9 @@ module Communication::Website::Page::WithKind
   extend ActiveSupport::Concern
 
   included do
-
+    # Deprecated
+    # Utile pour la migration, le rails app:fix
+    # Supprimer après seulement
     enum kind: {
       home: 0,
       communication_posts: 10,
@@ -22,49 +24,6 @@ module Communication::Website::Page::WithKind
       teachers: 140
     }, _prefix: 'kind'
 
-    # -> dans les nouvelles classes
-    SPECIAL_PAGES_WITH_GIT_SPECIAL_PATH = [
-      'communication_posts',
-      'education_programs',
-      'education_diplomas',
-      'research_papers',
-      'research_volumes',
-      'organizations',
-      'persons',
-      'administrators',
-      'authors',
-      'researchers',
-      'teachers'
-    ].freeze
-
-    # -> dans les nouvelles classes
-    def has_special_git_path?
-      is_special_page? && SPECIAL_PAGES_WITH_GIT_SPECIAL_PATH.include?(kind)
-    end
-
-    # -> dans les nouvelles classes
-    def special_page_git_dependencies(website)
-      dependencies = [website.config_default_permalinks]
-      case kind
-      when "communication_posts"
-        dependencies += [
-          website.categories,
-          website.authors.map(&:author),
-          website.posts
-        ].flatten
-      when "education_programs", "education_diplomas", "research_papers", "organizations"
-        # dependencies += website.education_programs
-        dependencies += website.public_send(kind)
-      when "people"
-        dependencies += website.people_with_facets
-      when "administrators", "authors", "researchers", "teachers"
-        # dependencies += website.authors.map(&:author)
-        dependencies += website.public_send(kind).map(&kind.singularize.to_sym)
-      end
-
-      dependencies
-    end
-
   end
 
 end
diff --git a/app/models/communication/website/page/with_type.rb b/app/models/communication/website/page/with_type.rb
index 3ea32edae..52c0df179 100644
--- a/app/models/communication/website/page/with_type.rb
+++ b/app/models/communication/website/page/with_type.rb
@@ -32,7 +32,8 @@ module Communication::Website::Page::WithType
     true
   end
 
+  # All special pages are undeletable
   def deletable?
-    true
+    is_regular_page?
   end
 end
\ No newline at end of file
-- 
GitLab