Merge pull request #3704 from betagouv/dev

2019-03-28-03
This commit is contained in:
Frederic Merizen 2019-03-28 18:21:16 +01:00 committed by GitHub
commit b5193e5f54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 25 deletions

View file

@ -2,4 +2,8 @@ class Champs::SiretChamp < Champ
def search_terms def search_terms
etablissement.present? ? etablissement.search_terms : [value] etablissement.present? ? etablissement.search_terms : [value]
end end
def mandatory_and_blank?
mandatory? && Siret.new(siret: value).invalid?
end
end end

View file

@ -193,16 +193,6 @@ class Procedure < ApplicationRecord
end end
end end
def clone_attachments(original, kopy)
if original.is_a?(TypeDeChamp) && original.piece_justificative_template.attached?
kopy.piece_justificative_template.attach({
io: StringIO.new(original.piece_justificative_template.download),
filename: original.piece_justificative_template.blob.filename,
content_type: original.piece_justificative_template.blob.content_type
})
end
end
def clone(admin, from_library) def clone(admin, from_library)
is_different_admin = !admin.owns?(self) is_different_admin = !admin.owns?(self)
@ -222,8 +212,6 @@ class Procedure < ApplicationRecord
procedure.remote_logo_url = self.logo_url procedure.remote_logo_url = self.logo_url
procedure.lien_notice = nil procedure.lien_notice = nil
[:notice, :deliberation].each { |attachment| clone_attachment(procedure, attachment) }
procedure.types_de_champ += PiecesJustificativesService.types_pj_as_types_de_champ(self) procedure.types_de_champ += PiecesJustificativesService.types_pj_as_types_de_champ(self)
if is_different_admin || from_library if is_different_admin || from_library
procedure.types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) } procedure.types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) }
@ -255,6 +243,26 @@ class Procedure < ApplicationRecord
procedure procedure
end end
def clone_attachments(original, kopy)
if original.is_a?(TypeDeChamp)
clone_attachment(:piece_justificative_template, original, kopy)
elsif original.is_a?(Procedure)
clone_attachment(:notice, original, kopy)
clone_attachment(:deliberation, original, kopy)
end
end
def clone_attachment(attribute, original, kopy)
original_attachment = original.send(attribute)
if original_attachment.attached?
kopy.send(attribute).attach({
io: StringIO.new(original_attachment.download),
filename: original_attachment.blob.filename,
content_type: original_attachment.blob.content_type
})
end
end
def whitelisted? def whitelisted?
whitelisted_at.present? whitelisted_at.present?
end end
@ -455,16 +463,6 @@ class Procedure < ApplicationRecord
true true
end end
def clone_attachment(cloned_procedure, attachment_symbol)
attachment = send(attachment_symbol)
if attachment.attached?
cloned_procedure.send(attachment_symbol).attach(
io: StringIO.new(attachment.download),
filename: attachment.filename
)
end
end
def check_juridique def check_juridique
if juridique_required? && (cadre_juridique.blank? && !deliberation.attached?) if juridique_required? && (cadre_juridique.blank? && !deliberation.attached?)
errors.add(:cadre_juridique, " : veuillez remplir le texte de loi ou la délibération") errors.add(:cadre_juridique, " : veuillez remplir le texte de loi ou la délibération")

View file

@ -37,12 +37,12 @@ class PieceJustificativeToChampPieceJointeMigrationService
pj = dossier.retrieve_last_piece_justificative_by_type(type_pj_id) pj = dossier.retrieve_last_piece_justificative_by_type(type_pj_id)
if pj.present? if pj.present?
convert_pj_to_champ!(pj, champ)
champ.update( champ.update(
updated_at: pj.updated_at, updated_at: pj.updated_at,
created_at: pj.created_at created_at: pj.created_at
) )
convert_pj_to_champ!(pj, champ)
else else
champ.update( champ.update(
updated_at: dossier.updated_at, updated_at: dossier.updated_at,

View file

@ -2,7 +2,9 @@
placeholder: champ.libelle, placeholder: champ.libelle,
class: 'small-margin', class: 'small-margin',
data: { remote: true, debounce: true, url: champs_siret_path(form.index), params: { champ_id: champ&.id }.to_query, spinner: true }, data: { remote: true, debounce: true, url: champs_siret_path(form.index), params: { champ_id: champ&.id }.to_query, spinner: true },
required: champ.mandatory? required: champ.mandatory?,
pattern: "[0-9]{14}",
title: "Le numéro de SIRET doit comporter exactement 14 chiffres"
.spinner.right-spinner.hidden .spinner.right-spinner.hidden
%div{ class: "siret-info-#{form.index}" } %div{ class: "siret-info-#{form.index}" }
- if champ.etablissement.present? - if champ.etablissement.present?

View file

@ -858,6 +858,33 @@ describe Dossier do
end end
end end
context "with mandatory SIRET champ" do
let(:type_de_champ) { create(:type_de_champ_siret, mandatory: true) }
let(:champ_siret) { create(:champ_siret, type_de_champ: type_de_champ) }
before do
dossier.champs << champ_siret
end
it 'should not have errors' do
errors = dossier.check_mandatory_champs
expect(errors).to be_empty
end
context "and invalid SIRET" do
before do
champ_siret.update(value: "1234")
dossier.reload
end
it 'should have errors' do
errors = dossier.check_mandatory_champs
expect(errors).not_to be_empty
expect(errors.first).to eq("Le champ #{champ_siret.libelle} doit être rempli.")
end
end
end
context "with champ repetition" do context "with champ repetition" do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, mandatory: true) } let(:type_de_champ_repetition) { create(:type_de_champ_repetition, mandatory: true) }

View file

@ -489,6 +489,22 @@ describe Procedure do
it 'should duplicate piece_justificative_template on a type_de_champ' do it 'should duplicate piece_justificative_template on a type_de_champ' do
expect(subject.types_de_champ.where(type_champ: "piece_justificative").first.piece_justificative_template.attached?).to be true expect(subject.types_de_champ.where(type_champ: "piece_justificative").first.piece_justificative_template.attached?).to be true
end end
context 'with a notice attached' do
let(:procedure) { create(:procedure, :with_notice, received_mail: received_mail, service: service) }
it 'should duplicate notice' do
expect(subject.notice.attached?).to be true
end
end
context 'with a deliberation attached' do
let(:procedure) { create(:procedure, :with_deliberation, received_mail: received_mail, service: service) }
it 'should duplicate deliberation' do
expect(subject.deliberation.attached?).to be true
end
end
end end
describe '#publish!' do describe '#publish!' do