store attestation fiscale and display

This commit is contained in:
Christophe Robillard 2020-04-29 18:57:30 +02:00
parent 38c68b16e3
commit 3ddb5a4cb4
6 changed files with 45 additions and 6 deletions

View file

@ -5,6 +5,7 @@ class Etablissement < ApplicationRecord
has_many :exercices, dependent: :destroy
has_one_attached :entreprise_attestation_sociale
has_one_attached :entreprise_attestation_fiscale
accepts_nested_attributes_for :exercices
@ -116,12 +117,12 @@ class Etablissement < ApplicationRecord
)
end
def upload_attestation_sociale(url)
def upload_attestation(url, attestation)
filename = File.basename(URI.parse(url).path)
response = Typhoeus.get(url)
if response.success?
entreprise_attestation_sociale.attach(
attestation.attach(
io: StringIO.new(response.body),
filename: filename,
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
@ -129,6 +130,14 @@ class Etablissement < ApplicationRecord
end
end
def upload_attestation_sociale(url)
upload_attestation(url, entreprise_attestation_sociale)
end
def upload_attestation_fiscale(url)
upload_attestation(url, entreprise_attestation_fiscale)
end
private
def dossier_id_for_export