Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-03-17 15:05:57 +01:00
commit 751a62b6db
19 changed files with 185 additions and 116 deletions

View file

@ -0,0 +1,16 @@
$(document).on('page:load', modal_action);
$(document).ready(modal_action);
function modal_action() {
$('#PJmodal').on('show.bs.modal', function (event) {
$("#PJmodal .modal-body .table .tr_content").hide();
var button = $(event.relatedTarget) // Button that triggered the modal
var modal_title = button.data('modal_title'); // Extract info from data-* attributes
var modal_index = button.data('modal_index'); // Extract info from data-* attributes
var modal = $(this)
modal.find('#PJmodal_title').html(modal_title);
$("#PJmodal .modal-body .table #"+modal_index).show();
})
}

View file

@ -0,0 +1,9 @@
#PJmodal {
.modal-body {
.table {
.tr_content {
display: none;
}
}
}
}

View file

@ -11,7 +11,6 @@ class API::V1::DossiersController < APIController
EOS
meta champs: {
}
def index

View file

@ -34,8 +34,7 @@ class Users::DescriptionController < UsersController
if @procedure.cerfa_flag?
unless params[:cerfa_pdf].nil?
cerfa = @dossier.cerfa
cerfa.content = params[:cerfa_pdf]
cerfa = Cerfa.new(content: params[:cerfa_pdf], dossier: @dossier)
unless cerfa.save
flash.now.alert = cerfa.errors.full_messages.join('<br />').html_safe
return render 'show'
@ -56,9 +55,13 @@ class Users::DescriptionController < UsersController
end
end
@dossier.pieces_justificatives.each do |piece_justificative|
unless params["piece_justificative_#{piece_justificative.type}"].nil?
piece_justificative.content = params["piece_justificative_#{piece_justificative.type}"]
@dossier.types_de_piece_justificative.each do |type_de_pieces_justificatives|
unless params["piece_justificative_#{type_de_pieces_justificatives.id}"].nil?
piece_justificative = PieceJustificative.new(content: params["piece_justificative_#{type_de_pieces_justificatives.id}"],
dossier: @dossier,
type_de_piece_justificative: type_de_pieces_justificatives)
unless piece_justificative.save
flash.now.alert = piece_justificative.errors.full_messages.join('<br />').html_safe
return render 'show'

View file

@ -38,6 +38,10 @@ class DossierFacades
@dossier.procedure
end
def cerfas_ordered
@dossier.cerfa.order('created_at DESC')
end
def invites
@dossier.invites
end

View file

@ -10,7 +10,7 @@ class Dossier < ActiveRecord::Base
has_one :etablissement, dependent: :destroy
has_one :entreprise, dependent: :destroy
has_one :cerfa, dependent: :destroy
has_many :cerfa, dependent: :destroy
has_many :pieces_justificatives, dependent: :destroy
has_many :champs, dependent: :destroy
@ -27,8 +27,6 @@ class Dossier < ActiveRecord::Base
delegate :types_de_piece_justificative, to: :procedure
delegate :types_de_champ, to: :procedure
after_save :build_default_cerfa, if: Proc.new { procedure.cerfa_flag? && procedure_id_changed? }
after_save :build_default_pieces_justificatives, if: Proc.new { procedure_id_changed? }
after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
validates :nom_projet, presence: true, allow_blank: false, allow_nil: true
@ -39,15 +37,12 @@ class Dossier < ActiveRecord::Base
WAITING_FOR_USER = %w(replied validated)
TERMINE = %w(closed)
def retrieve_piece_justificative_by_type(type)
def retrieve_last_piece_justificative_by_type(type)
pieces_justificatives.where(type_de_piece_justificative_id: type).last
end
def build_default_pieces_justificatives
procedure.types_de_piece_justificative.each do |type_de_piece_justificative|
PieceJustificative.create(type_de_piece_justificative_id: type_de_piece_justificative.id, dossier_id: id)
end
def retrieve_all_piece_justificative_by_type(type)
pieces_justificatives.where(type_de_piece_justificative_id: type)
end
def build_default_champs
@ -190,7 +185,7 @@ class Dossier < ActiveRecord::Base
end
def cerfa_available?
procedure.cerfa_flag? && !cerfa.empty?
procedure.cerfa_flag? && cerfa.size != 0
end
def as_csv(options={})
@ -199,12 +194,4 @@ class Dossier < ActiveRecord::Base
entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map {|k, v| ["entreprise.#{k}", v] }.to_h
dossier_attr.merge(etablissement_attr).merge(entreprise_attr)
end
private
def build_default_cerfa
create_cerfa
true
end
end

