Merge pull request #1760 from betagouv/fix-1729
Fix 1729 remove <code> tags from mail templates
This commit is contained in:
commit
8fe5c25c46
3 changed files with 80 additions and 1 deletions
|
@ -2,6 +2,36 @@ $(document).on('turbolinks:load', wysihtml5_active);
|
|||
|
||||
function wysihtml5_active (){
|
||||
$('.wysihtml5').each(function(i, elem) {
|
||||
$(elem).wysihtml5({ toolbar:{ "fa": true, "link": false, "color": false }, "locale": "fr-FR" });
|
||||
$(elem).wysihtml5({
|
||||
toolbar: {
|
||||
"fa": true,
|
||||
"link": false,
|
||||
"color": false
|
||||
},
|
||||
parserRules: {
|
||||
tags: {
|
||||
p: {},
|
||||
h1: {},
|
||||
h2: {},
|
||||
h3: {},
|
||||
h4: {},
|
||||
h5: {},
|
||||
h6: {},
|
||||
b: {},
|
||||
i: {},
|
||||
u: {},
|
||||
small: {},
|
||||
blockquote: {},
|
||||
ul: {},
|
||||
ol: {},
|
||||
li: {},
|
||||
img: {},
|
||||
code: {
|
||||
unwrap: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
"locale": "fr-FR"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
namespace :'2018_03_29_remove_code_tags_from_mail_templates' do
|
||||
task clean: :environment do
|
||||
remove_code_tag_from_body(Mails::ClosedMail)
|
||||
remove_code_tag_from_body(Mails::InitiatedMail)
|
||||
remove_code_tag_from_body(Mails::ReceivedMail)
|
||||
remove_code_tag_from_body(Mails::RefusedMail)
|
||||
remove_code_tag_from_body(Mails::WithoutContinuationMail)
|
||||
end
|
||||
|
||||
def remove_code_tag_from_body(model_class)
|
||||
mails = model_class.where("body LIKE ?", "%<code>%")
|
||||
puts "#{mails.count} #{model_class.name} to clean"
|
||||
mails.each do |m|
|
||||
puts "cleaning #{model_class.name} ##{m.id}"
|
||||
m.update(body: m.body.gsub("<code>", "").gsub("</code>", ""))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,31 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe '2018_03_29_remove_code_tags_from_mail_templates#clean' do
|
||||
let(:rake_task) { Rake::Task['2018_03_29_remove_code_tags_from_mail_templates:clean'] }
|
||||
|
||||
let!(:dirty_closed_mail) { create(:closed_mail, body: "<h1>Salut</h1><br>Voici ton email avec une balise <code>--balise--</code>") }
|
||||
let!(:dirty_initiated_mail) { create(:initiated_mail, body: "<h1>Salut</h1><br>Voici ton email avec une balise <code>--balise--</code>") }
|
||||
let!(:dirty_received_mail) { create(:received_mail, body: "<h1>Salut</h1><br>Voici ton email avec une balise <code>--balise--</code>") }
|
||||
let!(:dirty_refused_mail) { create(:refused_mail, body: "<h1>Salut</h1><br>Voici ton email avec une balise <code>--balise--</code>") }
|
||||
let!(:dirty_without_continuation_mail) { create(:without_continuation_mail, body: "<h1>Salut</h1><br>Voici ton email avec une balise <code>--balise--</code>") }
|
||||
|
||||
before do
|
||||
TPS::Application.load_tasks
|
||||
rake_task.invoke
|
||||
dirty_closed_mail.reload
|
||||
dirty_initiated_mail.reload
|
||||
dirty_received_mail.reload
|
||||
dirty_refused_mail.reload
|
||||
dirty_without_continuation_mail.reload
|
||||
end
|
||||
|
||||
after { rake_task.reenable }
|
||||
|
||||
it 'cleans up code tags' do
|
||||
expect(dirty_closed_mail.body).to eq("<h1>Salut</h1><br>Voici ton email avec une balise --balise--")
|
||||
expect(dirty_initiated_mail.body).to eq("<h1>Salut</h1><br>Voici ton email avec une balise --balise--")
|
||||
expect(dirty_received_mail.body).to eq("<h1>Salut</h1><br>Voici ton email avec une balise --balise--")
|
||||
expect(dirty_refused_mail.body).to eq("<h1>Salut</h1><br>Voici ton email avec une balise --balise--")
|
||||
expect(dirty_without_continuation_mail.body).to eq("<h1>Salut</h1><br>Voici ton email avec une balise --balise--")
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue