diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index dc368edf30d58fc96b124f81959cb637b2123c62..5bdbc37db5447431af365e8bae5f8b00c9db78c4 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -28,7 +28,6 @@ class Communication::Block < ApplicationRecord include WithDependencies include WithPosition include WithUniversity - include WithWebsites include Sanitizable IMAGE_MAX_SIZE = 5.megabytes @@ -84,18 +83,6 @@ class Communication::Block < ApplicationRecord template.data end - def website - about.website - rescue - nil - end - - def websites - about.websites - rescue - [] - end - def display_dependencies template.display_dependencies end diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 8aaf20077bd5a72796536beae315b82ef55bcd86..86a79193d90d51f2bb0a3188f51dff7e9072cc8f 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -45,7 +45,6 @@ class Communication::Website::Category < ApplicationRecord include WithBlobs include WithBlocks include WithFeaturedImage - include WithGit include WithMenuItemTarget include WithPermalink include WithPosition diff --git a/app/models/communication/website/git_file.rb b/app/models/communication/website/git_file.rb index 780e6264fe0f4b1cc3928ede68280823bafcc074..08c74466164462c8a2f9c679995ae25aa66baf5e 100644 --- a/app/models/communication/website/git_file.rb +++ b/app/models/communication/website/git_file.rb @@ -29,10 +29,12 @@ 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) # Permalinks must be calculated BEFORE renders - object.manage_permalink_in_website(website) if Communication::Website::Permalink.supported_by?(object) - # Handle optional before-sync process - object.before_git_sync + manage_permalink object, website + # Blobs need to be completely analyzed, which is async + analyze_if_blob object # The git file might exist or not git_file = where(website: website, about: object).first_or_create # Mark for destruction if necessary @@ -54,6 +56,16 @@ class Communication::Website::GitFile < ApplicationRecord protected + def self.manage_permalink(object, website) + return unless Communication::Website::Permalink.supported_by?(object) + object.manage_permalink_in_website(website) + end + + def self.analyze_if_blob(object) + return unless object.is_a? ActiveStorage::Blob + object.analyze unless object.analyzed? + end + def template_static if about.respond_to? :template_static about.template_static diff --git a/app/models/communication/website/menu.rb b/app/models/communication/website/menu.rb index e93e33daa6f70c319c4ef09afae441fc539c8dee..d03c7db268b70929dd934aab99d99c3018cb6f54 100644 --- a/app/models/communication/website/menu.rb +++ b/app/models/communication/website/menu.rb @@ -29,7 +29,6 @@ # class Communication::Website::Menu < ApplicationRecord include Sanitizable - include WithGit include WithTranslations include WithUniversity include WithWebsites diff --git a/app/models/communication/website/menu/item.rb b/app/models/communication/website/menu/item.rb index c8815d4fe0c01fb212321de703ba8d3877b4aa1f..be62c4eec84ff3666bd3717f8f4cca47878b35f4 100644 --- a/app/models/communication/website/menu/item.rb +++ b/app/models/communication/website/menu/item.rb @@ -37,7 +37,6 @@ class Communication::Website::Menu::Item < ApplicationRecord include WithPosition include WithTree include WithUniversity - include WithWebsites attr_accessor :skip_publication_callback diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 87bbf6d78db46eea084e1e8e1091726928dd43a6..c2f25d608dc59fd66fd0c724d2268d212116ad77 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -52,7 +52,6 @@ class Communication::Website::Page < ApplicationRecord include WithBlocks include WithDuplication include WithFeaturedImage - include WithGit include WithMenuItemTarget include WithPosition include WithTree diff --git a/app/models/communication/website/page/organization.rb b/app/models/communication/website/page/organization.rb index 1ba321f7cf4e3ad67ef69a9493b3d3e0ca10dc3d..6bce06ad357bd62737fec45a294e681d83e4f937 100644 --- a/app/models/communication/website/page/organization.rb +++ b/app/models/communication/website/page/organization.rb @@ -47,7 +47,7 @@ class Communication::Website::Page::Organization < Communication::Website::Page def display_dependencies super + [website.config_default_permalinks] + - website.organizations + website.connected_organizations end protected diff --git a/app/models/communication/website/page/person.rb b/app/models/communication/website/page/person.rb index e6326aaf1e2b69a6f1c858343bbb1154187f6725..76f9fdc378808ce6ed8aee1998575374ec55a2f8 100644 --- a/app/models/communication/website/page/person.rb +++ b/app/models/communication/website/page/person.rb @@ -47,7 +47,7 @@ class Communication::Website::Page::Person < Communication::Website::Page def display_dependencies super + [website.config_default_permalinks] + - website.people_with_facets + website.connected_people end protected diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 2db2dde0672c647f60b1790ce48e53184668eb2c..15cb41f33387a81db9015c43d8a174348e89354b 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -43,7 +43,6 @@ class Communication::Website::Post < ApplicationRecord include WithBlocks include WithDuplication include WithFeaturedImage - include WithGit include WithMenuItemTarget include WithPermalink include WithSlug # We override slug_unavailable? method diff --git a/app/models/communication/website/with_connections.rb b/app/models/communication/website/with_connections.rb index 0b33bad47cfb50092ae5bf183be833420b24493d..459f23ac1f3927e6da330f1bd891ee80122a94fd 100644 --- a/app/models/communication/website/with_connections.rb +++ b/app/models/communication/website/with_connections.rb @@ -26,6 +26,17 @@ module Communication::Website::WithConnections disconnect_object object end + # TODO factoriser avec les extranets + def connected_people + ids = connections.where(object_type: 'University::Person').pluck(:object_id) + University::Person.where(id: ids) + end + + def connected_organizations + ids = connections.where(object_type: 'University::Organization').pluck(:object_id) + University::Organization.where(id: ids) + end + protected def connect_object(object) diff --git a/app/models/communication/website/with_old_dependencies.rb b/app/models/communication/website/with_old_dependencies.rb index 100a1d8e256bd51f3835b97a9f8ccdf7f3423c40..527d1aa980f3cd3718a99d0ef08aa0a9fabf840b 100644 --- a/app/models/communication/website/with_old_dependencies.rb +++ b/app/models/communication/website/with_old_dependencies.rb @@ -24,23 +24,6 @@ module Communication::Website::WithOldDependencies end - # Deprecated - def blocks - @blocks ||= begin - blocks = Communication::Block.where(about_type: 'Communication::Website::Page', about_id: pages) - blocks = blocks.or(Communication::Block.where(about_type: 'Communication::Website::Post', about_id: posts)) - blocks = blocks.or(Communication::Block.where(about_type: 'Education::Program', about_id: education_programs)) if has_education_programs? - blocks = blocks.or(Communication::Block.where(about_type: 'Education::Diploma', about_id: education_diplomas)) if has_education_diplomas? - # TODO: Blocks from People & Organizations ? - blocks - end - end - - # Deprecated - def blocks_dependencies - @blocks_dependencies ||= blocks.collect(&:git_dependencies).flatten.compact.uniq - end - def education_diplomas has_education_diplomas? ? about.diplomas : Education::Diploma.none end diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index aa063e78e16ea902b5ef5dd54f69a911954e2043..90b7dc07720d3eed6f3bbefc22eb4a871a66b93e 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -24,11 +24,6 @@ module WithGit path end - def before_git_sync - # Can be override to force some process before sync - # ex: ActiveStorage Blob analyze - end - def save_and_sync if save sync_with_git @@ -54,8 +49,8 @@ module WithGit def sync_with_git websites_for_self.each do |website| - website.touch next unless website.git_repository.valid? + Communication::Website::GitFile.sync website, self dependencies.each do |object| Communication::Website::GitFile.sync website, object end @@ -65,48 +60,20 @@ module WithGit handle_asynchronously :sync_with_git, queue: 'default' def destroy_from_git - websites_for_self.each do |website| + websites.each do |website| next unless website.git_repository.valid? - # FIXME - dependencies = git_destroy_dependencies(website).to_a.flatten.uniq.compact - dependencies.each do |object| - Communication::Website::GitFile.sync website, object, destroy: true - end + Communication::Website::GitFile.sync website, self, destroy: true + # # FIXME + # dependencies = git_destroy_dependencies(website).to_a.flatten.uniq.compact + # dependencies.each do |object| + # Communication::Website::GitFile.sync website, object, destroy: true + # end website.git_repository.sync! end end - - # Deprecated - def has_website_for_self?(website) - websites_for_self.include?(website) - end - - # Deprecated - def git_dependencies(website = nil) - [self] - end - - # Deprecated - def git_destroy_dependencies(website = nil) - [self] - end protected - - # Deprecated - def in_block_dependencies?(website) - website.blocks_dependencies.include?(self) - end - - # Deprecated - 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 - - # Deprecated + def websites_for_self if is_a? Communication::Website [self] diff --git a/app/models/concerns/with_websites.rb b/app/models/concerns/with_websites.rb index d70bd1fb248761c655d6735891f3976b7d9803a0..3c8b2ad97eddee84a0c9779b1d505fc2b5529436 100644 --- a/app/models/concerns/with_websites.rb +++ b/app/models/concerns/with_websites.rb @@ -1,7 +1,10 @@ +# Le website utilise WithGit sans WithWebsites, parce qu'il en est un module WithWebsites extend ActiveSupport::Concern included do + include WithGit + after_save :connect_to_websites end diff --git a/app/models/education/diploma.rb b/app/models/education/diploma.rb index c5352e64d81221408c33af905511d86584d31788..f63c561c4c4e4ed18e19b64b7d87f651e20251f9 100644 --- a/app/models/education/diploma.rb +++ b/app/models/education/diploma.rb @@ -25,7 +25,6 @@ class Education::Diploma < ApplicationRecord include Sanitizable include WithBlocks - include WithGit include WithPermalink include WithSlug include WithUniversity diff --git a/app/models/education/program.rb b/app/models/education/program.rb index dd9c6199367bf9fa6e6d0540d37f80447af83441..12d8b9e11792b7f87205d0974f52454dc264ca04 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -57,7 +57,6 @@ class Education::Program < ApplicationRecord include WithBlocks include WithDiploma include WithFeaturedImage - include WithGit include WithInheritance include WithMenuItemTarget include WithPermalink @@ -68,6 +67,7 @@ class Education::Program < ApplicationRecord include WithTree include WithUniversity include WithWebsites + include WithWebsitesCategories rich_text_areas_with_inheritance :accessibility, :contacts, diff --git a/app/models/education/program/with_websites.rb b/app/models/education/program/with_websites_categories.rb similarity index 50% rename from app/models/education/program/with_websites.rb rename to app/models/education/program/with_websites_categories.rb index 6fe2a46406b1c3f1fbc793ee7d1dd4d220f0d9de..186c6dc885cabccdbad714baf662f11738b4dcaa 100644 --- a/app/models/education/program/with_websites.rb +++ b/app/models/education/program/with_websites_categories.rb @@ -1,4 +1,4 @@ -module Education::Program::WithWebsites +module Education::Program::WithWebsitesCategories extend ActiveSupport::Concern included do @@ -12,20 +12,6 @@ module Education::Program::WithWebsites dependent: :destroy end - def websites - @websites ||= university.websites.reject do |website| - website_concerned = false - # Site de formation - website_concerned = true if website.about == self - # Site d'école - if website.about&.is_a? Education::School - # Formation dispensée dans l'école - website_concerned = true if self.in? website.about.programs - end - !website_concerned - end - end - def set_websites_categories websites.each { |website| website.set_programs_categories! } end diff --git a/app/models/education/school.rb b/app/models/education/school.rb index 7e919ff72a705c7bda2f84f2ccc57b480b5a20a5..b08323dd87263a3181fb130b98e3baaeccb9b886 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -27,8 +27,8 @@ class Education::School < ApplicationRecord include Aboutable include Sanitizable include WithAlumni + include WithBlobs include WithCountry - include WithGit include WithPrograms # must come before WithAlumni and WithTeam include WithTeam include WithWebsites @@ -87,4 +87,12 @@ class Education::School < ApplicationRecord def has_research_volumes? false end + + protected + + def explicit_blob_ids + [ + logo&.blob_id + ] + end end diff --git a/app/models/research/hal/publication.rb b/app/models/research/hal/publication.rb index ca8f84adf6d230b2bf7a8561b6923ed847e0c15b..6cb7aecdb6c0273139cf9894823c3e5d7fa2ff23 100644 --- a/app/models/research/hal/publication.rb +++ b/app/models/research/hal/publication.rb @@ -22,7 +22,6 @@ class Research::Hal::Publication < ApplicationRecord include Sanitizable include WithSlug - include WithGit include WithWebsites has_and_belongs_to_many :researchers, diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index 6be6ce32d0c2f526620f0f25b9a5fbd2928e4486..5e9c0133238d7852b2f388cd3b72d168b87f17e9 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -23,7 +23,6 @@ class Research::Journal < ApplicationRecord include Sanitizable include Aboutable include WithUniversity - include WithGit include WithWebsites has_many :communication_websites, class_name: 'Communication::Website', as: :about, dependent: :nullify diff --git a/app/models/research/journal/paper.rb b/app/models/research/journal/paper.rb index 800a2a8e8382443728ba7288f936a88499355616..b699dd1c89a251b72f14a4717fa7e79d8e612991 100644 --- a/app/models/research/journal/paper.rb +++ b/app/models/research/journal/paper.rb @@ -45,7 +45,6 @@ class Research::Journal::Paper < ApplicationRecord include Sanitizable include WithBlobs include WithBlocks - include WithGit include WithPermalink include WithPosition include WithPublication diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 057e91a2be7210d120d8e9cb60f4e4c349d0b26e..dbb1871c03fd9cf443f857caa7d4559dd24c85fa 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -33,7 +33,6 @@ class Research::Journal::Volume < ApplicationRecord include Sanitizable include WithBlobs include WithFeaturedImage - include WithGit include WithPermalink include WithPublication include WithSlug diff --git a/app/models/university/organization.rb b/app/models/university/organization.rb index cfc1faa5101eb5c23db9f1fe68df55a42ab8f034..9081c6dfa8b2d35b5b3828134734e273c3dc20c1 100644 --- a/app/models/university/organization.rb +++ b/app/models/university/organization.rb @@ -45,7 +45,6 @@ class University::Organization < ApplicationRecord include WithBlocks include WithCountry include WithGeolocation - include WithGit include WithPermalink include WithSlug include WithUniversity diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 26c0e4f172bac044a7a86cafce9985c2ec9ddc7f..eff10be723865739fc2c11a6b7d2a4ee62fca101 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -55,7 +55,6 @@ class University::Person < ApplicationRecord include Sanitizable include WithUniversity - include WithGit include WithBlobs include WithCountry include WithEducation @@ -64,7 +63,7 @@ class University::Person < ApplicationRecord include WithPicture include WithRoles include WithBlocks - include WithPermalink + include WitvihPermalink include WithResearch include WithTranslations include WithWebsites diff --git a/config/initializers/active_storage.rb b/config/initializers/active_storage.rb index ddc32d906d4aa899f4a3c852efdf6de92e114fd5..09189629127c9671cab691d6adf82dec7628e749 100644 --- a/config/initializers/active_storage.rb +++ b/config/initializers/active_storage.rb @@ -46,10 +46,6 @@ Rails.application.config.to_prepare do def git_path(website) "data/media/#{id[0..1]}/#{id}.yml" end - - def before_git_sync - analyze unless analyzed? - end end ActiveStorage::Blob.include ActiveStorageGitPathStatic