Merge branch 'develop' into staging
This commit is contained in:
commit
94fd350f83
18 changed files with 321 additions and 11 deletions
20
app/controllers/admin/mails_controller.rb
Normal file
20
app/controllers/admin/mails_controller.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
class Admin::MailsController < AdminController
|
||||
before_action :retrieve_procedure
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
mail = current_administrateur.procedures.find(params[:procedure_id]).mail_templates.find(params[:id])
|
||||
mail.update_attributes(update_params)
|
||||
|
||||
redirect_to admin_procedure_mails_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_params
|
||||
params.require(:mail_received).permit(:body, :object)
|
||||
end
|
||||
end
|
|
@ -54,6 +54,8 @@ class Backoffice::DossiersController < ApplicationController
|
|||
@facade.dossier.next_step! 'gestionnaire', 'receive'
|
||||
flash.notice = 'Dossier considéré comme reçu.'
|
||||
|
||||
NotificationMailer.dossier_received(@facade.dossier).deliver_now!
|
||||
|
||||
render 'show'
|
||||
end
|
||||
|
||||
|
|
|
@ -3,6 +3,10 @@ class NotificationMailer < ApplicationMailer
|
|||
send_mail dossier, "Nouveau commentaire pour votre dossier TPS N°#{dossier.id}"
|
||||
end
|
||||
|
||||
def dossier_received dossier
|
||||
send_mail dossier, MailTemplate.replace_tags(dossier.procedure.mail_received.object, dossier)
|
||||
end
|
||||
|
||||
def dossier_validated dossier
|
||||
send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été validé"
|
||||
end
|
||||
|
|
18
app/models/mail_received.rb
Normal file
18
app/models/mail_received.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
class MailReceived < MailTemplate
|
||||
before_save :default_values
|
||||
|
||||
def default_values
|
||||
self.object ||= "[TPS] Accusé de réception pour votre dossier n°--numero_dossier--"
|
||||
self.body ||= "Bonjour,
|
||||
<br>
|
||||
<br>
|
||||
Votre administration vous confirme la bonne réception de votre dossier n°--numero_dossier-- complet. Celui-ci sera instruit dans le délais légal déclaré par votre interlocuteur.<br>
|
||||
<br>
|
||||
En vous souhaitant une bonne journée,
|
||||
<br>
|
||||
<br>
|
||||
---
|
||||
<br>
|
||||
L'équipe TPS"
|
||||
end
|
||||
end
|
33
app/models/mail_template.rb
Normal file
33
app/models/mail_template.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
class MailTemplate < ActiveRecord::Base
|
||||
belongs_to :procedure
|
||||
|
||||
enum tags: {
|
||||
numero_dossier: {
|
||||
description: "Permet d'afficher le numéro de dossier de l'utilisateur."
|
||||
},
|
||||
libelle_procedure: {
|
||||
description: "Permet d'afficher le libellé de la procédure."
|
||||
}
|
||||
}
|
||||
|
||||
def self.replace_tags string, dossier
|
||||
@dossier = dossier
|
||||
|
||||
tags.inject(string) do |acc, tag|
|
||||
acc.gsub!("--#{tag.first}--", replace_tag(tag.first.to_sym)) || acc
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.replace_tag tag
|
||||
case tag
|
||||
when :numero_dossier
|
||||
@dossier.id.to_s
|
||||
when :libelle_procedure
|
||||
@dossier.procedure.libelle
|
||||
else
|
||||
'--BALISE_NON_RECONNUE--'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,8 @@ class Procedure < ActiveRecord::Base
|
|||
has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy
|
||||
has_many :types_de_champ_private, dependent: :destroy
|
||||
has_many :dossiers
|
||||
has_many :mail_templates
|
||||
has_one :mail_received
|
||||
|
||||
has_one :procedure_path, dependent: :destroy
|
||||
|
||||
|
@ -15,7 +17,7 @@ class Procedure < ActiveRecord::Base
|
|||
|
||||
delegate :use_api_carto, to: :module_api_carto
|
||||
|
||||
accepts_nested_attributes_for :types_de_champ,:reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
|
||||
accepts_nested_attributes_for :types_de_champ, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
|
||||
accepts_nested_attributes_for :types_de_piece_justificative, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
|
||||
accepts_nested_attributes_for :module_api_carto
|
||||
accepts_nested_attributes_for :types_de_champ_private
|
||||
|
@ -25,12 +27,18 @@ class Procedure < ActiveRecord::Base
|
|||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
|
||||
after_save :build_default_mails, if: Proc.new { id_changed? }
|
||||
|
||||
def build_default_mails
|
||||
MailReceived.create(procedure: self)
|
||||
end
|
||||
|
||||
def path
|
||||
procedure_path.path unless procedure_path.nil?
|
||||
end
|
||||
|
||||
def default_path
|
||||
libelle.downcase.gsub(/[^a-z0-9\-_]/,"_").gsub(/_*$/, '').gsub(/_+/, '_')
|
||||
libelle.downcase.gsub(/[^a-z0-9\-_]/, "_").gsub(/_*$/, '').gsub(/_+/, '_')
|
||||
end
|
||||
|
||||
def types_de_champ_ordered
|
||||
|
@ -79,20 +87,20 @@ class Procedure < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def clone
|
||||
procedure = self.deep_clone(include: [ :types_de_piece_justificative, :types_de_champ, :module_api_carto ])
|
||||
procedure = self.deep_clone(include: [:types_de_piece_justificative, :types_de_champ, :module_api_carto])
|
||||
procedure.archived = false
|
||||
procedure.published = false
|
||||
return procedure if procedure.save
|
||||
end
|
||||
|
||||
def publish!(path)
|
||||
self.update_attributes!({ published: true, archived: false })
|
||||
self.update_attributes!({published: true, archived: false})
|
||||
ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur)
|
||||
end
|
||||
|
||||
def archive
|
||||
self.procedure_path.destroy! if self.path
|
||||
self.update_attributes!({ archived: true })
|
||||
self.update_attributes!({archived: true})
|
||||
end
|
||||
|
||||
def total_dossier
|
||||
|
|
29
app/views/admin/mails/index.html.haml
Normal file
29
app/views/admin/mails/index.html.haml
Normal file
|
@ -0,0 +1,29 @@
|
|||
=render partial: 'admin/procedures/head', locals: {active: 'E-mails'}
|
||||
|
||||
%h3
|
||||
E-mail d'accusé de réception
|
||||
|
||||
- unless @procedure.mail_received.blank?
|
||||
= form_for @procedure.mail_received, url: {controller: 'admin/mails', action: 'update', id: @procedure.mail_received.id} do |f|
|
||||
=f.text_field :object, {class:'form-control', style:'width: 40%'}
|
||||
%br
|
||||
=f.text_area :body, {class: 'form-control wysihtml5'}
|
||||
%br
|
||||
=f.submit 'Mettre à jour', {class:'btn btn-success', style:'float: right'}
|
||||
|
||||
|
||||
%table.table{style:'width: 50%'}
|
||||
%tr
|
||||
%th
|
||||
Balise
|
||||
%th
|
||||
Description
|
||||
- MailTemplate.tags.each do |balise|
|
||||
%tr
|
||||
%td.center
|
||||
%b.text-success
|
||||
\--
|
||||
= balise.first
|
||||
\--
|
||||
%td
|
||||
=balise.second[:description]
|
|
@ -20,5 +20,8 @@
|
|||
= link_to_unless(@procedure.locked?, 'Champs privés', admin_procedure_types_de_champ_private_path(@procedure)) do
|
||||
= link_to('Champs privés', '#')
|
||||
|
||||
%li{ class: ('active' if active == 'E-mails') }
|
||||
= link_to('E-mails', admin_procedure_mails_path(@procedure))
|
||||
|
||||
%li{ class: ('active' if active == 'Prévisualisation'), style: 'float:right' }
|
||||
= link_to('Prévisualisation', admin_procedure_previsualisation_path(@procedure), {style: 'font-style: italic;'})
|
1
app/views/notification_mailer/dossier_received.text.erb
Normal file
1
app/views/notification_mailer/dossier_received.text.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= MailTemplate.replace_tags @dossier.procedure.mail_received.body, @dossier %>
|
|
@ -114,6 +114,8 @@ Rails.application.routes.draw do
|
|||
post '/:index/move_down' => 'pieces_justificatives#move_down', as: :move_down
|
||||
end
|
||||
|
||||
resources 'mails'
|
||||
|
||||
put 'archive' => 'procedures#archive', as: :archive
|
||||
put 'publish' => 'procedures#publish', as: :publish
|
||||
post 'transfer' => 'procedures#transfer', as: :transfer
|
||||
|
|
11
db/migrate/20160830142653_create_mail_templates_table.rb
Normal file
11
db/migrate/20160830142653_create_mail_templates_table.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class CreateMailTemplatesTable < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :mail_templates do |t|
|
||||
t.string :object
|
||||
t.text :body
|
||||
t.string :type
|
||||
end
|
||||
|
||||
add_belongs_to :mail_templates, :procedure
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160829114646) do
|
||||
ActiveRecord::Schema.define(version: 20160830142653) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -227,6 +227,13 @@ ActiveRecord::Schema.define(version: 20160829114646) do
|
|||
t.integer "user_id"
|
||||
end
|
||||
|
||||
create_table "mail_templates", force: :cascade do |t|
|
||||
t.string "object"
|
||||
t.text "body"
|
||||
t.string "type"
|
||||
t.integer "procedure_id"
|
||||
end
|
||||
|
||||
create_table "module_api_cartos", force: :cascade do |t|
|
||||
t.integer "procedure_id"
|
||||
t.boolean "use_api_carto", default: false
|
||||
|
|
42
spec/controllers/admin/mails_controller_spec.rb
Normal file
42
spec/controllers/admin/mails_controller_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::MailsController, type: :controller do
|
||||
let(:procedure) { create :procedure }
|
||||
|
||||
before do
|
||||
sign_in procedure.administrateur
|
||||
end
|
||||
|
||||
describe 'GET index' do
|
||||
subject { get :index, procedure_id: procedure.id }
|
||||
|
||||
it { expect(subject.status).to eq 200 }
|
||||
end
|
||||
|
||||
describe 'PATCH update' do
|
||||
let(:object) { 'plop modif' }
|
||||
let(:body) { 'plip modif' }
|
||||
|
||||
context 'when is mail_received id' do
|
||||
subject { patch :update,
|
||||
procedure_id: procedure.id,
|
||||
id: procedure.mail_received.id,
|
||||
mail_received: {
|
||||
object: object,
|
||||
body: body
|
||||
} }
|
||||
|
||||
it { expect(subject).to redirect_to admin_procedure_mails_path }
|
||||
|
||||
describe 'values in database for mail received' do
|
||||
before do
|
||||
subject
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it { expect(procedure.mail_received.object).to eq object }
|
||||
it { expect(procedure.mail_received.body).to eq body }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||
|
||||
describe Backoffice::DossiersController, type: :controller do
|
||||
before do
|
||||
@request.env['HTTP_REFERER'] = TPS::Application::URL
|
||||
@request.env['HTTP_REFERER'] = TPS::Application::URL
|
||||
end
|
||||
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
|
@ -125,11 +125,24 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
it 'change state to received' do
|
||||
post :receive, dossier_id: dossier_id
|
||||
subject { post :receive, dossier_id: dossier_id }
|
||||
|
||||
dossier.reload
|
||||
expect(dossier.state).to eq('received')
|
||||
context 'when it post a receive instruction' do
|
||||
before do
|
||||
subject
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it 'change state to received' do
|
||||
expect(dossier.state).to eq('received')
|
||||
end
|
||||
end
|
||||
|
||||
it 'Notification email is send' do
|
||||
expect(NotificationMailer).to receive(:dossier_received).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
||||
|
|
7
spec/factories/mail_received.rb
Normal file
7
spec/factories/mail_received.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
FactoryGirl.define do
|
||||
factory :mail_received do
|
||||
object "Mail d'accusé de bonne reception de votre dossier"
|
||||
body "Votre dossier est correctement reçu"
|
||||
type 'MailReceived'
|
||||
end
|
||||
end
|
|
@ -34,4 +34,14 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
it { expect(subject.body).to match("ce jour à #{dossier.updated_at}.") }
|
||||
it { expect(subject.subject).to eq("Votre dossier TPS N°#{dossier.id} a été déposé") }
|
||||
end
|
||||
|
||||
describe '.dossier_received' do
|
||||
let(:user) { create(:user) }
|
||||
let(:dossier) { create(:dossier, user: user) }
|
||||
|
||||
subject(:subject) { described_class.dossier_received(dossier) }
|
||||
|
||||
it { expect(subject.subject).to eq("[TPS] Accusé de réception pour votre dossier n°#{dossier.id}") }
|
||||
it { expect(subject.body).to match("Votre administration vous confirme la bonne réception de votre dossier n°#{dossier.id}") }
|
||||
end
|
||||
end
|
||||
|
|
68
spec/models/mail_template_spec.rb
Normal file
68
spec/models/mail_template_spec.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe MailTemplate do
|
||||
it { is_expected.to have_db_column(:body) }
|
||||
it { is_expected.to have_db_column(:type) }
|
||||
|
||||
it { is_expected.to belong_to(:procedure) }
|
||||
|
||||
describe '.tags' do
|
||||
subject { MailTemplate.tags }
|
||||
|
||||
it { expect(subject.size).to eq 2 }
|
||||
|
||||
describe 'numero_dossier' do
|
||||
subject { super()['numero_dossier'] }
|
||||
|
||||
describe 'attr and description value' do
|
||||
|
||||
it { expect(subject['description']).to eq "Permet d'afficher le numéro de dossier de l'utilisateur." }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'numero_dossier' do
|
||||
subject { super()['libelle_procedure'] }
|
||||
|
||||
describe 'attr and description value' do
|
||||
|
||||
it { expect(subject['description']).to eq "Permet d'afficher le libellé de la procédure." }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.replace_tags' do
|
||||
let(:dossier) { create :dossier }
|
||||
let(:procedure) { dossier.procedure }
|
||||
let(:mail_received) { procedure.mail_received }
|
||||
|
||||
describe 'for tag --numero_dossier--' do
|
||||
before do
|
||||
procedure.mail_received.update_column(:object, '[TPS] Dossier n°--numero_dossier--')
|
||||
end
|
||||
|
||||
subject { MailTemplate.replace_tags procedure.mail_received.object, dossier }
|
||||
|
||||
it { expect(subject).to eq "[TPS] Dossier n°#{dossier.id}" }
|
||||
end
|
||||
|
||||
describe 'for tag --libelle_procedure--' do
|
||||
before do
|
||||
procedure.mail_received.update_column(:object, '[TPS] Dossier pour la procédure --libelle_procedure--')
|
||||
end
|
||||
|
||||
subject { MailTemplate.replace_tags procedure.mail_received.object, dossier }
|
||||
|
||||
it { expect(subject).to eq "[TPS] Dossier pour la procédure #{procedure.libelle}" }
|
||||
end
|
||||
|
||||
describe 'multiple tags' do
|
||||
before do
|
||||
procedure.mail_received.update_column(:object, '[TPS] Dossier n°--numero_dossier-- pour la procédure --libelle_procedure-- et encore le numéro : --numero_dossier--')
|
||||
end
|
||||
|
||||
subject { MailTemplate.replace_tags procedure.mail_received.object, dossier }
|
||||
|
||||
it { expect(subject).to eq "[TPS] Dossier n°#{dossier.id} pour la procédure #{procedure.libelle} et encore le numéro : #{dossier.id}" }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,6 +5,8 @@ describe Procedure do
|
|||
it { is_expected.to have_many(:types_de_piece_justificative) }
|
||||
it { is_expected.to have_many(:types_de_champ) }
|
||||
it { is_expected.to have_many(:dossiers) }
|
||||
it { is_expected.to have_many(:mail_templates) }
|
||||
it { is_expected.to have_one(:mail_received) }
|
||||
it { is_expected.to have_one(:module_api_carto) }
|
||||
it { is_expected.to belong_to(:administrateur) }
|
||||
end
|
||||
|
@ -20,6 +22,36 @@ describe Procedure do
|
|||
it { is_expected.to have_db_column(:logo_secure_token) }
|
||||
it { is_expected.to have_db_column(:cerfa_flag) }
|
||||
it { is_expected.to have_db_column(:published) }
|
||||
|
||||
describe 'mail_received' do
|
||||
let(:procedure) { create :procedure }
|
||||
|
||||
before do
|
||||
create :mail_received, procedure: procedure
|
||||
end
|
||||
|
||||
it { expect(procedure.mail_received).not_to be_nil }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#build_default_mails' do
|
||||
subject { build :procedure }
|
||||
|
||||
it 'call the fonction build_default_mails' do
|
||||
expect(subject).to receive(:build_default_mails)
|
||||
subject.save
|
||||
end
|
||||
|
||||
describe 'accessible values' do
|
||||
|
||||
before do
|
||||
subject.save
|
||||
end
|
||||
|
||||
it { expect(subject.mail_templates.size).to eq 1 }
|
||||
it { expect(subject.mail_received).not_to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
|
|
Loading…
Reference in a new issue