Administrateur can be param the acknowledgement of delivery mail object and body.
This commit is contained in:
parent
d438e9a329
commit
12ebab66cc
13 changed files with 222 additions and 6 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
|
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 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
|
10
app/models/mail_template.rb
Normal file
10
app/models/mail_template.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class MailTemplate < ActiveRecord::Base
|
||||
belongs_to :procedure
|
||||
|
||||
enum balises: {
|
||||
numero_dossier: {
|
||||
attr: 'dossier.id',
|
||||
description: "Permet d'afficher le numéro de dossier de l'utilisateur."
|
||||
}
|
||||
}
|
||||
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.balises.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;'})
|
|
@ -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
|
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
|
27
spec/models/mail_template_spec.rb
Normal file
27
spec/models/mail_template_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
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 '.balises' do
|
||||
subject { MailTemplate.balises }
|
||||
|
||||
it { expect(subject.size).to eq 1 }
|
||||
|
||||
describe 'numero_dossier' do
|
||||
subject { super().first }
|
||||
|
||||
it { expect(subject.first).to eq 'numero_dossier' }
|
||||
|
||||
describe 'attr and description value' do
|
||||
subject { super().second }
|
||||
|
||||
it { expect(subject[:attr]).to eq 'dossier.id' }
|
||||
it { expect(subject[:description]).to eq "Permet d'afficher le numéro de dossier de l'utilisateur." }
|
||||
end
|
||||
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…
Add table
Reference in a new issue