View file

@ -9,8 +9,8 @@ class DossierSerializer < ActiveModel::Serializer
has_one :entreprise
has_one :etablissement
has_one :cerfa
has_many :cerfa
has_many :commentaires
has_many :champs
has_many :pieces_justificatives
has_many :types_de_piece_justificative
end

View file

@ -2,5 +2,4 @@ class PieceJustificativeSerializer < ActiveModel::Serializer
attributes :created_at,
:content_url => :url
has_one :type_de_piece_justificative
end

View file

@ -2,4 +2,6 @@ class TypeDePieceJustificativeSerializer < ActiveModel::Serializer
attributes :id,
:libelle,
:description
has_many :pieces_justificatives
end

View file

@ -0,0 +1,43 @@
#PJmodal.modal.fade{"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
.modal-dialog.modal-lg{:role => "document"}
.modal-content
.modal-header
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
%span{"aria-hidden" => "true"} ×
%h4#myModalLabel.modal-title
Historique des
%span#PJmodal_title
.modal-body
%table.table
%thead
%th
Utilisateur
%th
Date d'envoi
%th
Lien
%thead.tr_content#cerfa
-if @facade.procedure.cerfa_flag?
- if @facade.dossier.cerfa_available?
- @facade.cerfas_ordered.each do |cerfa|
%tr
%td.col-md-6.col-lg-4
= cerfa.dossier.user.email
%td.col-md-6.col-lg-4
= cerfa.created_at
%td.col-md-6.col-lg-4
=link_to 'Récupérer', cerfa.content_url, {target: :blank}
- @facade.dossier.types_de_piece_justificative.each do |type_de_piece_justificative|
%tbody.tr_content{id: "type_de_pj_#{type_de_piece_justificative.id}"}
- @facade.dossier.retrieve_all_piece_justificative_by_type(type_de_piece_justificative.id).each do |piece_justificative|
%tr
%td.col-md-6.col-lg-4
= piece_justificative.dossier.user.email
%td.col-md-6.col-lg-4
= piece_justificative.created_at
%td.col-md-6.col-lg-4
=link_to 'Récupérer', piece_justificative.content_url, {target: :blank}
.modal-footer

View file

