From c60212800a51f72b32fdfed2bf8f66b5dddb785f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Mon, 16 May 2022 13:05:09 +0200
Subject: [PATCH] dependencies program diploma

---
 app/models/education/diploma.rb | 14 +++++++++++++-
 app/models/education/program.rb |  3 ++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/app/models/education/diploma.rb b/app/models/education/diploma.rb
index f268217ca..cdbb4aef7 100644
--- a/app/models/education/diploma.rb
+++ b/app/models/education/diploma.rb
@@ -49,15 +49,27 @@ class Education::Diploma < ApplicationRecord
     }
   end
 
+  def published_programs_for_website(website)
+    website.education_programs.published.where(diploma: self)
+  end
+
   # We need to send the diplomas only to the websites that need them
   def for_website?(website)
-    website.education_programs.published.where(diploma: self).any?
+    published_programs_for_website(website).any?
   end
 
   def git_path(website)
     "content/diplomas/#{slug}/_index.html"
   end
 
+  def git_dependencies(website)
+    published_programs = published_programs_for_website(website)
+
+    dependencies = [self]
+    dependencies += published_programs + published_programs.map(&:active_storage_blobs).flatten if published_programs.any?
+    dependencies
+  end
+
   def to_s
     "#{name}"
   end
diff --git a/app/models/education/program.rb b/app/models/education/program.rb
index 5b7465455..ec001f173 100644
--- a/app/models/education/program.rb
+++ b/app/models/education/program.rb
@@ -210,7 +210,8 @@ class Education::Program < ApplicationRecord
     university_people_through_role_involvements +
     university_people_through_role_involvements.map(&:active_storage_blobs).flatten +
     university_people_through_role_involvements.map(&:administrator) +
-    website.menus
+    website.menus +
+    [diploma]
   end
 
   def git_destroy_dependencies(website)
-- 
GitLab