From e68441d573b0c10f21a0546ff3f17bf535faa8ef Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 28 Apr 2021 15:08:48 +0200 Subject: [PATCH] Allow publishing revisions when feature flag is enabled --- .../new_administrateur/administrateur_controller.rb | 7 +++++++ .../new_administrateur/procedures_controller.rb | 10 +++++++--- .../new_administrateur/types_de_champ_controller.rb | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/controllers/new_administrateur/administrateur_controller.rb b/app/controllers/new_administrateur/administrateur_controller.rb index 6a8da5753..7c5f4cdda 100644 --- a/app/controllers/new_administrateur/administrateur_controller.rb +++ b/app/controllers/new_administrateur/administrateur_controller.rb @@ -19,6 +19,13 @@ module NewAdministrateur end end + def procedure_revisable? + if @procedure.locked? && !@procedure.feature_enabled?(:procedure_revisions) + flash.alert = 'Démarche verrouillée' + redirect_to admin_procedure_path(@procedure) + end + end + def reset_procedure if @procedure.brouillon? @procedure.reset! diff --git a/app/controllers/new_administrateur/procedures_controller.rb b/app/controllers/new_administrateur/procedures_controller.rb index 7ef2b56f3..c0c697143 100644 --- a/app/controllers/new_administrateur/procedures_controller.rb +++ b/app/controllers/new_administrateur/procedures_controller.rb @@ -1,7 +1,7 @@ module NewAdministrateur class ProceduresController < AdministrateurController before_action :retrieve_procedure, only: [:champs, :annotations, :edit, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :allow_expert_review, :experts_require_administrateur_invitation] - before_action :procedure_locked?, only: [:champs, :annotations] + before_action :procedure_revisable?, only: [:champs, :annotations] ITEMS_PER_PAGE = 25 @@ -154,12 +154,16 @@ module NewAdministrateur def publish @procedure.assign_attributes(publish_params) - if @procedure.publish_or_reopen!(current_administrateur) + if @procedure.draft_changed? + @procedure.publish_revision! + flash.notice = "Nouvelle version de la démarche publiée" redirect_to admin_procedure_path(@procedure) + elsif @procedure.publish_or_reopen!(current_administrateur) flash.notice = "Démarche publiée" - else redirect_to admin_procedure_path(@procedure) + else flash.alert = @procedure.errors.full_messages + redirect_to admin_procedure_path(@procedure) end end diff --git a/app/controllers/new_administrateur/types_de_champ_controller.rb b/app/controllers/new_administrateur/types_de_champ_controller.rb index 160110985..4d4e1685c 100644 --- a/app/controllers/new_administrateur/types_de_champ_controller.rb +++ b/app/controllers/new_administrateur/types_de_champ_controller.rb @@ -1,7 +1,7 @@ module NewAdministrateur class TypesDeChampController < AdministrateurController before_action :retrieve_procedure, only: [:create, :update, :move, :destroy] - before_action :procedure_locked?, only: [:create, :update, :move, :destroy] + before_action :procedure_revisable?, only: [:create, :update, :move, :destroy] def create type_de_champ = @procedure.draft_revision.add_type_de_champ(type_de_champ_create_params)