Merge pull request #404 from sgmap/encart-decision

Encart decision
This commit is contained in:
gregoirenovel 2017-06-13 15:35:42 +02:00 committed by GitHub
commit ecbb6500a2
16 changed files with 168 additions and 118 deletions

View file

@ -281,3 +281,8 @@
}
}
}
.motivation-text-area {
color: #000000;
margin-bottom: 15px;
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -0,0 +1,5 @@
class AddMotivationToDossier < ActiveRecord::Migration[5.0]
def change
add_column :dossiers, :motivation, :text
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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