Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-04-20 16:52:11 +02:00
commit dbd92efcd9
21 changed files with 225 additions and 67 deletions

View file

@ -11,8 +11,18 @@ class CommentairesController < ApplicationController
@commentaire.dossier.next_step! 'user', 'comment' if current_user.email == @commentaire.dossier.user.email
end
unless params[:piece_justificative].nil?
pj = PiecesJustificativesService.upload_one! @commentaire.dossier, current_user, params
if pj.errors.empty?
@commentaire.piece_justificative = pj
else
flash.alert = pj.errors.full_messages.join("<br>").html_safe
end
end
@commentaire.body = params['texte_commentaire']
@commentaire.save
@commentaire.save unless flash.alert
if is_gestionnaire?
NotificationMailer.new_answer(@commentaire.dossier).deliver_now!

View file

@ -1,3 +1,5 @@
class Commentaire < ActiveRecord::Base
belongs_to :dossier
belongs_to :piece_justificative
end

View file

@ -1,6 +1,7 @@
class PieceJustificative < ActiveRecord::Base
belongs_to :dossier
belongs_to :type_de_piece_justificative
has_one :commentaire
belongs_to :user
@ -10,6 +11,7 @@ class PieceJustificative < ActiveRecord::Base
mount_uploader :content, PieceJustificativeUploader
validates :content, :file_size => {:maximum => 3.megabytes}
validates :content, presence: true, allow_blank: false, allow_nil: false
def empty?
content.blank?
@ -17,7 +19,22 @@ class PieceJustificative < ActiveRecord::Base
def content_url
unless content.url.nil?
(Downloader.new content, type_de_piece_justificative.libelle).url
(Downloader.new content,
(type_de_piece_justificative.nil? ? content.file.original_filename : type_de_piece_justificative.libelle)).url
end
end
def self.accept_format
" application/pdf,
application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.oasis.opendocument.text,
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet
"
end
end

View file

@ -1,6 +1,10 @@
class ClamavService
def self.safe_file? path_file
if Rails.env == 'development'
return CLAMAV[:response] if CLAMAV[:mock?]
end
FileUtils.chmod 0666, path_file
client = ClamAV::Client.new

View file

@ -21,4 +21,20 @@ class PiecesJustificativesService
end
errors
end
def self.upload_one! dossier, user, params
if ClamavService.safe_file? params[:piece_justificative][:content].path
piece_justificative = PieceJustificative.new(content: params[:piece_justificative][:content],
dossier: dossier,
type_de_piece_justificative: nil,
user: user)
piece_justificative.save
else
piece_justificative = PieceJustificative.new
piece_justificative.errors.add(:content, params[:piece_justificative][:content].original_filename+": <b>Virus détecté !!</b>")
end
piece_justificative
end
end

View file

