diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/jobs/resend_stored_blob_data_job.rb b/app/jobs/resend_stored_blob_data_job.rb deleted file mode 100644 index e38ced519..000000000 --- a/app/jobs/resend_stored_blob_data_job.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class ResendStoredBlobDataJob < ApplicationJob - # Resending the blob data will trigger a malware scan. - def perform(batch_size: 1000) - return unless FeatureFlags::FeatureFlag.active?(:malware_scan) - - Upload - .where(malware_scan_result: "pending") - .limit(batch_size) - .find_each do |upload| - sleep(2) # Avoid rate limiting - Malware::ResendStoredBlobData.new(upload:).call - end - end -end diff --git a/app/lib/malware/resend_stored_blob_data.rb b/app/lib/malware/resend_stored_blob_data.rb deleted file mode 100644 index 048c8a211..000000000 --- a/app/lib/malware/resend_stored_blob_data.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -module Malware - class ResendStoredBlobData - # Only later versions of the Azure Storage REST API support tags operations. - Kernel.silence_warnings { Azure::Storage::Blob::Default::STG_VERSION = "2022-11-02" } - - BLOB_CONTAINER_NAME = ENV["AZURE_STORAGE_CONTAINER"] || "uploads" - - def initialize(upload:) - @upload = upload - end - - def call - return unless upload.scan_result_pending? && upload.file&.key.present? - - response = blob_service.call(:put, put_blob_url, attachment_data, headers) - - FetchMalwareScanResultJob.set(wait: 1.minute).perform_later(upload:) if response.success? - rescue ActiveStorage::FileNotFoundError - upload.update!(malware_scan_result: "error") - end - - private - - attr_reader :upload - - def blob_service - @blob_service ||= - Azure::Storage::Blob::BlobService.new( - storage_account_name: ENV["AZURE_STORAGE_ACCOUNT_NAME"], - storage_access_key: ENV["AZURE_STORAGE_ACCESS_KEY"] - ) - end - - def headers - { - "x-ms-blob-type" => "BlockBlob", - "x-ms-version" => "2022-11-02", - "Content-Length" => attachment_data.size - } - end - - def attachment_data - @attachment_data ||= upload.file.download - end - - def put_blob_url - blob_service.generate_uri(File.join(BLOB_CONTAINER_NAME, upload.file.key)) - end - end -end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/models/referral.rb b/app/models/referral.rb index 0c84f535f..0a54aa2a0 100644 --- a/app/models/referral.rb +++ b/app/models/referral.rb @@ -8,10 +8,6 @@ class Referral < ApplicationRecord has_many :uploads, as: :uploadable - # TODO: This is a temporary association to allow us to delete referrals that have been created - # but not submitted. Once we delete the referral_evidences table we can remove this association. - has_many :referral_evidences, dependent: :destroy - has_one :allegation_upload, -> { where(section: "allegation").order(created_at: :desc) }, class_name: "Upload", diff --git a/config/analytics.yml b/config/analytics.yml index 4156bdba0..9a0d44054 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -37,12 +37,6 @@ shared: - job_title - last_name - complete - :referral_evidences: - - id - - filename - - referral_id - - created_at - - updated_at :referrals: - id - created_at diff --git a/config/analytics_pii.yml b/config/analytics_pii.yml index 839492495..7dde5c6bc 100644 --- a/config/analytics_pii.yml +++ b/config/analytics_pii.yml @@ -8,8 +8,6 @@ - first_name - phone - last_name - :referral_evidences: - - filename :referrals: - first_name - last_name diff --git a/db/migrate/20230615115253_delete_referral_evidences.rb b/db/migrate/20230615115253_delete_referral_evidences.rb new file mode 100644 index 000000000..bf170ff39 --- /dev/null +++ b/db/migrate/20230615115253_delete_referral_evidences.rb @@ -0,0 +1,9 @@ +class DeleteReferralEvidences < ActiveRecord::Migration[7.0] + def change + drop_table :referral_evidences, if_exists: true do |t| + t.references :referral, index: true, foreign_key: true + t.string :filename + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c2a18ef50..0d3914bf0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,6 +13,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_29_131752) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" + enable_extension "plpgsql" create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -21,9 +22,7 @@ t.bigint "blob_id", null: false t.datetime "created_at", null: false t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" - t.index %w[record_type record_id name blob_id], - name: "index_active_storage_attachments_uniqueness", - unique: true + t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end create_table "active_storage_blobs", force: :cascade do |t| @@ -41,9 +40,7 @@ create_table "active_storage_variant_records", force: :cascade do |t| t.bigint "blob_id", null: false t.string "variation_digest", null: false - t.index %w[blob_id variation_digest], - name: "index_active_storage_variant_records_uniqueness", - unique: true + t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end create_table "eligibility_checks", force: :cascade do |t| @@ -88,14 +85,6 @@ t.index ["referral_id"], name: "index_organisations_on_referral_id" end - create_table "referral_evidences", force: :cascade do |t| - t.string "filename" - t.bigint "referral_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["referral_id"], name: "index_referral_evidences_on_referral_id" - end - create_table "referrals", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -219,20 +208,20 @@ t.index ["email"], name: "index_staff_on_email", unique: true t.index ["invitation_token"], name: "index_staff_on_invitation_token", unique: true t.index ["invited_by_id"], name: "index_staff_on_invited_by_id" - t.index %w[invited_by_type invited_by_id], name: "index_staff_on_invited_by" + t.index ["invited_by_type", "invited_by_id"], name: "index_staff_on_invited_by" t.index ["reset_password_token"], name: "index_staff_on_reset_password_token", unique: true t.index ["unlock_token"], name: "index_staff_on_unlock_token", unique: true end create_table "uploads", force: :cascade do |t| t.string "section", null: false - t.string "filename", null: false, default: "" + t.string "filename", default: "", null: false t.string "uploadable_type" t.bigint "uploadable_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "malware_scan_result", default: "pending", null: false - t.index %w[uploadable_type uploadable_id], name: "index_uploads_on_uploadable" + t.index ["uploadable_type", "uploadable_id"], name: "index_uploads_on_uploadable" end create_table "users", force: :cascade do |t| @@ -263,9 +252,8 @@ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "organisations", "referrals" - add_foreign_key "referral_evidences", "referrals" add_foreign_key "referrals", "eligibility_checks" add_foreign_key "referrals", "users" add_foreign_key "referrers", "referrals" - add_foreign_key "reminder_emails", "referrals", column: "referral_id" + add_foreign_key "reminder_emails", "referrals" end diff --git a/lib/tasks/.keep b/lib/tasks/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/tasks/malware_scan.rake b/lib/tasks/malware_scan.rake deleted file mode 100644 index eadd8535c..000000000 --- a/lib/tasks/malware_scan.rake +++ /dev/null @@ -1,12 +0,0 @@ -namespace :malware_scan do - desc "Resend blob data for uploads that have a pending malware scan result" - task resend_stored_blob_data: :environment do - ResendStoredBlobDataJob.perform_later - end - - desc "Print a count of uploads with a pending malware scan result" - task count_pending: :environment do - upload_count = Upload.where(malware_scan_result: "pending").count - puts "#{upload_count} uploads have a pending malware scan result" - end -end diff --git a/lib/tasks/transfer_attachments.rake b/lib/tasks/transfer_attachments.rake deleted file mode 100644 index e2438d81f..000000000 --- a/lib/tasks/transfer_attachments.rake +++ /dev/null @@ -1,33 +0,0 @@ -desc "Transfers the ActiveStorage attachments from referrals to uploads" -task transfer_attachments: :environment do - ActiveRecord::Base.transaction do - sections = %w[allegation duties previous_misconduct] - - sections.each do |section| - attachments = - ActiveStorage::Attachment.where(record_type: "Referral", name: "#{section}_upload") - - attachments.each do |attachment| - upload = attachment.record.uploads.new(section:, filename: attachment.filename.to_s) - upload.save(validate: false) - attachment.update(record: upload, record_type: "Upload", name: "file") - end - - puts "Transferred #{attachments.size} #{section} attachments" - end - - evidence_attachments = ActiveStorage::Attachment.where(record_type: "ReferralEvidence") - - evidence_attachments.each do |attachment| - upload = - attachment.record.referral.uploads.new( - section: "evidence", - filename: attachment.filename.to_s - ) - upload.save(validate: false) - attachment.update(record: upload, record_type: "Upload", name: "file") - end - - puts "Transferred #{evidence_attachments.size} evidence attachments" - end -end diff --git a/spec/lib/malware/resend_stored_blob_data_spec.rb b/spec/lib/malware/resend_stored_blob_data_spec.rb deleted file mode 100644 index 4980b1c5e..000000000 --- a/spec/lib/malware/resend_stored_blob_data_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe Malware::ResendStoredBlobData do - describe "#call" do - subject(:resend_stored_blob_data) { described_class.new(upload:).call } - - let(:upload) { create(:upload, :allegation) } - let(:attachment) { instance_double(ActiveStorage::Blob, key: "key") } - let(:response_success) { true } - let(:put_blob_url) { "http://example.com/uploads/#{upload.file.key}" } - let(:stubbed_blob_service) do - instance_double(Azure::Storage::Blob::BlobService, generate_uri: put_blob_url) - end - let(:stubbed_response) do - instance_double(Azure::Core::Http::HttpResponse, success?: response_success) - end - - before do - allow(Azure::Storage::Blob::BlobService).to receive(:new).and_return(stubbed_blob_service) - allow(stubbed_blob_service).to receive(:call).and_return(stubbed_response) - end - - it "calls the Azure Storage REST API to PUT blob data from the upload attachment" do - expect(stubbed_blob_service).to receive(:call).with( - :put, - put_blob_url, - upload.file.download, - anything - ) - resend_stored_blob_data - end - - it "enqueues a FetchMalwareScanResultJob" do - allow(FetchMalwareScanResultJob).to receive(:set).with(wait: 1.minute).and_return( - FetchMalwareScanResultJob - ) - expect(FetchMalwareScanResultJob).to receive(:perform_later).with(upload:) - resend_stored_blob_data - end - - context "when the upload attachment is missing" do - let(:attachment) { instance_double(ActiveStorage::Blob) } - - before do - allow(upload).to receive(:file).and_return(attachment) - allow(attachment).to receive(:key).and_raise(ActiveStorage::FileNotFoundError) - end - - it "updates to the malware scan result field to 'error'" do - resend_stored_blob_data - expect(upload.reload.malware_scan_result).to eq("error") - end - end - - context "when the upload attachment key is nil" do - let(:attachment) { instance_double(ActiveStorage::Blob, key: nil) } - - before { allow(upload).to receive(:file).and_return(attachment) } - - it "returns without update" do - expect { resend_stored_blob_data }.not_to change(upload.reload, :malware_scan_result) - end - end - end -end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb deleted file mode 100644 index d19212abd..000000000 --- a/test/application_system_test_case.rb +++ /dev/null @@ -1,5 +0,0 @@ -require "test_helper" - -class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :chrome, screen_size: [1400, 1400] -end diff --git a/test/channels/application_cable/connection_test.rb b/test/channels/application_cable/connection_test.rb deleted file mode 100644 index 6340bf9c0..000000000 --- a/test/channels/application_cable/connection_test.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "test_helper" - -module ApplicationCable - class ConnectionTest < ActionCable::Connection::TestCase - # test "connects with cookies" do - # cookies.signed[:user_id] = 42 - # - # connect - # - # assert_equal connection.user_id, "42" - # end - end -end diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/controllers/pages_controller_test.rb b/test/controllers/pages_controller_test.rb deleted file mode 100644 index 257c27cf7..000000000 --- a/test/controllers/pages_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "test_helper" - -class PagesControllerTest < ActionDispatch::IntegrationTest - # test "the truth" do - # assert true - # end -end diff --git a/test/helpers/.keep b/test/helpers/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/integration/.keep b/test/integration/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/models/.keep b/test/models/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/system/.keep b/test/system/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 0c22470ec..000000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -ENV["RAILS_ENV"] ||= "test" -require_relative "../config/environment" -require "rails/test_help" - -module ActiveSupport - class TestCase - # Run tests in parallel with specified workers - parallelize(workers: :number_of_processors) - - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all - - # Add more helper methods to be used by all tests here... - end -end