diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 6e9502353145d815d8a2290548b2308f0b3e4792..2de5b4a46d557de7f4760a600e9a05de5435df0f 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -88,6 +88,7 @@ class Communication::Website < ApplicationRecord end def dependencies + configs + pages + posts + categories + diff --git a/app/models/communication/website/git_file.rb b/app/models/communication/website/git_file.rb index 08c74466164462c8a2f9c679995ae25aa66baf5e..b4352b3dcd52d62179ee1934e678f6a4b284c6f7 100644 --- a/app/models/communication/website/git_file.rb +++ b/app/models/communication/website/git_file.rb @@ -29,8 +29,14 @@ class Communication::Website::GitFile < ApplicationRecord attr_accessor :will_be_destroyed def self.sync(website, object, destroy: false) - # A dependency does not always have a GitFile (ex: Communication::Block) - return unless object.respond_to?(:git_files) + # All exportable objects must respond to this method + # WithGitFiles defines it + # AsDirectObject includes WithGitFiles, therefore all direct objects are exportable + # AsIndirectObject does not include it, but some indirect objects have it (Person, Organization...) + # Some objects need to declare that property: + # - the website itself + # - configs (which inherit from the website) + return unless object.try(:exportable_to_git?) # Permalinks must be calculated BEFORE renders manage_permalink object, website # Blobs need to be completely analyzed, which is async diff --git a/app/models/communication/website/with_configs.rb b/app/models/communication/website/with_configs.rb index 34cb40689d735b835a8aa6cb04345bcdecd5d7ff..5c5ff105eb1e49400e9c6b9c0d173e9b17b0e5b7 100644 --- a/app/models/communication/website/with_configs.rb +++ b/app/models/communication/website/with_configs.rb @@ -3,6 +3,15 @@ module Communication::Website::WithConfigs included do + def configs + [ + config_default_languages, + config_default_permalinks, + config_development_config, + config_production_config + ] + end + def config_default_languages @config_default_languages ||= Communication::Website::Configs::DefaultLanguages.find(id) end diff --git a/app/models/communication/website/with_git_repository.rb b/app/models/communication/website/with_git_repository.rb index fd6bb72da7e04eff10bb34809e1ea6641653680c..3f76c0fe093853a34003fd27b1ea266819f16677 100644 --- a/app/models/communication/website/with_git_repository.rb +++ b/app/models/communication/website/with_git_repository.rb @@ -24,4 +24,10 @@ module Communication::Website::WithGitRepository self.git_repository.sync! end handle_asynchronously :destroy_obsolete_git_files, queue: :default + + # Le website devient data/website.yml + # Les configs héritent du modèle website et s'exportent en différents fichiers + def exportable_to_git? + true + end end diff --git a/app/models/communication/website/with_old_dependencies.rb b/app/models/communication/website/with_old_dependencies.rb index 39e51edead9c61358aaca5b360d192c03db2c50c..0498e80c65a23c3f1a9d215e552a8cb134ee8120 100644 --- a/app/models/communication/website/with_old_dependencies.rb +++ b/app/models/communication/website/with_old_dependencies.rb @@ -52,46 +52,12 @@ module Communication::Website::WithOldDependencies has_teachers? ? about.teachers : University::Person.none end - def people_in_blocks - @people_in_blocks ||= blocks_dependencies.reject { |dependency| !dependency.is_a? University::Person } + def people + connected_persons end def organizations - organizations_in_blocks - end - - def organizations_in_blocks - @organizations_in_blocks ||= blocks_dependencies.reject { |dependency| !dependency.is_a? University::Organization } - end - - def people_with_facets_in_blocks - @people_with_facets_in_blocks ||= blocks_dependencies.reject { |dependency| !dependency.class.to_s.start_with?('University::Person') } - end - - def people - # TODO: Scoper aux langues du website dans le cas où une personne serait traduite dans + de langues - @people ||= begin - people = [] - people += authors if has_authors? - people += teachers if has_teachers? - people += administrators if has_administrators? - people += researchers if has_researchers? - people += people_in_blocks if has_people_in_blocks? - people.uniq.compact - end - end - - def people_with_facets - # TODO: Scoper aux langues du website dans le cas où une personne serait traduite dans + de langues - @people_with_facets ||= begin - people_with_facets = people - people_with_facets += authors.compact.map(&:author) if has_authors? - people_with_facets += teachers.compact.map(&:teacher) if has_teachers? - people_with_facets += administrators.compact.map(&:administrator) if has_administrators? - people_with_facets += researchers.compact.map(&:researcher) if has_researchers? - people_with_facets += people_with_facets_in_blocks if has_people_in_blocks? - people_with_facets.uniq.compact - end + connected_organizations end # Deprecated, needs refactor for performance @@ -105,23 +71,15 @@ module Communication::Website::WithOldDependencies end def has_organizations? - has_organizations_in_blocks? + connected_organizations.any? end def has_authors? authors.compact.any? end - def has_people_in_blocks? - people_in_blocks.compact.any? - end - - def has_organizations_in_blocks? - organizations_in_blocks.compact.any? - end - def has_persons? - has_authors? || has_administrators? || has_researchers? || has_teachers? || has_people_in_blocks? + connected_people.any? end def has_administrators? diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index b06c6f5bfc98be17ce46842cd962cc845786b4aa..0752db0bee2e77f970deef103dfa65f283ef4065 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -1,3 +1,7 @@ +# Donne la capacité de se synchroniser avec Git lors d'une opération ActiveRecord +# Utilisé par : +# - website +# - objets directs module WithGit extend ActiveSupport::Concern @@ -45,13 +49,4 @@ module WithGit website.git_repository.sync! end - def for_website?(website) - website.id == website_id - end - - protected - - def website_for_self - is_a?(Communication::Website) ? self : website - end end diff --git a/app/models/concerns/with_git_files.rb b/app/models/concerns/with_git_files.rb index 1e5ad126821214d5604af4b56e97e195bb688706..8d77e4a8a7b6c06b09d694677c1dec1018a17006 100644 --- a/app/models/concerns/with_git_files.rb +++ b/app/models/concerns/with_git_files.rb @@ -12,6 +12,10 @@ module WithGitFiles raise NotImplementedError end + def exportable_to_git? + true + end + def git_path_content_prefix(website) # Handle language-less objects # TODO I18n: Right now, we use the language of the object, fallbacking on the language of the website. In the end, we'll only use the language of the object