Procedure: add deliberation
This commit is contained in:
parent
a96889310b
commit
fa14db1cbf
4 changed files with 45 additions and 3 deletions
|
@ -224,7 +224,7 @@ class Admin::ProceduresController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def procedure_params
|
def procedure_params
|
||||||
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on]
|
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on]
|
||||||
if @procedure&.locked?
|
if @procedure&.locked?
|
||||||
params.require(:procedure).permit(*editable_params)
|
params.require(:procedure).permit(*editable_params)
|
||||||
else
|
else
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Procedure < ApplicationRecord
|
||||||
has_one :without_continuation_mail, class_name: "Mails::WithoutContinuationMail", dependent: :destroy
|
has_one :without_continuation_mail, class_name: "Mails::WithoutContinuationMail", dependent: :destroy
|
||||||
|
|
||||||
has_one_attached :notice
|
has_one_attached :notice
|
||||||
|
has_one_attached :deliberation
|
||||||
|
|
||||||
delegate :use_api_carto, to: :module_api_carto
|
delegate :use_api_carto, to: :module_api_carto
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :cadre_juridique, presence: true, allow_blank: false, allow_nil: false
|
validate :check_juridique
|
||||||
|
|
||||||
include AASM
|
include AASM
|
||||||
|
|
||||||
|
@ -350,6 +351,12 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def check_juridique
|
||||||
|
if cadre_juridique.blank? && !deliberation.attached?
|
||||||
|
errors.add(:cadre_juridique, " : veuillez remplir le texte de loi ou la délibération")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def field_hash(label, table, column)
|
def field_hash(label, table, column)
|
||||||
{
|
{
|
||||||
'label' => label,
|
'label' => label,
|
||||||
|
|
|
@ -22,9 +22,24 @@
|
||||||
= f.text_field :web_hook_url, class: 'form-control', placeholder: 'https://callback.exemple.fr/'
|
= f.text_field :web_hook_url, class: 'form-control', placeholder: 'https://callback.exemple.fr/'
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
%h4 Cadre juridique : indiquez la référence ou l'URL du texte juridique ou chargez la délibération qui justifie cette procédure *
|
%h4 Cadre juridique *
|
||||||
|
%p Indiquez la référence ou l'URL du texte juridique ou chargez la délibération qui justifie cette procédure
|
||||||
|
= f.label :cadre_juridique, 'Référence ou texte de loi'
|
||||||
= f.text_field :cadre_juridique, class: 'form-control', placeholder: 'https://www.legifrance.gouv.fr/'
|
= f.text_field :cadre_juridique, class: 'form-control', placeholder: 'https://www.legifrance.gouv.fr/'
|
||||||
|
|
||||||
|
= f.label :deliberation, 'Délibération'
|
||||||
|
- deliberation = @procedure.deliberation
|
||||||
|
- if !deliberation.attached?
|
||||||
|
= f.file_field :deliberation,
|
||||||
|
direct_upload: true
|
||||||
|
- else
|
||||||
|
%a{ href: url_for(deliberation), target: '_blank' }
|
||||||
|
= deliberation.filename.to_s
|
||||||
|
%br
|
||||||
|
Modifier :
|
||||||
|
= f.file_field :deliberation,
|
||||||
|
direct_upload: true
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
%h4 Notice explicative de la procédure
|
%h4 Notice explicative de la procédure
|
||||||
- notice = @procedure.notice
|
- notice = @procedure.notice
|
||||||
|
|
|
@ -173,6 +173,26 @@ describe Procedure do
|
||||||
context 'organisation' do
|
context 'organisation' do
|
||||||
it { is_expected.to allow_value('URRSAF').for(:organisation) }
|
it { is_expected.to allow_value('URRSAF').for(:organisation) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'juridique' do
|
||||||
|
it { is_expected.not_to allow_value(nil).for(:cadre_juridique) }
|
||||||
|
it { is_expected.to allow_value('text').for(:cadre_juridique) }
|
||||||
|
|
||||||
|
context 'with deliberation' do
|
||||||
|
let(:procedure) { build(:procedure, cadre_juridique: nil) }
|
||||||
|
|
||||||
|
it { expect(procedure.valid?).to eq(false) }
|
||||||
|
|
||||||
|
context 'when the deliberation is uploaded ' do
|
||||||
|
before do
|
||||||
|
allow(procedure).to receive(:deliberation)
|
||||||
|
.and_return(double('attached?': true))
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(procedure.valid?).to eq(true) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#types_de_champ_ordered' do
|
describe '#types_de_champ_ordered' do
|
||||||
|
|
Loading…
Reference in a new issue