Sha256: e400cd20c26c8006f8c083b9548ed0a56b29408838af569883bcd6c1de8d7922

Contents?: true

Size: 860 Bytes

Versions: 29

Compression:

Stored size: 860 Bytes

Contents

module Sufia
  module GenericFile
    module VirusCheck
      extend ActiveSupport::Concern

      included do
        validate :detect_viruses
      end

      # Default behavior is to raise a validation error and halt the save if a virus is found
      def detect_viruses
        return unless content.changed?
        path = if content.content.respond_to?(:path)
                 content.content.path
               else
                 Tempfile.open('') do |t|
                   t.binmode
                   t.write(content.content)
                   t.close
                   t.path
                 end
               end
        Sufia::GenericFile::Actor.virus_check(path)
        true
      rescue Sufia::VirusFoundError => virus
        logger.warn(virus.message)
        errors.add(:base, virus.message)
        false
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
sufia-5.0.0 sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-5.0.0 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-5.0.0.rc1 sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-5.0.0.rc1 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-6.0.0.rc2 sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-6.0.0.rc2 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-6.0.0.rc1 sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-6.0.0.rc1 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-4.3.1 sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-4.3.1 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-6.0.0.beta1 sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-6.0.0.beta1 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-5.0.0.beta1 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-4.2.0 sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-4.2.0 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-4.1.0 sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-4.1.0 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-4.0.1 sufia-models/app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-4.0.1 app/models/concerns/sufia/generic_file/virus_check.rb
sufia-models-4.0.0 app/models/concerns/sufia/generic_file/virus_check.rb