Add attestation url to dossier on api
This commit is contained in:
parent
fd977a4a84
commit
fba195c0b5
4 changed files with 31 additions and 8 deletions
|
@ -2,4 +2,13 @@ class Attestation < ApplicationRecord
|
|||
belongs_to :dossier
|
||||
|
||||
mount_uploader :pdf, AttestationUploader
|
||||
|
||||
def pdf_url
|
||||
if Rails.application.secrets.fog[:enabled]
|
||||
RemoteDownloader.new(pdf.path).url
|
||||
elsif pdf&.url
|
||||
# FIXME: this is horrible but used only in dev and will be removed after migration
|
||||
File.join(LOCAL_DOWNLOAD_URL, pdf.url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -144,7 +144,9 @@ class Dossier < ApplicationRecord
|
|||
:etablissement,
|
||||
piece_justificative_file_attachment: :blob
|
||||
],
|
||||
avis: [],
|
||||
justificatif_motivation_attachment: :blob,
|
||||
attestation: [],
|
||||
avis: { piece_justificative_file_attachment: :blob },
|
||||
etablissement: [],
|
||||
individual: [],
|
||||
user: [])
|
||||
|
|
|
@ -14,6 +14,9 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
:motivation,
|
||||
:instructeurs
|
||||
|
||||
attribute :attestation, if: :include_attestation?
|
||||
attribute :justificatif_motivation, if: :include_justificatif_motivation?
|
||||
|
||||
has_one :individual
|
||||
has_one :entreprise
|
||||
has_one :etablissement
|
||||
|
@ -22,7 +25,6 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
has_many :champs_private
|
||||
has_many :pieces_justificatives
|
||||
has_many :types_de_piece_justificative
|
||||
has_one :justificatif_motivation
|
||||
has_many :avis
|
||||
|
||||
has_many :champs, serializer: ChampSerializer
|
||||
|
@ -53,10 +55,12 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
PiecesJustificativesService.serialize_champs_as_pjs(object)
|
||||
end
|
||||
|
||||
def attestation
|
||||
object.attestation.pdf_url
|
||||
end
|
||||
|
||||
def justificatif_motivation
|
||||
if object.justificatif_motivation.attached?
|
||||
Rails.application.routes.url_helpers.url_for(object.justificatif_motivation)
|
||||
end
|
||||
Rails.application.routes.url_helpers.url_for(object.justificatif_motivation)
|
||||
end
|
||||
|
||||
def types_de_piece_justificative
|
||||
|
@ -102,4 +106,12 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
def processed_at
|
||||
object.processed_at&.in_time_zone('UTC')
|
||||
end
|
||||
|
||||
def include_attestation?
|
||||
object.accepte?
|
||||
end
|
||||
|
||||
def include_justificatif_motivation?
|
||||
object.justificatif_motivation.attached?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -154,10 +154,10 @@ describe API::V1::DossiersController do
|
|||
context 'when dossier exists and belongs to procedure' do
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:date_creation) { Time.zone.local(2008, 9, 1, 10, 5, 0) }
|
||||
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :en_construction, procedure: procedure, motivation: "Motivation") } }
|
||||
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :with_attestation, :accepte, procedure: procedure, motivation: "Motivation") } }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
|
||||
let(:field_list) { [:id, :created_at, :updated_at, :archived, :individual, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :email, :instructeurs, :justificatif_motivation, :avis] }
|
||||
let(:field_list) { [:id, :created_at, :updated_at, :archived, :individual, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :email, :instructeurs, :attestation, :avis] }
|
||||
subject { body[:dossier] }
|
||||
|
||||
it 'return REST code 200', :show_in_doc do
|
||||
|
@ -165,7 +165,7 @@ describe API::V1::DossiersController do
|
|||
end
|
||||
|
||||
it { expect(subject[:id]).to eq(dossier.id) }
|
||||
it { expect(subject[:state]).to eq('initiated') }
|
||||
it { expect(subject[:state]).to eq('closed') }
|
||||
it { expect(subject[:created_at]).to eq('2008-09-01T08:05:00.000Z') }
|
||||
it { expect(subject[:updated_at]).to eq('2008-09-01T08:05:00.000Z') }
|
||||
it { expect(subject[:archived]).to eq(dossier.archived) }
|
||||
|
|
Loading…
Reference in a new issue