@ -1,6 +1,4 @@
#pieces_justificatives
-#%h3.text-info Liste des pièces justificatives
-#%br
%table.table
-if @facade.procedure.cerfa_flag?
@ -12,23 +10,40 @@
- if user_signed_in?
= 'Pièce fournie'
- elsif gestionnaire_signed_in?
%a{ href: "#{@facade.dossier.cerfa.content_url}", target: '_blank' } Consulter
%a{ href: "#{@facade.dossier.cerfa.last.content_url}", target: '_blank' } Consulter
%span{style:'margin-left:12px'}
\-
%a.btn.glyphicon.glyphicon-time{style:'color: black; padding-top: 0',
"data-target" => "#PJmodal",
"data-toggle" => "modal",
:type => "button",
"data-modal_title" => 'formulaires',
"data-modal_index" => 'cerfa'}
- else
= 'Pièce non fournie'
- @facade.dossier.pieces_justificatives.each do |piece_justificative|
%tr{ id: "piece_justificative_#{piece_justificative.type}" }
- @facade.dossier.types_de_piece_justificative.each do |type_de_piece_justificative|
%tr{ id: "piece_justificative_#{type_de_piece_justificative.id}" }
%th.col-lg-6
= piece_justificative.libelle
= type_de_piece_justificative.libelle
%td.col-lg-6.col-md-6
- if piece_justificative.api_entreprise
- if type_de_piece_justificative.api_entreprise
%span.text-success Nous l'avons récupéré pour vous.
- elsif !piece_justificative.empty?
- elsif !(@pj = @facade.dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id)).nil?
- if user_signed_in?
= 'Pièce fournie'
- elsif gestionnaire_signed_in?
%a{ href: "#{piece_justificative.content_url}", target: '_blank' } Consulter
%a{ href: "#{@pj.content_url}", target: '_blank' } Consulter
%span{style:'margin-left:12px'}
\-
%a.btn.glyphicon.glyphicon-time{style:'color: black; padding-top: 0',
"data-target" => "#PJmodal",
"data-toggle" => "modal",
:type => "button",
"data-modal_title" => type_de_piece_justificative.libelle,
"data-modal_index" => "type_de_pj_#{type_de_piece_justificative.id}"}
- else
= 'Pièce non fournie'
- if gestionnaire_signed_in?
=render partial: '/dossiers/modal_historique'

View file

@ -94,16 +94,16 @@
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes }
- @dossier.pieces_justificatives.each do |piece_justificative|
- @dossier.types_de_piece_justificative.each do |type_de_piece_justificative|
%tr
%th.col-lg-6
= piece_justificative.libelle
= type_de_piece_justificative.libelle
%td.col-lg-5
-if piece_justificative.api_entreprise
%span.text-success{ id: "piece_justificative_#{piece_justificative.type}" } Nous l'avons récupéré pour vous.
-if type_de_piece_justificative.api_entreprise
%span.text-success{ id: "piece_justificative_#{type_de_piece_justificative.id}" } Nous l'avons récupéré pour vous.
-else
-if piece_justificative.empty?
= file_field_tag "piece_justificative_#{piece_justificative.type}", accept: " application/pdf,
-if @dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id).nil?
= file_field_tag "piece_justificative_#{type_de_piece_justificative.id}", accept: " application/pdf,
application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.ms-excel,
@ -116,7 +116,7 @@
-else
%span.btn.btn-sm.btn-file.btn-success
Modifier
= file_field_tag "piece_justificative_#{piece_justificative.type}", accept: " application/pdf,
= file_field_tag "piece_justificative_#{type_de_piece_justificative.id}", accept: " application/pdf,
application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.ms-excel,

View file

@ -0,0 +1,8 @@
class DBremovePieceJustificativeEmpty < ActiveRecord::Migration
class PieceJustificative < ActiveRecord::Base
end
def change
PieceJustificative.where(content: nil).delete_all
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160315101245) do
ActiveRecord::Schema.define(version: 20160317135217) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

View file

