diff --git a/app/controllers/manager/procedures_controller.rb b/app/controllers/manager/procedures_controller.rb index f384772ba..4035c968c 100644 --- a/app/controllers/manager/procedures_controller.rb +++ b/app/controllers/manager/procedures_controller.rb @@ -6,5 +6,16 @@ module Manager flash[:notice] = "Démarche whitelistée." redirect_to manager_procedure_path(procedure) end + + def draft + procedure = Procedure.find(params[:id]) + if procedure.dossiers.empty? + procedure.draft! + flash[:notice] = "La démarche a bien été passée en brouillon." + else + flash[:alert] = "Impossible de repasser en brouillon une démarche à laquelle sont rattachés des dossiers." + end + redirect_to manager_procedure_path(procedure) + end end end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 006a3bf3c..ec4c26a36 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -86,6 +86,10 @@ class Procedure < ApplicationRecord transitions from: :publiee, to: :hidden transitions from: :archivee, to: :hidden end + + event :draft, after: :after_draft do + transitions from: :publiee, to: :brouillon + end end def publish_or_reopen!(path) @@ -372,6 +376,10 @@ class Procedure < ApplicationRecord publish_with_path!(path) end + def after_draft + update!(published_at: nil) + end + def update_juridique_required self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?) true diff --git a/app/views/manager/procedures/show.html.erb b/app/views/manager/procedures/show.html.erb index 0f7d5eb7a..891a5d374 100644 --- a/app/views/manager/procedures/show.html.erb +++ b/app/views/manager/procedures/show.html.erb @@ -36,6 +36,10 @@ as well as a link to its edit page. <% if !procedure.whitelisted? %> <%= link_to 'whitelister', whitelist_manager_procedure_path(procedure), method: :post, class: 'button' %> <% end %> + + <% if procedure.publiee? && procedure.dossiers.empty? %> + <%= link_to 'passer en brouillon', draft_manager_procedure_path(procedure), method: :post, class: 'button' %> + <% end %>