@ -46,8 +46,8 @@
%br
.row{style: 'text-align:right'}
-if !@facade.dossier.validated? && !@facade.dossier.submitted? && !@facade.dossier.closed?
- if user_signed_in?
- if !@facade.dossier.validated? && !@facade.dossier.submitted? && !@facade.dossier.closed?
- if user_signed_in? && (current_user.email == @facade.dossier.user.email)
- if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0
%a.btn.btn-success{"data-target" => "#UploadPJmodal",
"data-toggle" => "modal",
@ -57,18 +57,19 @@
%br
= render partial: 'users/recapitulatif/modal_upload_pj'
- if(current_user.email == @facade.dossier.user.email)
-if @facade.dossier.procedure.module_api_carto.use_api_carto
%a#maj_carte.btn.btn-primary{href: "/users/dossiers/#{@facade.dossier.id}/carte"}
= 'Modifier ma carte'
%a#maj_infos.btn.btn-info{href: "/users/dossiers/#{@facade.dossier.id}/description"}
= 'Modifier mon dossier'
-if @facade.dossier.procedure.module_api_carto.use_api_carto
%a#maj_carte.btn.btn-primary{href: "/users/dossiers/#{@facade.dossier.id}/carte"}
= 'Modifier ma carte'
%a#maj_infos.btn.btn-info{href: "/users/dossiers/#{@facade.dossier.id}/description"}
= 'Modifier mon dossier'
-if gestionnaire_signed_in?
-if !@facade.dossier.validated? && !@facade.dossier.submitted? && !@facade.dossier.closed?
= form_tag(url_for({controller: 'backoffice/dossiers', action: :valid, dossier_id: @facade.dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success
= 'Valider le dossier'
-elsif @facade.dossier.submitted?
= form_tag(url_for({controller: 'backoffice/dossiers', action: :close, dossier_id: @facade.dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success

View file

@ -8,27 +8,9 @@
-if @dossier.cerfa_available?
%span.btn.btn-sm.btn-file.btn-success
Modifier
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: "application/pdf,
application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.oasis.opendocument.text,
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes }
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: PieceJustificative.accept_format, :max_file_size => 3.megabytes }
-else
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: "application/pdf,
application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.oasis.opendocument.text,
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes }
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: PieceJustificative.accept_format, :max_file_size => 3.megabytes }
- @dossier.types_de_piece_justificative.each do |type_de_piece_justificative|
%tr
@ -39,27 +21,9 @@
%span.text-success{ id: "piece_justificative_#{type_de_piece_justificative.id}" } Nous l'avons récupéré pour vous.
-else
-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,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.oasis.opendocument.text,
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes
= file_field_tag "piece_justificative_#{type_de_piece_justificative.id}", accept: PieceJustificative.accept_format, :max_file_size => 3.megabytes
-else
%span.btn.btn-sm.btn-file.btn-success
Modifier
= 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,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.oasis.opendocument.text,
application/vnd.oasis.opendocument.presentation,
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes
= file_field_tag "piece_justificative_#{type_de_piece_justificative.id}", accept: PieceJustificative.accept_format, :max_file_size => 3.megabytes

View file

@ -1,10 +1,10 @@
.content#commentaires_flux{style:'width:100%;'}
%div#commentaire_new{style: 'width:80%; margin-left:auto; margin-right:auto'}
= form_tag(url_for({ controller: 'commentaires', action: :create, dossier_id: @facade.dossier.id }), class: 'form-inline', method: 'POST') do
%textarea.form-control{id: 'texte_commentaire', class: 'wysihtml5', name: 'texte_commentaire', style: 'width: 100%; margin-bottom:2%', rows: '5', placeholder:"Dialoguer avec votre interlocuteur privilégié en charge de votre dossier."}
%div#commentaire_new{style: 'width:80%; margin-left:auto; margin-right:auto; margin-bottom:7%'}
= form_tag(url_for({ controller: 'commentaires', action: :create, dossier_id: @facade.dossier.id }), class: 'form-inline', method: 'POST', multipart: true) do
%textarea.form-control{id: 'texte_commentaire', class: 'wysihtml5', name: 'texte_commentaire', style: 'width: 100%; margin-bottom:2%', rows: '5', placeholder:"Commentaire"}
%h4.text-primary{style: 'margin-top: 0px'} Ajout un fichier
= file_field_tag "piece_justificative[content]", accept: PieceJustificative.accept_format, style: 'float: left; margin-left: 20px'
%input.form-control.btn.btn-success{:type => 'submit', :value => 'Poster', style: 'float:right'}
%br
%br
-@facade.commentaires.each do |com|
%span.text-info#email_contact{style: 'font-weight:bold'}
@ -12,7 +12,15 @@
%span#created_at
\-
=com.created_at_fr
- unless com.piece_justificative.nil?
\-
%span#piece_justificative
%b
= link_to com.piece_justificative.content.file.original_filename, com.piece_justificative.content_url, style:'color: green', target: '_blank'
%br
.description#body
=com.body.html_safe
%br

View file

@ -36,4 +36,6 @@
%br
= render partial: '/dossiers/infos_dossier'
%br
= render partial: '/users/recapitulatif/commentaires_flux'

View file

@ -0,0 +1,4 @@
CLAMAV = Hashie::Mash.new ({
mock?: true,
response: true
})

View file

@ -0,0 +1,5 @@
class AddPieceJustificativeReferenceToCommentaire < ActiveRecord::Migration
def change
add_reference :commentaires, :piece_justificative, references: :piece_justificatives
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: 20160317153115) do
ActiveRecord::Schema.define(version: 20160419142017) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -84,10 +84,11 @@ ActiveRecord::Schema.define(version: 20160317153115) do
create_table "commentaires", force: :cascade do |t|
t.string "email"
t.datetime "created_at", null: false
t.datetime "created_at", null: false
t.string "body"
t.integer "dossier_id"
t.datetime "updated_at", null: false
t.datetime "updated_at", null: false
t.integer "piece_justificative_id"
end
add_index "commentaires", ["dossier_id"], name: "index_commentaires_on_dossier_id", using: :btree

View file

@ -181,7 +181,7 @@ describe API::V1::DossiersController do
describe 'piece justificative' do
before do
create :piece_justificative, dossier: dossier, type_de_piece_justificative: dossier.procedure.types_de_piece_justificative.first, user: dossier.user
create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative: dossier.procedure.types_de_piece_justificative.first, user: dossier.user
end
let(:field_list) { [

View file

@ -6,6 +6,10 @@ describe Backoffice::CommentairesController, type: :controller do
let(:email_commentaire) { 'test@test.com' }
let(:texte_commentaire) { 'Commentaire de test' }
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
end
describe '#POST create' do
before do
sign_in create(:gestionnaire)
@ -17,6 +21,52 @@ describe Backoffice::CommentairesController, type: :controller do
end
end
context 'when document is upload whith a commentaire' do
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
subject do
post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire, piece_justificative: {content: document_upload}
end
it 'create a new piece justificative' do
expect { subject }.to change(PieceJustificative, :count).by(1)
end
it 'clamav check the pj' do
expect(ClamavService).to receive(:safe_file?)
subject
end
describe 'piece justificative created' do
let(:pj) { PieceJustificative.last }
before do
subject
end
it 'not have a type de pj' do
expect(pj.type_de_piece_justificative).to be_nil
end
it 'content not be nil' do
expect(pj.content).not_to be_nil
end
end
describe 'commentaire created' do
let(:commentaire) { Commentaire.last }
before do
subject
end
it 'have a piece justificative reference' do
expect(commentaire.piece_justificative).not_to be_nil
expect(commentaire.piece_justificative).to eq PieceJustificative.last
end
end
end
describe 'change dossier state after post a comment' do
context 'gestionnaire is connected' do
context 'when dossier is at state updated' do

View file

@ -6,6 +6,10 @@ describe Users::CommentairesController, type: :controller do
let(:email_commentaire) { 'test@test.com' }
let(:texte_commentaire) { 'Commentaire de test' }
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
end
describe '#POST create' do
context 'création correct d\'un commentaire' do
subject do
@ -26,6 +30,53 @@ describe Users::CommentairesController, type: :controller do
end
end
context 'when document is upload whith a commentaire' do
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
subject do
sign_in dossier.user
post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire, piece_justificative: {content: document_upload}
end
it 'create a new piece justificative' do
expect { subject }.to change(PieceJustificative, :count).by(1)
end
it 'clamav check the pj' do
expect(ClamavService).to receive(:safe_file?)
subject
end
describe 'piece justificative created' do
let(:pj) { PieceJustificative.last }
before do
subject
end
it 'not have a type de pj' do
expect(pj.type_de_piece_justificative).to be_nil
end
it 'content not be nil' do
expect(pj.content).not_to be_nil
end
end
describe 'commentaire created' do
let(:commentaire) { Commentaire.last }
before do
subject
end
it 'have a piece justificative reference' do
expect(commentaire.piece_justificative).not_to be_nil
expect(commentaire.piece_justificative).to eq PieceJustificative.last
end
end
end
describe 'change dossier state after post a comment' do
context 'when user is connected' do
context 'when dossier is at state replied' do
@ -39,7 +90,7 @@ describe Users::CommentairesController, type: :controller do
subject { dossier.state }
it {is_expected.to eq('updated')}
it { is_expected.to eq('updated') }
end
end
end

View file

@ -1,11 +1,11 @@
FactoryGirl.define do
factory :piece_justificative do
trait :rib do
content '/chemin/vers/RIB'
content Rack::Test::UploadedFile.new("./spec/support/files/RIB.pdf", 'application/pdf')
end
trait :contrat do
content '/chemin/vers/Contrat'
content Rack::Test::UploadedFile.new("./spec/support/files/Contrat.pdf", 'application/pdf')
end
end
end

View file

@ -6,4 +6,6 @@ describe Commentaire do
it { is_expected.to have_db_column(:created_at) }
it { is_expected.to have_db_column(:updated_at) }
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:piece_justificative) }
end

View file

@ -10,9 +10,17 @@ describe PieceJustificative do
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:type_de_piece_justificative) }
it { is_expected.to belong_to(:user) }
it { is_expected.to have_one(:commentaire) }
end
describe 'validations' do
context 'content' do
it { is_expected.not_to allow_value(nil).for(:content) }
it { is_expected.not_to allow_value('').for(:content) }
end
end
describe 'delegation' do
it { is_expected.to delegate_method(:libelle).to(:type_de_piece_justificative) }
it { is_expected.to delegate_method(:api_entreprise).to(:type_de_piece_justificative) }
@ -21,10 +29,7 @@ describe PieceJustificative do
describe '#empty?' do
let(:piece_justificative) { create(:piece_justificative, content: content) }
subject { piece_justificative.empty? }
context 'when content is nil' do
let(:content) { nil }
it { is_expected.to be_truthy }
end
context 'when content exist' do
let(:content) { File.open('./spec/support/files/piece_justificative_388.pdf') }
it { is_expected.to be_falsey }