@ -116,7 +116,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(retour.body, symbolize_names: true) }
let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :pieces_justificatives, :champs, :commentaires] }
let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :champs, :commentaires] }
subject { body[:dossier] }
it 'return REST code 200', :show_in_doc do
@ -161,30 +161,34 @@ describe API::V1::DossiersController do
it { expect(subject.keys).to match_array(field_list) }
end
describe 'pieces_justificatives' do
let(:field_list) { [
:url] }
subject { super()[:pieces_justificatives] }
describe 'types_de_piece_justificative' do
before do
create :piece_justificative, dossier: dossier, type_de_piece_justificative: dossier.procedure.types_de_piece_justificative.first
end
it { expect(subject.length).to eq 2 }
describe 'first piece justificative' do
subject { super().first }
it { expect(subject.keys.include?(:url)).to be_truthy }
it { expect(subject[:created_at]).not_to be_nil }
it { expect(subject.keys.include?(:type_de_piece_justificative)).to be_truthy }
describe 'type de piece justificative' do
let(:field_list) { [
:id,
:libelle,
:description] }
subject { super()[:type_de_piece_justificative] }
subject { super()[:types_de_piece_justificative] }
it { expect(subject.length).to eq 2 }
describe 'first type de piece justificative' do
subject { super().first }
it { expect(subject.keys.include?(:id)).to be_truthy }
it { expect(subject[:libelle]).to eq('RIB') }
it { expect(subject[:description]).to eq('Releve identité bancaire') }
describe 'piece justificative' do
let(:field_list) { [
:url, :created_at] }
subject {
super()[:pieces_justificatives].first }
it { expect(subject.keys.include?(:url)).to be_truthy }
it { expect(subject[:created_at]).not_to be_nil }
end
end
end
@ -234,14 +238,16 @@ describe API::V1::DossiersController do
end
describe 'cerfa' do
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :with_cerfa_upload, procedure: procedure) } }
let(:content) { File.open('./spec/support/files/piece_justificative_388.pdf') }
before do
dossier.cerfa.content = content
dossier.cerfa.save
tmp_cerfa = dossier.cerfa.first
tmp_cerfa.content = content
tmp_cerfa.save
end
subject { super()[:cerfa] }
subject { super()[:cerfa].first }
it { expect(subject[:created_at]).not_to be_nil }
it { expect(subject[:url]).to match /^http:\/\/.*downloads.*_CERFA\.pdf$/ }

View file

@ -132,8 +132,9 @@ describe Users::DescriptionController, type: :controller do
dossier.reload
end
context 'un CERFA PDF est envoyé' do
subject { dossier.cerfa }
context 'when a CERFA PDF is send' do
subject { dossier.cerfa.first }
it 'content' do
expect(subject['content']).to eq(name_piece_justificative)
end
@ -143,21 +144,17 @@ describe Users::DescriptionController, type: :controller do
end
end
context 'les anciens CERFA PDF sont écrasées à chaque fois' do
let(:cerfas) { Cerfa.find_by_dossier_id(dossier_id) }
context 'les anciens CERFA PDF ne sont pas écrasées' do
let(:cerfas) { Cerfa.where(dossier_id: dossier_id) }
before do
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, cerfa_pdf: cerfa_pdf
end
it 'il n\'y a qu\'un CERFA PDF par dossier' do
expect(cerfas.class).to eq Cerfa
it "il y a deux CERFA PDF pour ce dossier" do
expect(cerfas.size).to eq 2
end
end
context 'pas de CERFA PDF' do
# TODO à écrire
end
end
end
@ -223,11 +220,11 @@ describe Users::DescriptionController, type: :controller do
end
context 'for piece 0' do
subject { dossier.retrieve_piece_justificative_by_type all_pj_type[0].to_s }
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[0].to_s }
it { expect(subject.content).not_to be_nil }
end
context 'for piece 1' do
subject { dossier.retrieve_piece_justificative_by_type all_pj_type[1].to_s }
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[1].to_s }
it { expect(subject.content).not_to be_nil }
end
end

View file

@ -23,23 +23,22 @@ FactoryGirl.define do
trait :with_two_quartier_prioritaires do
after(:build) do |dossier, _evaluator|
qp1 = create(:quartier_prioritaire)
qp2 = create(:quartier_prioritaire)
dossier.quartier_prioritaires << qp1
dossier.quartier_prioritaires << qp2
dossier.quartier_prioritaires << create(:quartier_prioritaire)
dossier.quartier_prioritaires << create(:quartier_prioritaire)
end
end
trait :with_two_cadastres do
after(:build) do |dossier, _evaluator|
dossier.cadastres << create(:cadastre)
dossier.cadastres << create(:cadastre)
end
end
qp1 = create(:cadastre)
qp2 = create(:cadastre)
trait :with_cerfa_upload do
after(:build) do |dossier, _evaluator|
dossier.cadastres << qp1
dossier.cadastres << qp2
dossier.cerfa << create(:cerfa)
end
end
end

