Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/models/communication/website/with_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion app/models/university/with_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ 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)
# Production osuny.osuny.org -> osuny
# 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
Expand Down
71 changes: 71 additions & 0 deletions app/services/migrations/handle_legacy_sound_blocks.rb
Original file line number Diff line number Diff line change
@@ -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?

@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}"
Comment thread
SebouChu marked this conversation as resolved.
end
end
3 changes: 2 additions & 1 deletion config/application.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Loading