From a358f0958facf7a896f976641f2d1e872c540f51 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Mon, 2 May 2022 11:06:06 +0200
Subject: [PATCH] dependencies through blocks

---
 app/models/concerns/with_git.rb       | 7 +++++++
 app/models/university/organization.rb | 1 +
 app/models/university/person.rb       | 1 +
 3 files changed, 9 insertions(+)

diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb
index 0b6845c2e..2da1884f0 100644
--- a/app/models/concerns/with_git.rb
+++ b/app/models/concerns/with_git.rb
@@ -84,6 +84,13 @@ module WithGit
     end
   end
 
+  def dependencies_through_blocks(website)
+    # We select all blocks having this object as dependency
+    blocks = website.blocks.select { |block| in? block.git_dependencies }
+    # We map them to their parent object (program, page, etc.)
+    blocks.map(&:about).uniq.compact
+  end
+
   def websites_for_self
     if is_a? Communication::Website
       [self]
diff --git a/app/models/university/organization.rb b/app/models/university/organization.rb
index 9e8a37796..bfc568b5f 100644
--- a/app/models/university/organization.rb
+++ b/app/models/university/organization.rb
@@ -79,6 +79,7 @@ class University::Organization < ApplicationRecord
       dependencies.concat active_storage_blobs
     end
     dependencies += website.menus.to_a
+    dependencies += dependencies_through_blocks(website) if in_block_dependencies?(website)
     dependencies
   end
 
diff --git a/app/models/university/person.rb b/app/models/university/person.rb
index 6e497a1bf..ae8ee83c2 100644
--- a/app/models/university/person.rb
+++ b/app/models/university/person.rb
@@ -172,6 +172,7 @@ class University::Person < ApplicationRecord
     dependencies << researcher if researcher.for_website?(website)
     dependencies << teacher if teacher.for_website?(website)
     dependencies += website.menus.to_a
+    dependencies += dependencies_through_blocks(website) if in_block_dependencies?(website)
     dependencies
   end
 
-- 
GitLab