Binary file not shown.

BIN
spec/support/files/RIB.pdf Normal file

Binary file not shown.

View file

@ -4,7 +4,11 @@ describe 'users/recapitulatif/_commentaires_flux.html.haml', type: :view do
let(:dossier) { create(:dossier) }
let(:dossier_id) { dossier.id }
let(:email_commentaire) { 'mon_mail_de_commentaire@test.com' }
let!(:commentaire) { create(:commentaire, dossier: dossier, email: email_commentaire, body: 'ma super description') }
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
let(:pj) { create :piece_justificative, content: document_upload }
let!(:commentaire) { create(:commentaire, dossier: dossier, email: email_commentaire, body: 'ma super description', piece_justificative: pj) }
let(:body) { 'Commentaire de test' }
before do
@ -24,6 +28,12 @@ describe 'users/recapitulatif/_commentaires_flux.html.haml', type: :view do
it 'le corps du commentaire est présent' do
expect(rendered).to have_selector('div[class=description][id=body]')
end
context 'when commentaire as PJ' do
it 'commentaire present the link' do
expect(rendered).to have_css('#piece_justificative')
end
end
end
context 'Affichage du formulaire de commentaire' do
@ -34,5 +44,11 @@ describe 'users/recapitulatif/_commentaires_flux.html.haml', type: :view do
it 'Champs de texte' do
expect(rendered).to have_selector('textarea[id=texte_commentaire][name=texte_commentaire]')
end
describe 'File input' do
it 'have file_input tag' do
expect(rendered).to have_css('#piece_justificative_content')
end
end
end
end