Module: ValidatePdf

Extended by:
ActiveSupport::Concern
Included in:
EVSSClaimDocumentUploaderBase, LighthouseDocumentUploaderBase
Defined in:
app/uploaders/validate_pdf.rb

Instance Method Summary collapse

Instance Method Details

#validate(temp_file) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'app/uploaders/validate_pdf.rb', line 12

def validate(temp_file)
   = PdfInfo::Metadata.read(temp_file)
  if .encrypted?
    raise Common::Exceptions::UnprocessableEntity.new(detail: I18n.t('errors.messages.uploads.pdf.locked'),
                                                      source: 'ValidatePdf')
  end
  temp_file.rewind
rescue PdfInfo::MetadataReadError
  raise Common::Exceptions::UnprocessableEntity.new(detail: I18n.t('errors.messages.uploads.pdf.invalid'),
                                                    source: 'ValidatePdf')
end

#validate_pdf(file) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'app/uploaders/validate_pdf.rb', line 24

def validate_pdf(file)
  # Skip when the pdf file is generated by DisabilityCompensationJob
  return if file.respond_to?(:fast_track)

  temp_file = file.tempfile
  return unless File.extname(temp_file) == '.pdf' && !temp_file.nil?

  validate temp_file
end