From 09653d0069781a1bf65fd01e74ec33bd7f9578db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Fri, 28 Apr 2023 14:26:24 +0200 Subject: [PATCH] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Arnaud Levy <arnaud.levy@noesya.coop> Co-authored-by: Pierre-André Boissinot <pierreandre.boissinot@noesya.coop> --- app/models/communication/website.rb | 2 ++ .../communication/website/with_git_repository.rb | 4 ++-- app/models/concerns/as_direct_object.rb | 10 +++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 2de5b4a46..6820e3868 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -88,6 +88,8 @@ class Communication::Website < ApplicationRecord end def dependencies + # Le website est le SEUL cas d'auto-dépendance + [self] + configs + pages + posts + diff --git a/app/models/communication/website/with_git_repository.rb b/app/models/communication/website/with_git_repository.rb index 3f76c0fe0..b42580aae 100644 --- a/app/models/communication/website/with_git_repository.rb +++ b/app/models/communication/website/with_git_repository.rb @@ -11,11 +11,11 @@ module Communication::Website::WithGitRepository @git_repository ||= Git::Repository.new self end - # Supprimer tous les git_files qui ne sont pas dans les recursive_dependencie_syncable + # Supprimer tous les git_files qui ne sont pas dans les recursive_dependencies_syncable def destroy_obsolete_git_files website_git_files.find_each do |git_file| dependency = git_file.about - is_obsolete = !dependency.in?(recursive_dependencie_syncable) + is_obsolete = !dependency.in?(recursive_dependencies_syncable) if is_obsolete # TODO git_file.destroy serait plus ActiveRecord Communication::Website::GitFile.sync(self, dependency, destroy: true) diff --git a/app/models/concerns/as_direct_object.rb b/app/models/concerns/as_direct_object.rb index cfbaec991..6b21fb09c 100644 --- a/app/models/concerns/as_direct_object.rb +++ b/app/models/concerns/as_direct_object.rb @@ -17,11 +17,13 @@ module AsDirectObject class_name: 'Communication::Website', foreign_key: :communication_website_id - has_many :connections, + has_many :connections, as: :direct_source, class_name: 'Communication::Website::Connection', dependent: :destroy # When the direct object disappears all connections with the object as a source must disappear + after_save :sync_connections + after_touch :sync_connections end def is_direct_object? @@ -31,4 +33,10 @@ module AsDirectObject def is_indirect_object? false end + + def sync_connections + dependencies.each do |dependency| + website.connect(dependency, self) + end + end end \ No newline at end of file -- GitLab