From fe84e8e0f7bf4f1fa4042e929c13d14345e4fb4a Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 12 Nov 2019 15:26:18 +0100 Subject: [PATCH] Remove carrierwave --- Gemfile | 3 - Gemfile.lock | 10 -- config/env.example | 1 - config/secrets.yml | 4 - ...mmentaire_piece_justificative_to_file.rake | 51 -------- lib/tasks/cloud_storage.rake | 113 ------------------ 6 files changed, 182 deletions(-) delete mode 100644 lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake delete mode 100644 lib/tasks/cloud_storage.rake diff --git a/Gemfile b/Gemfile index 1d23d00d8..3a224b34a 100644 --- a/Gemfile +++ b/Gemfile @@ -13,12 +13,9 @@ gem 'bcrypt' gem 'bootstrap-sass', '>= 3.4.1' gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8' gem 'browser' -gem 'carrierwave' -gem 'carrierwave-i18n' gem 'chartkick' gem 'chunky_png' gem 'clamav-client', require: 'clamav/client' -gem 'copy_carrierwave_file' gem 'daemons' gem 'deep_cloneable' # Enable deep clone of active record models gem 'delayed_cron_job' # Cron jobs diff --git a/Gemfile.lock b/Gemfile.lock index fae5871bb..71de81e68 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -136,11 +136,6 @@ GEM capybara-selenium (0.0.6) capybara selenium-webdriver - carrierwave (1.3.1) - activemodel (>= 4.0.0) - activesupport (>= 4.0.0) - mime-types (>= 1.16) - carrierwave-i18n (0.2.0) case_transform (0.2) activesupport chartkick (3.2.0) @@ -158,8 +153,6 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.1.5) connection_pool (2.2.2) - copy_carrierwave_file (1.3.0) - carrierwave (>= 0.9) crack (0.4.3) safe_yaml (~> 1.0.0) crass (1.0.5) @@ -730,12 +723,9 @@ DEPENDENCIES capybara-email capybara-screenshot capybara-selenium - carrierwave - carrierwave-i18n chartkick chunky_png clamav-client - copy_carrierwave_file daemons database_cleaner deep_cloneable diff --git a/config/env.example b/config/env.example index c3c40d089..aa54c288a 100644 --- a/config/env.example +++ b/config/env.example @@ -23,7 +23,6 @@ FOG_OPENSTACK_IDENTITY_API_VERSION="" FOG_OPENSTACK_REGION="" FOG_DIRECTORY="" FOG_ENABLED="" -CARRIERWAVE_CACHE_DIR="/tmp/tps-local-cache" DS_PROXY_URL="" FC_PARTICULIER_ID="" diff --git a/config/secrets.yml b/config/secrets.yml index 2ac8aa244..23c8e5267 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -42,8 +42,6 @@ defaults: &defaults openstack_identity_api_version: "<%= ENV['FOG_OPENSTACK_IDENTITY_API_VERSION'] %>" openstack_region: <%= ENV['FOG_OPENSTACK_REGION'] %> directory: <%= ENV['FOG_DIRECTORY'] %> - carrierwave: - cache_dir: <%= ENV['CARRIERWAVE_CACHE_DIR'] %> mailtrap: username: <%= ENV['MAILTRAP_USERNAME'] %> password: <%= ENV['MAILTRAP_PASSWORD'] %> @@ -84,8 +82,6 @@ test: key: api_entreprise_test_key fog: directory: tps_dev - carrierwave: - cache_dir: /tmp/tps-test-cache pipedrive: key: pipedrive_test_key france_connect_particulier: diff --git a/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake b/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake deleted file mode 100644 index 6a721ed00..000000000 --- a/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake +++ /dev/null @@ -1,51 +0,0 @@ -require Rails.root.join("lib", "tasks", "task_helper") - -namespace :'2017_10_30_copy_commentaire_piece_justificative_to_file' do - task set: :environment do - commentaires_to_process = Commentaire.where(file: nil).where.not(piece_justificative_id: nil).reorder(id: :desc) - - rake_puts "#{commentaires_to_process.count} commentaires to process..." - - commentaires_to_process.each do |c| - process_commentaire(c) - end - end - - task fix: :environment do - commentaires_to_fix = Commentaire.where.not(file: nil).where.not(piece_justificative_id: nil).reorder(id: :desc) - - rake_puts "#{commentaires_to_fix.count} commentaires to fix..." - - commentaires_to_fix.each do |c| - process_commentaire(c) - end - end - - def sanitize_name(name) # from https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/sanitized_file.rb#L323 - name = name.gsub(/[^[:word:]\.\-\+]/, "_") - name = "_#{name}" if name.match?(/\A\.+\z/) - name = "unnamed" if name.empty? - return name.mb_chars.to_s - end - - def process_commentaire(commentaire) - rake_puts "Processing commentaire #{commentaire.id}" - if commentaire.piece_justificative.present? - # https://github.com/carrierwaveuploader/carrierwave#uploading-files-from-a-remote-location - commentaire.remote_file_url = commentaire.piece_justificative.content_url - - if commentaire.piece_justificative.original_filename.present? - commentaire.file.define_singleton_method(:filename) { sanitize_name(commentaire.piece_justificative.original_filename) } - end - - if commentaire.body.blank? - commentaire.body = commentaire.piece_justificative.original_filename || "." - end - - commentaire.save - if commentaire.file.blank? - rake_puts "Failed to save file for commentaire #{commentaire.id}" - end - end - end -end diff --git a/lib/tasks/cloud_storage.rake b/lib/tasks/cloud_storage.rake deleted file mode 100644 index 2a276ac55..000000000 --- a/lib/tasks/cloud_storage.rake +++ /dev/null @@ -1,113 +0,0 @@ -require Rails.root.join("lib", "tasks", "task_helper") - -namespace :cloudstorage do - task init: :environment do - os_config = (YAML.load_file(Fog.credentials_path))['default'] - @os = OpenStack::Connection.create( - { - username: os_config['openstack_username'], - api_key: os_config['openstack_api_key'], - auth_method: "password", - auth_url: "https://auth.cloud.ovh.net/v2.0/", - authtenant_name: os_config['openstack_tenant'], - service_type: "object-store", - region: os_config['openstack_region'] - } - ) - @cont = @os.container(CarrierWave::Uploader::Base.fog_directory) - end - - desc 'Move local attestations on cloud storage' - task migrate: :environment do - puts 'Starting migration' - - Rake::Task['cloudstorage:init'].invoke - - error_count = 0 - [Cerfa, PieceJustificative, Procedure].each do |c| - c.all.each do |entry| - content = (c == Procedure) ? entry.logo : entry.content - if !(content.current_path.nil? || File.exist?(File.dirname(content.current_path) + '/uploaded')) - secure_token = SecureRandom.uuid - filename = "#{entry.class.to_s.underscore}-#{secure_token}#{File.extname(content.current_path)}" - rake_puts "Uploading #{content.current_path}" - begin - @cont.create_object(filename, {}, File.open(content.current_path)) - - File.open(File.dirname(content.current_path) + '/uploaded', "w+") { |f| f.write(File.basename(content.current_path)) } - File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "w+") { |f| f.write(filename) } - File.open(File.dirname(content.current_path) + '/secure_token_cloudstorage', "w+") { |f| f.write(secure_token) } - - entry.update_column(c == Procedure ? :logo : :content, filename) - entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, secure_token) - rescue Errno::ENOENT - rake_puts "ERROR: #{content.current_path} does not exist!" - File.open('upload_errors.report', "a+") { |f| f.write(content.current_path) } - error_count += 1 - end - else - if content.current_path.present? && File.exist?(File.dirname(content.current_path) + '/uploaded') - filename = File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "r").read - secure_token = File.open(File.dirname(content.current_path) + '/secure_token_cloudstorage', "r").read - - entry.update_column(c == Procedure ? :logo : :content, filename) - entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, secure_token) - - rake_puts "RESTORE IN DATABASE: #{filename} " - elsif content.current_path.present? - rake_puts "Skipping #{content.current_path}" - end - end - end - end - - rake_puts "There were #{error_count} errors while uploading files. See upload_errors.report file for details." - puts 'Enf of migration' - end - - desc 'Clear documents in tenant and revert file entries in database' - task :revert do - Rake::Task['cloudstorage:init'].invoke - - [Cerfa, PieceJustificative, Procedure].each do |c| - c.all.each do |entry| - content = (c == Procedure) ? entry.logo : entry.content - if content.current_path.present? - if File.exist?(File.dirname(content.current_path) + '/uploaded') - previous_filename = File.read(File.dirname(content.current_path) + '/uploaded') - - entry.update_column(c == Procedure ? :logo : :content, previous_filename) - entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, nil) - - rake_puts "restoring #{content.current_path} db data to #{previous_filename}" - - @cont.delete_object(File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "r").read) - - FileUtils.rm(File.dirname(content.current_path) + '/uploaded') - FileUtils.rm(File.dirname(content.current_path) + '/filename_cloudstorage') - FileUtils.rm(File.dirname(content.current_path) + '/secure_token_cloudstorage') - end - end - end - end - end - - desc 'Clear old documents in tenant' - task :clear do - Rake::Task['cloudstorage:init'].invoke - - @cont.objects.each do |object| - rake_puts "Removing #{object}" - @cont.delete_object(object) - end - end - - task :clear_old_objects do - Rake::Task['cloudstorage:init'].invoke - - @cont.objects_detail.each do |object, details| - last_modified = Time.zone.parse(details[:last_modified]) - @cont.delete_object(object) if last_modified.utc <= (Time.zone.now - 2.years).utc - end - end -end