From 8b3c042e393615a203292f420d4732fd174e3c70 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 7 Oct 2019 16:12:55 +0200 Subject: [PATCH 1/6] Change default executable name for LibreOffice [SCI-3970] --- lib/active_storage/previewer/libreoffice_previewer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_storage/previewer/libreoffice_previewer.rb b/lib/active_storage/previewer/libreoffice_previewer.rb index 23c18b5ce..a039a8017 100644 --- a/lib/active_storage/previewer/libreoffice_previewer.rb +++ b/lib/active_storage/previewer/libreoffice_previewer.rb @@ -44,7 +44,7 @@ module ActiveStorage end def libreoffice_path - ENV['LIBREOFFICE_PATH'] || 'libreoffice' + ENV['LIBREOFFICE_PATH'] || 'soffice' end end end From f9497e2e3e299b5528c2938497999565f42b7555 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Mon, 7 Oct 2019 16:21:11 +0200 Subject: [PATCH 2/6] Fix TinyMCE import from ELN --- app/utilities/protocols_importer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/utilities/protocols_importer.rb b/app/utilities/protocols_importer.rb index 131e25312..cb642648a 100644 --- a/app/utilities/protocols_importer.rb +++ b/app/utilities/protocols_importer.rb @@ -157,10 +157,11 @@ module ProtocolsImporter # Decode the file bytes file = StringIO.new(Base64.decode64(tiny_mce_img_json['bytes'])) - tiny_mce_img.image.attach(io: file, + to_blob = ActiveStorage::Blob.create_after_upload!(io: file, filename: tiny_mce_img_json['fileName'], content_type: tiny_mce_img_json['fileType'], metadata: JSON.parse(tiny_mce_img_json['fileMetadata'] || '{}')) + tiny_mce_img.image.attach(to_blob) if description.gsub!("data-mce-token=\"#{tiny_mce_img_json['tokenId']}\"", "data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"") else From 3d9c2282f381cb635bbbf9313e8c9848370caa98 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 8 Oct 2019 10:42:55 +0200 Subject: [PATCH 3/6] Implement JPEG quality extraction for ActiveStorage [SCI-3959] --- app/controllers/assets_controller.rb | 2 +- app/models/asset.rb | 14 ------------ config/initializers/active_storage.rb | 3 +++ .../analyzer/custom_image_analyzer.rb | 22 +++++++++++++++++++ 4 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 lib/active_storage/analyzer/custom_image_analyzer.rb diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index f248da78b..563011824 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -36,7 +36,7 @@ class AssetsController < ApplicationController end if response_json['type'] == 'previewable' if ['image/jpeg', 'image/pjpeg'].include? @asset.file.content_type - response_json['quality'] = @asset.file_image_quality || 90 + response_json['quality'] = @asset.file_image_quality || 80 end response_json.merge!( 'editable' => @asset.editable_image? && can_edit, diff --git a/app/models/asset.rb b/app/models/asset.rb index 785e8da99..2307d2b7a 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -15,8 +15,6 @@ class Asset < ApplicationRecord # ActiveStorage configuration has_one_attached :file - # before_post_process :extract_image_quality - # Asset validation # This could cause some problems if you create empty asset and want to # assign it to result @@ -204,18 +202,6 @@ class Asset < ApplicationRecord to_asset.post_process_file(to_asset.team) end - def extract_image_quality - return unless ['image/jpeg', 'image/pjpeg'].include? content_type - - tempfile = file.queued_for_write[:original] - unless tempfile.nil? - quality = Paperclip::Processor.new(tempfile).identify(" -format '%Q' #{tempfile.path}") - self.file_image_quality = quality.to_i - end - rescue StandardError => e - Rails.logger.info "There was an error extracting image quality - #{e}" - end - def image? content_type =~ %r{^image/#{Regexp.union(Constants::WHITELISTED_IMAGE_TYPES)}} end diff --git a/config/initializers/active_storage.rb b/config/initializers/active_storage.rb index 2efa60f57..609cfbc12 100644 --- a/config/initializers/active_storage.rb +++ b/config/initializers/active_storage.rb @@ -1,11 +1,14 @@ # frozen_string_literal: true require 'active_storage/previewer/libreoffice_previewer' +require 'active_storage/analyzer/custom_image_analyzer' require 'active_storage/downloader' Rails.application.config.active_storage.previewers = [ActiveStorage::Previewer::PopplerPDFPreviewer, ActiveStorage::Previewer::LibreofficePreviewer] +Rails.application.config.active_storage.analyzers.prepend(ActiveStorage::Analyzer::CustomImageAnalyzer) + Rails.application.config.active_storage.variable_content_types << 'image/svg+xml' Rails.application.config.active_storage.variant_processor = :vips if ENV['ACTIVESTORAGE_ENABLE_VIPS'] == 'true' diff --git a/lib/active_storage/analyzer/custom_image_analyzer.rb b/lib/active_storage/analyzer/custom_image_analyzer.rb new file mode 100644 index 000000000..8dd069e3f --- /dev/null +++ b/lib/active_storage/analyzer/custom_image_analyzer.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module ActiveStorage + class Analyzer::CustomImageAnalyzer < Analyzer::ImageAnalyzer + def self.accept?(blob) + ['image/jpeg', 'image/pjpeg'].include?(blob.content_type) && blob.attachments.take.record_type == 'Asset' + end + + def metadata + read_image do |image| + quality = image.identify { |b| b.format('%Q') }.to_i + blob.attachments.take.record.update(file_image_quality: quality) + + if rotated_image?(image) + { width: image.height, height: image.width } + else + { width: image.width, height: image.height } + end + end + end + end +end From 2608f3f1cfdb11df3337260f69e45f38c8614b23 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 8 Oct 2019 11:43:45 +0200 Subject: [PATCH 4/6] Improve code readability [SCI-3959] --- lib/active_storage/analyzer/custom_image_analyzer.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_storage/analyzer/custom_image_analyzer.rb b/lib/active_storage/analyzer/custom_image_analyzer.rb index 8dd069e3f..d38f5d7d6 100644 --- a/lib/active_storage/analyzer/custom_image_analyzer.rb +++ b/lib/active_storage/analyzer/custom_image_analyzer.rb @@ -2,8 +2,10 @@ module ActiveStorage class Analyzer::CustomImageAnalyzer < Analyzer::ImageAnalyzer + JPEG_MIME_TYPES = ['image/jpeg', 'image/pjpeg'].freeze + def self.accept?(blob) - ['image/jpeg', 'image/pjpeg'].include?(blob.content_type) && blob.attachments.take.record_type == 'Asset' + blob.content_type.in?(JPEG_MIME_TYPES) && blob.attachments.take.record_type == 'Asset' end def metadata From 6908a5c3a3fb677a31f3e6d9725802b3bcc89c9b Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 8 Oct 2019 12:02:45 +0200 Subject: [PATCH 5/6] Fix team deletion script [SCI-3960] --- app/services/user_data_deletion.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/user_data_deletion.rb b/app/services/user_data_deletion.rb index ff0550ec6..c9cd0e5c4 100644 --- a/app/services/user_data_deletion.rb +++ b/app/services/user_data_deletion.rb @@ -52,10 +52,10 @@ class UserDataDeletion end my_module.delete end + # Destroy workflow image - if experiment.workflowimg.exists? - experiment.workflowimg.clear(:original) - end + experiment.workflowimg.purge + experiment.activities.destroy_all experiment.report_elements.destroy_all experiment.my_module_groups.delete_all From f18941ea1907addb10ce97452868e551640d0dc1 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 8 Oct 2019 14:32:25 +0200 Subject: [PATCH 6/6] Update sassc gem version to 2.2.1 [SCI-3949] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8bdfc66ba..db6f2c48d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -502,7 +502,7 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sassc (2.2.0) + sassc (2.2.1) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0)