From 4993abf5f2027e04a2889d679ca37540a932206e Mon Sep 17 00:00:00 2001 From: Xavier J Date: Fri, 26 Feb 2016 13:59:03 +0100 Subject: [PATCH] Create fonction content_url to make public download link for cerfa and pj --- app/models/cerfa.rb | 8 +++++++- app/models/piece_justificative.rb | 8 +++++++- app/views/dossiers/_pieces_justificatives.html.haml | 4 ++-- spec/controllers/api/v1/dossiers_controller_spec.rb | 2 +- spec/controllers/api/v1/procedures_controller_spec.rb | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/models/cerfa.rb b/app/models/cerfa.rb index 8cf41d61e..bc06b2654 100644 --- a/app/models/cerfa.rb +++ b/app/models/cerfa.rb @@ -2,9 +2,15 @@ class Cerfa < ActiveRecord::Base belongs_to :dossier mount_uploader :content, CerfaUploader - validates :content, :file_size => { :maximum => 3.megabytes } + validates :content, :file_size => {:maximum => 3.megabytes} def empty? content.blank? end + + def content_url + unless content.url.nil? + (Downloader.new content, 'CERFA').url + end + end end \ No newline at end of file diff --git a/app/models/piece_justificative.rb b/app/models/piece_justificative.rb index 2b0780f1f..8cd6d2a80 100644 --- a/app/models/piece_justificative.rb +++ b/app/models/piece_justificative.rb @@ -7,9 +7,15 @@ class PieceJustificative < ActiveRecord::Base alias_attribute :type, :type_de_piece_justificative_id mount_uploader :content, PieceJustificativeUploader - validates :content, :file_size => { :maximum => 3.megabytes } + validates :content, :file_size => {:maximum => 3.megabytes} def empty? content.blank? end + + def content_url + unless content.url.nil? + (Downloader.new content, type_de_piece_justificative.libelle).url + end + end end diff --git a/app/views/dossiers/_pieces_justificatives.html.haml b/app/views/dossiers/_pieces_justificatives.html.haml index 943ff4a26..88ddbf7cc 100644 --- a/app/views/dossiers/_pieces_justificatives.html.haml +++ b/app/views/dossiers/_pieces_justificatives.html.haml @@ -12,7 +12,7 @@ - if user_signed_in? = 'Pièce fournie' - elsif gestionnaire_signed_in? - %a{ href: "#{(Downloader.new @facade.dossier.cerfa.content, 'CERFA').url}", target: '_blank' } Consulter + %a{ href: "#{@facade.dossier.cerfa.content_url}", target: '_blank' } Consulter - else = 'Pièce non fournie' @@ -27,7 +27,7 @@ - if user_signed_in? = 'Pièce fournie' - elsif gestionnaire_signed_in? - %a{ href: "#{(Downloader.new piece_justificative.content, piece_justificative.type_de_piece_justificative.libelle).url}", target: '_blank' } Consulter + %a{ href: "#{piece_justificative.content_url}", target: '_blank' } Consulter - else = 'Pièce non fournie' diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index d463fcaea..0ad2d3f4a 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -114,7 +114,7 @@ describe API::V1::DossiersController do let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let(:dossier_id) { dossier.id } let(:body) { JSON.parse(response.body, symbolize_names: true) } - let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement] } + let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :pieces_justificatives, :champs] } subject { body[:dossier] } it { expect(response.code).to eq('200') } diff --git a/spec/controllers/api/v1/procedures_controller_spec.rb b/spec/controllers/api/v1/procedures_controller_spec.rb index f3a080c6c..475bd44bf 100644 --- a/spec/controllers/api/v1/procedures_controller_spec.rb +++ b/spec/controllers/api/v1/procedures_controller_spec.rb @@ -37,7 +37,7 @@ describe API::V1::ProceduresController do let(:champ) { procedure.types_de_champ.first } it { expect(subject[:id]).to eq(champ.id) } it { expect(subject[:libelle]).to eq(champ.libelle) } - it { expect(subject[:type_champ]).to eq(champ.type_champ) } + it { expect(subject[:type]).to eq(champ.type_champ) } it { expect(subject[:order_place]).to eq(champ.order_place) } it { expect(subject[:description]).to eq(champ.description) } end