View file

@ -42,7 +42,7 @@ feature 'user is on description page' do
end
context 'when he adds a piece_justificative and submit form' do
before do
file_input_id = 'piece_justificative_' + dossier.pieces_justificatives.first.type.to_s
file_input_id = 'piece_justificative_' + dossier.types_de_piece_justificative.first.id.to_s
attach_file(file_input_id, File.path('spec/support/files/dossierPDF.pdf'))
click_on('Soumettre mon dossier')
dossier.reload

View file

@ -20,7 +20,7 @@ describe Dossier do
it { is_expected.to have_many(:commentaires) }
it { is_expected.to have_many(:quartier_prioritaires) }
it { is_expected.to have_many(:cadastres) }
it { is_expected.to have_one(:cerfa) }
it { is_expected.to have_many(:cerfa) }
it { is_expected.to have_one(:etablissement) }
it { is_expected.to have_one(:entreprise) }
it { is_expected.to belong_to(:user) }
@ -88,24 +88,17 @@ describe Dossier do
end
end
describe '#retrieve_piece_justificative_by_type' do
let(:all_dossier_pj_id) { dossier.procedure.types_de_piece_justificative }
subject { dossier.retrieve_piece_justificative_by_type all_dossier_pj_id.first }
describe '#retrieve_last_piece_justificative_by_type' do
let(:types_de_pj_dossier) { dossier.procedure.types_de_piece_justificative }
subject { dossier.retrieve_last_piece_justificative_by_type types_de_pj_dossier.first }
before do
dossier.build_default_pieces_justificatives
create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative: types_de_pj_dossier.first
end
it 'returns piece justificative with given type' do
expect(subject.type).to eq(all_dossier_pj_id.first.id)
end
end
describe '#build_default_pieces_justificatives' do
context 'when dossier is linked to a procedure' do
let(:dossier) { create(:dossier, user: user) }
it 'build all pieces justificatives needed' do
expect(dossier.pieces_justificatives.count).to eq(2)
end
expect(subject.type).to eq(types_de_pj_dossier.first.id)
end
end
@ -123,11 +116,6 @@ describe Dossier do
subject { build(:dossier, procedure: procedure, user: user) }
let!(:procedure) { create(:procedure) }
context 'when is linked to a procedure' do
it 'creates default pieces justificatives' do
expect(subject).to receive(:build_default_pieces_justificatives)
subject.save
end
it 'creates default champs' do
expect(subject).to receive(:build_default_champs)
subject.save
@ -135,10 +123,6 @@ describe Dossier do
end
context 'when is not linked to a procedure' do
subject { create(:dossier, procedure: procedure, user: user) }
it 'does not create default pieces justificatives' do
expect(subject).not_to receive(:build_default_pieces_justificatives)
subject.update_attributes(description: 'plop')
end
it 'does not create default champs' do
expect(subject).not_to receive(:build_default_champs)
@ -525,17 +509,15 @@ describe Dossier do
describe '#cerfa_available?' do
let(:procedure) { create(:procedure, cerfa_flag: cerfa_flag) }
let(:dossier) { create(:dossier, procedure: procedure)}
context 'Procedure accepts CERFA' do
let(:cerfa_flag) { true }
context 'when cerfa is not uploaded' do
it { expect(dossier.cerfa_available?).to be_falsey }
end
context 'when cerfa is uploaded' do
let(:dossier_with_cerfa) { create(:dossier, procedure: procedure) }
before do
allow_any_instance_of(Cerfa).to receive(:empty?).and_return(false)
end
it { expect(dossier_with_cerfa.cerfa_available?).to be_truthy }
let(:dossier) { create :dossier, :with_cerfa_upload, procedure: procedure }
it { expect(dossier.cerfa_available?).to be_truthy }
end
end
context 'Procedure does not accept CERFA' do