From 2f5ef75650c57e34fd10bfa60a8ba9bd913e4331 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Mon, 23 May 2022 15:22:28 +0200
Subject: [PATCH] no more actiontext, summernote with cleaner only

---
 Gemfile                                            |  2 +-
 Gemfile.lock                                       | 14 +++++++-------
 app/models/communication/website/imported/page.rb  |  2 +-
 app/models/communication/website/imported/post.rb  |  4 ++--
 app/services/osuny/sanitizer.rb                    |  6 +-----
 .../communication/websites/pages/_form.html.erb    |  2 +-
 .../communication/websites/pages/show.html.erb     |  2 +-
 7 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/Gemfile b/Gemfile
index b01ab29ad..140bdf705 100644
--- a/Gemfile
+++ b/Gemfile
@@ -46,7 +46,7 @@ gem 'simple-navigation'
 gem 'simple_form'
 gem 'simple_form_bs5_file_input'#, path: '../simple_form_bs5_file_input'
 gem 'simple_form_password_with_hints'#, path: '../simple_form_password_with_hints'
-gem 'summernote-rails', git: 'https://github.com/noesya/summernote-rails.git', branch: 'activestorage'
+gem 'summernote-rails', git: 'https://github.com/noesya/summernote-rails.git', branch: 'feature/cleaner'
 # gem 'summernote-rails', path: '../summernote-rails'
 gem 'two_factor_authentication', git: 'https://github.com/noesya/two_factor_authentication.git'
 # gem 'two_factor_authentication', path: '../two_factor_authentication'
diff --git a/Gemfile.lock b/Gemfile.lock
index e76deb9ae..bb4f7801a 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,10 +1,10 @@
 GIT
   remote: https://github.com/noesya/summernote-rails.git
-  revision: 529473cfdd85a50de64c6a7c8bce476cec8e85de
-  branch: activestorage
+  revision: da6e54c1e45c09dbeef2382d50f390aba968bd63
+  branch: feature/cleaner
   specs:
-    summernote-rails (0.8.24.0)
-      rails (>= 6.0)
+    summernote-rails (0.8.20.1)
+      railties (>= 3.1)
 
 GIT
   remote: https://github.com/noesya/two_factor_authentication.git
@@ -89,11 +89,11 @@ GEM
       execjs (~> 2)
     aws-eventstream (1.2.0)
     aws-partitions (1.589.0)
-    aws-sdk-core (3.131.0)
+    aws-sdk-core (3.131.1)
       aws-eventstream (~> 1, >= 1.0.2)
       aws-partitions (~> 1, >= 1.525.0)
       aws-sigv4 (~> 1.1)
-      jmespath (~> 1.0)
+      jmespath (~> 1, >= 1.6.1)
     aws-sdk-kms (1.57.0)
       aws-sdk-core (~> 3, >= 3.127.0)
       aws-sigv4 (~> 1.1)
@@ -545,4 +545,4 @@ RUBY VERSION
    ruby 2.7.5p203
 
 BUNDLED WITH
-   2.3.12
+   2.3.9
diff --git a/app/models/communication/website/imported/page.rb b/app/models/communication/website/imported/page.rb
index f4dbdce8b..18420493d 100644
--- a/app/models/communication/website/imported/page.rb
+++ b/app/models/communication/website/imported/page.rb
@@ -122,6 +122,6 @@ class Communication::Website::Imported::Page < ApplicationRecord
         end
       end
     end
-    page.update(text: rich_text_with_attachments(page.text.to_s))
+    page.update(text: rich_text_with_attachments(page.text))
   end
 end
diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb
index 8e2bcaec9..0c77bc954 100644
--- a/app/models/communication/website/imported/post.rb
+++ b/app/models/communication/website/imported/post.rb
@@ -122,7 +122,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
         content_type: featured_medium.file.blob.content_type
       )
     else
-      fragment = Nokogiri::HTML.fragment(post.text.body.to_html)
+      fragment = Nokogiri::HTML.fragment(post.text)
       image = fragment.css('img').first
       if image.present?
         begin
@@ -135,6 +135,6 @@ class Communication::Website::Imported::Post < ApplicationRecord
         end
       end
     end
-    post.update(text: rich_text_with_attachments(post.text.body.to_html))
+    post.update(text: rich_text_with_attachments(post.text))
   end
 end
diff --git a/app/services/osuny/sanitizer.rb b/app/services/osuny/sanitizer.rb
index ede92d171..bb3484bf2 100644
--- a/app/services/osuny/sanitizer.rb
+++ b/app/services/osuny/sanitizer.rb
@@ -9,12 +9,8 @@ class Osuny::Sanitizer
 
   private
 
-  # input can be String or ActionText::Content
   def self.sanitize_text(input)
-    input.is_a?(String) ? safe_list_sanitizer.sanitize(input)
-                        : ActionText::Content.new(
-                            safe_list_sanitizer.sanitize(input.to_html)
-                          )
+    safe_list_sanitizer.sanitize(input)
   end
 
   def self.sanitize_string(string)
diff --git a/app/views/admin/communication/websites/pages/_form.html.erb b/app/views/admin/communication/websites/pages/_form.html.erb
index 00d096e51..d32d113d3 100644
--- a/app/views/admin/communication/websites/pages/_form.html.erb
+++ b/app/views/admin/communication/websites/pages/_form.html.erb
@@ -13,7 +13,7 @@
           <%= f.input :breadcrumb_title %>
           <%= f.input :description_short, input_html: { value: page.description_short&.gsub('&amp;', '&') } %>
           <%= f.input :header_text, as: :string %>
-          <%= f.input :text, as: :summernote if page.text&.to_plain_text.present? %>
+          <%= f.input :text, as: :summernote if page.text&.present? %>
         </div>
       </div>
       <div class="card">
diff --git a/app/views/admin/communication/websites/pages/show.html.erb b/app/views/admin/communication/websites/pages/show.html.erb
index 0b5b5f084..b86553e58 100644
--- a/app/views/admin/communication/websites/pages/show.html.erb
+++ b/app/views/admin/communication/websites/pages/show.html.erb
@@ -20,7 +20,7 @@
         </div>
         <div class="card-body">
           <%= render 'admin/application/property/text', object: @page, property: :description_short %>
-          <%= render 'admin/application/property/text', object: @page, property: :text if @page.text&.to_plain_text.present? %>
+          <%= render 'admin/application/property/text', object: @page, property: :text if @page.text&.present? %>
         </div>
       </div>
       <%= render 'admin/communication/blocks/list', about: @page %>
-- 
GitLab