From 2e24576be36e69330b8e700b0bb22ad961dd9cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Mon, 23 Mar 2026 10:55:56 +0100 Subject: [PATCH 1/5] WIP movable to website --- app/models/communication/website/post.rb | 5 +++ app/models/concerns/movable_to_website.rb | 54 +++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 app/models/concerns/movable_to_website.rb diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index c11f20e4f..4ebd1e792 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -34,6 +34,7 @@ class Communication::Website::Post < ApplicationRecord include GeneratesGitFiles include Lifecyclable include Localizable + include MovableToWebsite include Sanitizable include Searchable include WithMenuItemTarget @@ -125,4 +126,8 @@ def update_authors_status_if_necessary! def list_blocks_template_kind :posts end + + def after_moved_to_website(source_website, target_website) + authors.clear if source_website.university_id != target_website.university_id + end end diff --git a/app/models/concerns/movable_to_website.rb b/app/models/concerns/movable_to_website.rb new file mode 100644 index 000000000..0eb81f3bf --- /dev/null +++ b/app/models/concerns/movable_to_website.rb @@ -0,0 +1,54 @@ +module MovableToWebsite + extend ActiveSupport::Concern + + def move_to!(website) + source_website = self.website + transaction do + update(communication_website_id: website.id, university_id: website.university_id) + clean_categories_after_move + clean_content_federations_after_move + move_localizations_to(website) + after_moved_to_website(source_website, website) + source_website.clean + end + self + end + + protected + + def clean_categories_after_move + return unless respond_to?(:categories) + categories.clear + end + + def clean_content_federations_after_move + return unless respond_to?(:content_federations) + content_federations.destroy_all + end + + def move_localizations_to(website) + localizations.each do |l10n| + l10n.update(communication_website_id: website.id, university_id: website.university_id) + move_featured_image(l10n, website) + move_blocks(l10n, website) + end + end + + def move_featured_image(l10n, website) + return unless l10n.respond_to?(:featured_image) && l10n.featured_image.attached? + return if l10n.featured_image.blob.university_id == website.university_id + l10n.featured_image.blob.update(university_id: website.university_id) + end + + def move_blocks(l10n, website) + return unless l10n.respond_to?(:blocks) + l10n.blocks.ordered.each do |block| + block.update(communication_website_id: website.id, university_id: website.university_id) + end + end + + def after_moved_to_website(source_website, target_website) + # Overridable method to implement specific logic + end + +end From 85c59e036082209ed5f4b75584f6f4d5ade25dc1 Mon Sep 17 00:00:00 2001 From: pabois Date: Mon, 30 Mar 2026 12:19:11 +0200 Subject: [PATCH 2/5] interface --- .../websites/posts_controller.rb | 1 + app/helpers/admin/application_helper.rb | 7 ++ app/models/user/with_roles.rb | 12 ++ .../websites/posts/show.html.erb | 1 + config/locales/en.yml | 5 + config/locales/fr.yml | 5 + config/routes/admin/communication.rb | 2 + db/schema.rb | 108 +++++++++--------- 8 files changed, 87 insertions(+), 54 deletions(-) diff --git a/app/controllers/admin/communication/websites/posts_controller.rb b/app/controllers/admin/communication/websites/posts_controller.rb index 4eba0bf3b..8f84f631a 100644 --- a/app/controllers/admin/communication/websites/posts_controller.rb +++ b/app/controllers/admin/communication/websites/posts_controller.rb @@ -4,6 +4,7 @@ class Admin::Communication::Websites::PostsController < Admin::Communication::We except: :restore include Admin::HasPreview + include Admin::HasMoveAction include Admin::HasStaticAction include Admin::Localizable diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index 924dbc198..dfcdafd53 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -49,6 +49,13 @@ def duplicate_link(object, html_classes: nil) class: html_classes end + def move_link(object, html_classes: button_classes_danger) + return unless can?(:move, object) && current_user.managed_websites.count > 1 + link_to t('admin.move.cta'), + [:move, :admin, object], + class: html_classes + end + def preview_link raw "