feat(sva): block configuration changes when procedure is published
This commit is contained in:
parent
afe373c6b4
commit
eb7f1f199a
8 changed files with 71 additions and 10 deletions
|
@ -8,6 +8,12 @@ class Procedure::SVASVRFormComponent < ApplicationComponent
|
|||
@configuration = configuration
|
||||
end
|
||||
|
||||
def form_disabled?
|
||||
return false if procedure.brouillon?
|
||||
|
||||
procedure.sva_svr_enabled?
|
||||
end
|
||||
|
||||
def decision_buttons
|
||||
scope = ".decision_buttons"
|
||||
|
||||
|
|
|
@ -24,3 +24,4 @@ en:
|
|||
reset_label: "Reset the delay"
|
||||
reset_hint: "Example: if the file is resubmitted on April 15 and the delay is 2 months, the decision will be automatically made on June 15, unless the instructor pronounces in the meantime or asks for corrections again"
|
||||
notice_new_files_only: "Information: if you activate this rule, only the newly submitted files will be subject to it."
|
||||
notice_edit_denied: "Warning: SVA/SVR cannot be changed or disabled."
|
||||
|
|
|
@ -24,3 +24,4 @@ fr:
|
|||
reset_label: "Réinitialiser le délai"
|
||||
reset_hint: "Exemple: si le dossier est re-déposé le 15 avril et que le délai est de 2 mois, la décision sera automatiquement prise le 15 juin, sauf à ce que l’instructeur se prononce d’ici là ou demande à nouveau des corrections"
|
||||
notice_new_files_only: "Information : si vous activez cette règle, seuls les nouveaux dossiers déposés y seront soumis."
|
||||
notice_edit_denied: "Avertissement : le changement ou la désactivation du SVA/SVR est impossible."
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
= form_for [procedure, configuration], url: admin_procedure_sva_svr_path(procedure), method: :put do |f|
|
||||
- if procedure.publiee?
|
||||
- if procedure.publiee? && !procedure.sva_svr_enabled?
|
||||
.fr-alert.fr-alert--info.fr-alert--sm.fr-mb-4w
|
||||
- if procedure.sva_svr_enabled?
|
||||
%p Information : si vous désactivez cette règle, seuls les nouveaux dossiers seront impactés. Ceux déjà déjà déposés la conserveront.
|
||||
- else
|
||||
%p= t('.notice_new_files_only')
|
||||
|
||||
- if procedure.publiee? && procedure.sva_svr_enabled?
|
||||
.fr-alert.fr-alert--warning.fr-alert--sm.fr-mb-4w
|
||||
%p= t('.notice_edit_denied')
|
||||
|
||||
%fieldset.fr-fieldset
|
||||
%legend.fr-fieldset__legend= t(".rule")
|
||||
|
@ -27,11 +27,7 @@
|
|||
%span.fr-hint-text
|
||||
= t(".resume_intro")
|
||||
|
||||
- if procedure.publiee? && procedure.sva_svr_enabled?
|
||||
.fr-alert.fr-alert--warning.fr-alert--sm
|
||||
%p Attention : un changement de ce réglage affectera les éventuels dossiers en cours.
|
||||
|
||||
= render Dsfr::RadioButtonListComponent.new(form: f, target: :resume, buttons: resume_buttons)
|
||||
|
||||
= f.submit t(".submit"), class: "fr-btn"
|
||||
= f.submit t(".submit"), class: "fr-btn", disabled: form_disabled?
|
||||
= link_to t(".cancel"), admin_procedure_path(procedure.id), class: "fr-btn fr-btn--secondary fr-ml-2w"
|
||||
|
|
|
@ -2,6 +2,8 @@ module ProcedureSVASVRConcern
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
validate :sva_svr_immutable_on_published, if: :will_save_change_to_sva_svr?
|
||||
|
||||
def sva_svr_enabled?
|
||||
sva? || svr?
|
||||
end
|
||||
|
@ -23,5 +25,16 @@ module ProcedureSVASVRConcern
|
|||
def decision
|
||||
sva_svr.fetch("decision", nil)&.to_sym
|
||||
end
|
||||
|
||||
def decision_was
|
||||
sva_svr_was.fetch("decision", nil)&.to_sym
|
||||
end
|
||||
|
||||
def sva_svr_immutable_on_published
|
||||
return if brouillon?
|
||||
return if [:sva, :svr].exclude?(decision_was)
|
||||
|
||||
errors.add(:sva_svr, :immutable)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,3 +57,5 @@ en:
|
|||
format: 'Private field %{message}'
|
||||
lien_dpo:
|
||||
invalid_uri_or_email: "Fill in with an email or a link"
|
||||
sva_svr:
|
||||
immutable: "SVA/SVR configuration can no longer be modified"
|
||||
|
|
|
@ -65,3 +65,5 @@ fr:
|
|||
invalid_uri_or_email: "Veuillez saisir un mail ou un lien"
|
||||
auto_archive_on:
|
||||
future: doit être dans le futur
|
||||
sva_svr:
|
||||
immutable: "La configuration SVA/SVR ne peut plus être modifiée"
|
||||
|
|
|
@ -401,6 +401,46 @@ describe Procedure do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with sva svr' do
|
||||
before {
|
||||
procedure.sva_svr["decision"] = "svr"
|
||||
}
|
||||
|
||||
context 'when procedure is published with sva' do
|
||||
let(:procedure) { create(:procedure, :published, :sva) }
|
||||
|
||||
it 'prevents changes to sva_svr' do
|
||||
expect(procedure).not_to be_valid
|
||||
expect(procedure.errors[:sva_svr].join).to include('ne peut plus être modifiée')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when procedure is published without sva' do
|
||||
let(:procedure) { create(:procedure, :published) }
|
||||
|
||||
it 'allow activation' do
|
||||
expect(procedure).to be_valid
|
||||
end
|
||||
|
||||
it 'allow activation from disabled value' do
|
||||
procedure.sva_svr["decision"] = "disabled"
|
||||
procedure.save!
|
||||
|
||||
procedure.sva_svr["decision"] = "svr"
|
||||
|
||||
expect(procedure).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'brouillon procedure' do
|
||||
let(:procedure) { create(:procedure, :sva) }
|
||||
|
||||
it "can update sva config" do
|
||||
expect(procedure).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'opendata' do
|
||||
|
|
Loading…
Reference in a new issue