From c73f0c4c583006a8bde78e4752e9bf58e106d16a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Tue, 4 Aug 2026 15:45:48 +0200 Subject: [PATCH 1/3] fix legacy sound blocks --- .../migrations/handle_legacy_sound_blocks.rb | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 app/services/migrations/handle_legacy_sound_blocks.rb diff --git a/app/services/migrations/handle_legacy_sound_blocks.rb b/app/services/migrations/handle_legacy_sound_blocks.rb new file mode 100644 index 000000000..da51e61fc --- /dev/null +++ b/app/services/migrations/handle_legacy_sound_blocks.rb @@ -0,0 +1,71 @@ +class Migrations::HandleLegacySoundBlocks + def self.migrate + puts 'Migrations::HandleLegacySoundBlocks - Starting migration' + new.migrate + end + + def initialize + @processed_blocks = 0 + @created_localizations = 0 + end + + def migrate + # Find all Communication::Block with template_kind "sound" (which is 197) + Communication::Block.where(template_kind: :sound).find_each do |block| + process_block(block) + end + + puts "Processed #{@processed_blocks} blocks" + puts "Created #{@created_localizations} Communication::File::Localization records" + end + + protected + + def process_block(block) + return if block.data.blank? || block.data['elements'].blank? + + @processed_blocks += 1 + puts "Processing block #{block.id} with language #{block.language}" + + data = block.data + return if data['file'].blank? + + file_data = data['file'] + return if file_data['communication_file_id'].present? + + begin + process_file_component(file_data, block) + rescue => e + puts "Error processing file element in block #{block.id}: #{e.message}" + return + end + + # Save the updated block data + block.data = data + block.update_column :data, block.data + block.send(:manage_file_contexts) + end + + def process_file_component(file_data, block) + blob_id = file_data['id'] + filename = file_data['filename'] + language = block.language + + puts " Processing file with blob id: #{blob_id}... (filename: #{filename})" + + # Find the ActiveStorage blob by ID + blob = ActiveStorage::Blob.find(blob_id) + + # Create or find the Communication::File and Localization + localization = Communication::File::Localization.find_or_create_from_blob(blob, language) + + # Update the element data to reference the new Communication::File + file_data['communication_file_id'] = localization.about_id + + if localization.saved_change_to_id? + @created_localizations += 1 + end + + puts " Created Communication::File #{localization.about_id} with localization #{localization.id}" + end +end From dd13909a3428d95bda28372699659b58390de049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Tue, 4 Aug 2026 15:57:31 +0200 Subject: [PATCH 2/3] fix --- app/services/migrations/handle_legacy_sound_blocks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/migrations/handle_legacy_sound_blocks.rb b/app/services/migrations/handle_legacy_sound_blocks.rb index da51e61fc..d222c8da7 100644 --- a/app/services/migrations/handle_legacy_sound_blocks.rb +++ b/app/services/migrations/handle_legacy_sound_blocks.rb @@ -22,7 +22,7 @@ def migrate protected def process_block(block) - return if block.data.blank? || block.data['elements'].blank? + return if block.data.blank? @processed_blocks += 1 puts "Processing block #{block.id} with language #{block.language}" From 3cc44bf784f14fcb5a90a38eb705f1a60f79a7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Tue, 4 Aug 2026 16:27:51 +0200 Subject: [PATCH 3/3] fix --- app/models/communication/website/with_security.rb | 8 ++++---- app/models/university/with_identifier.rb | 6 +++++- config/application.sample.yml | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/communication/website/with_security.rb b/app/models/communication/website/with_security.rb index 26da7008c..f8d96c44a 100644 --- a/app/models/communication/website/with_security.rb +++ b/app/models/communication/website/with_security.rb @@ -13,10 +13,10 @@ def allowed_domains def allowed_domains_default [ - ENV['KEYCDN_HOST'], # KeyCDN for assets resize - '*.osuny.org', # osuny for assets resize - 'osuny.s3.fr-par.scw.cloud', # Scaleway for direct assets - 'tile.openstreetmap.org' # Open Street Map default tiles + ENV['KEYCDN_HOST'], # KeyCDN for assets resize + "*#{University.environment_domain}", # osuny for assets resize + ENV["SCALEWAY_OS_HOST"], # Scaleway for direct assets + 'tile.openstreetmap.org' # Open Street Map default tiles ].compact end diff --git a/app/models/university/with_identifier.rb b/app/models/university/with_identifier.rb index 32133d44f..141172bcc 100644 --- a/app/models/university/with_identifier.rb +++ b/app/models/university/with_identifier.rb @@ -17,6 +17,10 @@ def self.with_host(host) find_by identifier: extract_identifier_from(host) end + def self.environment_domain + self.send("#{ENV['APPLICATION_ENV']}_domain") + end + private # University direct urls (not through website) @@ -24,7 +28,7 @@ def self.with_host(host) # Staging osuny.osuny.dev -> osuny # Dev osuny.osuny -> osuny def self.extract_identifier_from(host) - host.remove self.send("#{ENV['APPLICATION_ENV']}_domain") + host.remove environment_domain end def self.production_domain diff --git a/config/application.sample.yml b/config/application.sample.yml index fc127c36e..c4fc7ed37 100644 --- a/config/application.sample.yml +++ b/config/application.sample.yml @@ -46,11 +46,12 @@ PEXELS_API_KEY: RACK_TIMEOUT_SERVICE_TIMEOUT: "0" -RORVSWILD_API_KEY: +RORVSWILD_API_KEY: SCALEWAY_OS_ACCESS_KEY_ID: SCALEWAY_OS_BUCKET: SCALEWAY_OS_ENDPOINT: +SCALEWAY_OS_HOST: SCALEWAY_OS_REGION: SCALEWAY_OS_SECRET_ACCESS_KEY: