diff --git a/app/assets/stylesheets/left_panel.scss b/app/assets/stylesheets/left_panel.scss index c594715a2..e35b6494f 100644 --- a/app/assets/stylesheets/left_panel.scss +++ b/app/assets/stylesheets/left_panel.scss @@ -281,3 +281,8 @@ } } } + +.motivation-text-area { + color: #000000; + margin-bottom: 15px; +} diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index ec3524100..a5477430f 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -103,41 +103,34 @@ class Backoffice::DossiersController < Backoffice::DossiersListController redirect_to backoffice_dossier_path(id: dossier.id) end - def refuse + def process_dossier create_dossier_facade params[:dossier_id] + if params[:dossier] && params[:dossier][:motivation].present? + motivation = params[:dossier][:motivation] + end + dossier = @facade.dossier - dossier.next_step! 'gestionnaire', 'refuse' - flash.notice = 'Dossier considéré comme refusé.' + case params[:process_action] + when "refuse" + next_step = "refuse" + notice = "Dossier considéré comme refusé." + template = dossier.procedure.refused_mail_template + when "without_continuation" + next_step = "without_continuation" + notice = "Dossier considéré comme sans suite." + template = dossier.procedure.without_continuation_mail_template + when "close" + next_step = "close" + notice = "Dossier traité avec succès." + template = dossier.procedure.closed_mail_template + end - NotificationMailer.send_notification(dossier, dossier.procedure.refused_mail_template).deliver_now! + dossier.next_step! 'gestionnaire', next_step, motivation + flash.notice = notice - redirect_to backoffice_dossier_path(id: dossier.id) - end - - def without_continuation - create_dossier_facade params[:dossier_id] - - dossier = @facade.dossier - - dossier.next_step! 'gestionnaire', 'without_continuation' - flash.notice = 'Dossier considéré comme sans suite.' - - NotificationMailer.send_notification(dossier, dossier.procedure.without_continuation_mail_template).deliver_now! - - redirect_to backoffice_dossier_path(id: dossier.id) - end - - def close - create_dossier_facade params[:dossier_id] - - dossier = @facade.dossier - - dossier.next_step! 'gestionnaire', 'close' - flash.notice = 'Dossier traité avec succès.' - - NotificationMailer.send_notification(dossier, dossier.procedure.closed_mail_template).deliver_now! + NotificationMailer.send_notification(dossier, template).deliver_now! redirect_to backoffice_dossier_path(id: dossier.id) end diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index 25c87d133..cd44676f5 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -21,6 +21,10 @@ module MailTemplateConcern name: "date_de_decision", description: "Permet d'afficher la date à laquelle la décision finale (acceptation, refus, classement sans suite) sur le dossier a été prise." } + TAGS << TAG_MOTIVATION = { + name: "motivation", + description: "Permet d'afficher la motivation associée à la décision finale (acceptation, refus, classement sans suite) sur le dossier. Attention, elle est facultative." + } def object_for_dossier(dossier) replace_tags(object, dossier) @@ -55,6 +59,8 @@ module MailTemplateConcern dossier.procedure.libelle when TAG_DATE_DE_DECISION dossier.processed_at.present? ? dossier.processed_at.localtime.strftime("%d/%m/%Y") : "" + when TAG_MOTIVATION + dossier.motivation || "" else '--BALISE_NON_RECONNUE--' end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 8203618ed..6fbdfb1a2 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -130,7 +130,7 @@ class Dossier < ActiveRecord::Base commentaires.order(created_at: :desc) end - def next_step! role, action + def next_step! role, action, motivation = nil unless %w(initiate follow update comment receive refuse without_continuation close).include?(action) fail 'action is not valid' end @@ -170,14 +170,29 @@ class Dossier < ActiveRecord::Base when 'close' if received? closed! + + if motivation + self.motivation = motivation + save + end end when 'refuse' if received? refused! + + if motivation + self.motivation = motivation + save + end end when 'without_continuation' if received? without_continuation! + + if motivation + self.motivation = motivation + save + end end end end diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index 80f706bf9..cef3a274f 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -6,6 +6,6 @@ module Mails TEMPLATE_NAME = "mails/closed_mail" DISPLAYED_NAME = "Accusé d'acceptation" DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été accepté' - ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] + ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION, TAG_MOTIVATION] end end diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb index f9b859e74..8d0b9d032 100644 --- a/app/models/mails/refused_mail.rb +++ b/app/models/mails/refused_mail.rb @@ -6,6 +6,6 @@ module Mails TEMPLATE_NAME = "mails/refused_mail" DISPLAYED_NAME = 'Accusé de rejet du dossier' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été refusé' - ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] + ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION, TAG_MOTIVATION] end end diff --git a/app/models/mails/without_continuation_mail.rb b/app/models/mails/without_continuation_mail.rb index 0115037c3..7e615ca75 100644 --- a/app/models/mails/without_continuation_mail.rb +++ b/app/models/mails/without_continuation_mail.rb @@ -6,6 +6,6 @@ module Mails TEMPLATE_NAME = "mails/without_continuation_mail" DISPLAYED_NAME = 'Accusé de classement sans suite' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été classé sans suite' - ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] + ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION, TAG_MOTIVATION] end end diff --git a/app/views/dossiers/_dossier_show.html.haml b/app/views/dossiers/_dossier_show.html.haml index cfbe4ee02..60d426479 100644 --- a/app/views/dossiers/_dossier_show.html.haml +++ b/app/views/dossiers/_dossier_show.html.haml @@ -2,6 +2,8 @@ = render partial: 'dossiers/messagerie', locals: { dossier_facade: @facade } += render partial: 'dossiers/motivation', locals: { dossier_facade: @facade } + - if @facade.procedure.individual_with_siret .default-data-block .row.show-block.infos diff --git a/app/views/dossiers/_motivation.html.haml b/app/views/dossiers/_motivation.html.haml new file mode 100644 index 000000000..dad4f1b5c --- /dev/null +++ b/app/views/dossiers/_motivation.html.haml @@ -0,0 +1,11 @@ +- if Dossier::TERMINE.include?(@facade.dossier.state) && @facade.dossier.motivation.present? + .default-data-block.default_visible + .row.show-block.infos + .header + .col-xs-12.title + .carret-right + .carret-down + MOTIVATION + .body + .display-block-on-print + = @facade.dossier.motivation diff --git a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml index 2560a0bb8..c24112ece 100644 --- a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml +++ b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml @@ -8,17 +8,23 @@ = link_to 'Passer en instruction', backoffice_dossier_receive_path(@facade.dossier), method: :post, class: 'btn btn-danger btn-block', data: { confirm: "Confirmer vous le passage en instruction de ce dossier ?" } - elsif @facade.dossier.received? - %ul.list-inline - %li - = link_to url_for({ controller: 'backoffice/dossiers', action: :close, dossier_id: @facade.dossier.id }), class: 'btn btn-success', method: :post, title: 'Accepter', data: { toggle: :tooltip, confirm: "Accepter ce dossier ?" } do - %i.fa.fa-check - %li - = link_to url_for({ controller: 'backoffice/dossiers', action: :without_continuation, dossier_id: @facade.dossier.id }), class: 'btn btn-warning', method: :post, title: 'Classer sans suite', data: { toggle: :tooltip, confirm: "Classer sans suite ce dossier ?" } do - %i.fa.fa-circle-o - %li - = link_to url_for({ controller: 'backoffice/dossiers', action: :refuse, dossier_id: @facade.dossier.id }), class: 'btn btn-danger', method: :post, title: 'Refuser', data: { toggle: :tooltip, confirm: "Refuser ce dossier ?" } do - %i.fa.fa-times + = form_tag(backoffice_dossier_process_dossier_url(@facade.dossier.id), method: :post) do + = text_area :dossier, :motivation, class: "motivation-text-area", placeholder: "Motivation (facultative)" + %ul.list-inline + %li + = button_tag name: :process_action, value: "close", class: 'btn btn-success', title: 'Accepter', data: { toggle: :tooltip, confirm: "Accepter ce dossier ?" } do + %i.fa.fa-check + + %li + = button_tag name: :process_action, value: "without_continuation", class: 'btn btn-warning', title: 'Classer sans suite', data: { toggle: :tooltip, confirm: "Classer sans suite ce dossier ?" } do + %i.fa.fa-circle-o + + %li + = button_tag name: :process_action, value: "refuse", class: 'btn btn-danger', title: 'Refuser', data: { toggle: :tooltip, confirm: "Refuser ce dossier ?" } do + %i.fa.fa-times + + %hr = link_to 'Reouvrir', backoffice_dossier_reopen_path(@facade.dossier), method: :post, class: 'btn btn-default btn-block', data: { confirm: "Confirmer vous la réouverture de ce dossier ?" } %hr diff --git a/config/routes.rb b/config/routes.rb index 7aff0071f..c09431946 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -172,9 +172,7 @@ Rails.application.routes.draw do resources :dossiers do post 'receive' => 'dossiers#receive' - post 'refuse' => 'dossiers#refuse' - post 'without_continuation' => 'dossiers#without_continuation' - post 'close' => 'dossiers#close' + post 'process_dossier' => 'dossiers#process_dossier' member do post 'archive' post 'unarchive' diff --git a/db/migrate/20170530141608_add_motivation_to_dossier.rb b/db/migrate/20170530141608_add_motivation_to_dossier.rb new file mode 100644 index 000000000..6ee802630 --- /dev/null +++ b/db/migrate/20170530141608_add_motivation_to_dossier.rb @@ -0,0 +1,5 @@ +class AddMotivationToDossier < ActiveRecord::Migration[5.0] + def change + add_column :dossiers, :motivation, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 0fd7a56a4..b24616cc2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170523092900) do +ActiveRecord::Schema.define(version: 20170530141608) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -151,6 +151,7 @@ ActiveRecord::Schema.define(version: 20170523092900) do t.datetime "initiated_at" t.datetime "received_at" t.datetime "processed_at" + t.text "motivation" t.index ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree t.index ["user_id"], name: "index_dossiers_on_user_id", using: :btree end diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index b21bd6e32..5d11f4b2d 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -250,80 +250,84 @@ describe Backoffice::DossiersController, type: :controller do it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) } end - describe 'POST #refuse' do - before do - dossier.refused! - sign_in gestionnaire + describe 'POST #process_dossier' do + context "with refuse" do + before do + dossier.received! + sign_in gestionnaire + end + + subject { post :process_dossier, params: { process_action: "refuse", dossier_id: dossier_id} } + + it 'change state to refused' do + subject + + dossier.reload + expect(dossier.state).to eq('refused') + end + + it 'Notification email is sent' do + expect(NotificationMailer).to receive(:send_notification) + .with(dossier, kind_of(Mails::RefusedMail)).and_return(NotificationMailer) + expect(NotificationMailer).to receive(:deliver_now!) + + subject + end + + it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) } end - subject { post :refuse, params: {dossier_id: dossier_id} } + context "with without_continuation" do + before do + dossier.received! + sign_in gestionnaire + end - it 'change state to refused' do - subject + subject { post :process_dossier, params: { process_action: "without_continuation", dossier_id: dossier_id} } - dossier.reload - expect(dossier.state).to eq('refused') + it 'change state to without_continuation' do + subject + + dossier.reload + expect(dossier.state).to eq('without_continuation') + end + + it 'Notification email is sent' do + expect(NotificationMailer).to receive(:send_notification) + .with(dossier, kind_of(Mails::WithoutContinuationMail)).and_return(NotificationMailer) + expect(NotificationMailer).to receive(:deliver_now!) + + subject + end + + it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) } end - it 'Notification email is sent' do - expect(NotificationMailer).to receive(:send_notification) - .with(dossier, kind_of(Mails::RefusedMail)).and_return(NotificationMailer) - expect(NotificationMailer).to receive(:deliver_now!) + context "with close" do + before do + dossier.received! + sign_in gestionnaire + end - subject + subject { post :process_dossier, params: { process_action: "close", dossier_id: dossier_id} } + + it 'change state to closed' do + subject + + dossier.reload + expect(dossier.state).to eq('closed') + end + + it 'Notification email is sent' do + expect(NotificationMailer).to receive(:send_notification) + .with(dossier, kind_of(Mails::ClosedMail)).and_return(NotificationMailer) + expect(NotificationMailer).to receive(:deliver_now!) + + subject + end + + it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) } end - - it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) } - end - - describe 'POST #without_continuation' do - before do - dossier.without_continuation! - sign_in gestionnaire - end - subject { post :without_continuation, params: {dossier_id: dossier_id} } - - it 'change state to without_continuation' do - subject - - dossier.reload - expect(dossier.state).to eq('without_continuation') - end - - it 'Notification email is sent' do - expect(NotificationMailer).to receive(:send_notification) - .with(dossier, kind_of(Mails::WithoutContinuationMail)).and_return(NotificationMailer) - expect(NotificationMailer).to receive(:deliver_now!) - - subject - end - - it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) } - end - - describe 'POST #close' do - before do - dossier.received! - sign_in gestionnaire - end - subject { post :close, params: {dossier_id: dossier_id} } - - it 'change state to closed' do - subject - - dossier.reload - expect(dossier.state).to eq('closed') - end - - it 'Notification email is sent' do - expect(NotificationMailer).to receive(:send_notification) - .with(dossier, kind_of(Mails::ClosedMail)).and_return(NotificationMailer) - expect(NotificationMailer).to receive(:deliver_now!) - - subject - end - - it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) } end describe 'PUT #toggle_follow' do diff --git a/spec/views/backoffice/dossiers/show.html.html_spec.rb b/spec/views/backoffice/dossiers/show.html.html_spec.rb index 4060d600f..0be7ed6f9 100644 --- a/spec/views/backoffice/dossiers/show.html.html_spec.rb +++ b/spec/views/backoffice/dossiers/show.html.html_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe 'backoffice/dossiers/show.html.haml', type: :view do - let!(:dossier) { create(:dossier, :with_entreprise, state: state) } - let(:state) { 'draft' } + let!(:dossier) { create(:dossier, :with_entreprise, state: state, motivation: "Motivation de décision") } + let(:state) { 'closed' } let(:dossier_id) { dossier.id } let(:gestionnaire) { create(:gestionnaire) } @@ -44,5 +44,9 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do expect(rendered).to_not have_css('#maj_infos') end end + + it "shows the motivation" do + expect(rendered).to have_content("Motivation de décision") + end end end diff --git a/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb b/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb index cd91a032c..4682bb331 100644 --- a/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb +++ b/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb @@ -74,9 +74,9 @@ describe 'layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.htm it { expect(rendered).to have_content('En instruction') } it 'button accepter / refuser / classer sans suite are present' do - expect(rendered).to have_css('a[title="Accepter"]') - expect(rendered).to have_css('a[title="Classer sans suite"]') - expect(rendered).to have_css('a[title="Refuser"]') + expect(rendered).to have_css('button[title="Accepter"]') + expect(rendered).to have_css('button[title="Classer sans suite"]') + expect(rendered).to have_css('button[title="Refuser"]') end end