diff --git a/app/controllers/slack_uploads_controller.rb b/app/controllers/slack_uploads_controller.rb index 6f157c7d5..127e77649 100644 --- a/app/controllers/slack_uploads_controller.rb +++ b/app/controllers/slack_uploads_controller.rb @@ -17,12 +17,7 @@ class SlackUploadsController < ApplicationController end def blob_url - # Only generate representations for images - if @blob.content_type.start_with?('image/') - url_for(@blob.representation(resize_to_fill: [250, nil])) - else - url_for(@blob) - end + url_for(@blob.representation(resize_to_fill: [250, nil])) end def avatar_url diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 8c5750148..fd114c38c 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -60,9 +60,11 @@ class Attachment < ApplicationRecord end def thumb_url - return '' unless file.attached? && image? - - url_for(file.representation(resize_to_fill: [250, nil])) + if file.attached? && file.representable? + url_for(file.representation(resize_to_fill: [250, nil])) + else + '' + end end def with_attached_file? diff --git a/config/application.rb b/config/application.rb index 92dd9a011..5316e65bf 100644 --- a/config/application.rb +++ b/config/application.rb @@ -61,9 +61,6 @@ module Chatwoot # https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017 # FIX ME : fixes breakage of installation config. we need to migrate. config.active_record.yaml_column_permitted_classes = [ActiveSupport::HashWithIndifferentAccess] - - # Disable PDF/video preview generation as we don't use them - config.active_storage.previewers = [] end def self.config diff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rb index 0b03a56ad..241125538 100644 --- a/spec/models/attachment_spec.rb +++ b/spec/models/attachment_spec.rb @@ -68,22 +68,6 @@ RSpec.describe Attachment do end end - describe 'thumb_url' do - it 'returns empty string for non-image attachments' do - attachment = message.attachments.new(account_id: message.account_id, file_type: :file) - attachment.file.attach(io: StringIO.new('fake pdf'), filename: 'test.pdf', content_type: 'application/pdf') - - expect(attachment.thumb_url).to eq('') - end - - it 'generates thumb_url for image attachments' do - attachment = message.attachments.create!(account_id: message.account_id, file_type: :image) - attachment.file.attach(io: StringIO.new('fake image'), filename: 'test.jpg', content_type: 'image/jpeg') - - expect(attachment.thumb_url).to be_present - end - end - describe 'meta data handling' do let(:message) { create(:message) }