diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index 13591a50d82645ec710d2366662f21f9681a98b6..95ccf3744fffd4a75ae99b5be9a0f5656cd7e961 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -50,6 +50,7 @@ class Communication::Block < ApplicationRecord key_figures: 56, } + before_validation :sanitize_data before_save :update_template_images after_commit :save_and_sync_about, on: [:update, :destroy] @@ -77,11 +78,15 @@ class Communication::Block < ApplicationRecord protected - def save_and_sync_about - about&.save_and_sync unless about&.destroyed? + def sanitize_data + self.data = template.sanitized_data end def update_template_images self.template_images = template.active_storage_blobs end + + def save_and_sync_about + about&.save_and_sync unless about&.destroyed? + end end diff --git a/app/models/communication/block/template.rb b/app/models/communication/block/template.rb index 66cae4fd3495e62136e85f2ececa232d1f6e9621..90dbab361e38064a631126edbb63c4ab0ecb8fc8 100644 --- a/app/models/communication/block/template.rb +++ b/app/models/communication/block/template.rb @@ -5,6 +5,10 @@ class Communication::Block::Template @block = block end + def sanitized_data + data + end + def git_dependencies unless @git_dependencies @git_dependencies = [] diff --git a/app/models/communication/block/template/call_to_action.rb b/app/models/communication/block/template/call_to_action.rb index 57ea19c92cd70a957c2b7933313e429fe0672f34..5f8c6fe1cd4b09b0e96d7b3fbde136b244304e75 100644 --- a/app/models/communication/block/template/call_to_action.rb +++ b/app/models/communication/block/template/call_to_action.rb @@ -1,4 +1,19 @@ class Communication::Block::Template::CallToAction < Communication::Block::Template + def sanitized_data + { + "text" => Osuny::Sanitizer.sanitize(text), + "url" => url, + "button" => Osuny::Sanitizer.sanitize(button, 'string'), + "url_secondary" => url_secondary, + "button_secondary" => Osuny::Sanitizer.sanitize(button_secondary, 'string'), + "url_tertiary" => url_tertiary, + "button_tertiary" => Osuny::Sanitizer.sanitize(button_tertiary, 'string'), + "image" => data['image'], + "image_alt" => Osuny::Sanitizer.sanitize(data['image_alt'], 'string'), + "image_credit" => Osuny::Sanitizer.sanitize(data['image_credit'], 'string') + } + end + def build_git_dependencies add_dependency image&.blob end diff --git a/app/models/communication/block/template/chapter.rb b/app/models/communication/block/template/chapter.rb index 992a493a05bd55ab7eeb8cfab90b440ebb2f9d2a..9628edb0cdf9c425e14d37d9fba491a59d1e2418 100644 --- a/app/models/communication/block/template/chapter.rb +++ b/app/models/communication/block/template/chapter.rb @@ -1,4 +1,14 @@ class Communication::Block::Template::Chapter < Communication::Block::Template + def sanitized_data + { + "text" => Osuny::Sanitizer.sanitize(text), + "notes" => Osuny::Sanitizer.sanitize(notes), + "image" => data['image'], + "image_alt" => Osuny::Sanitizer.sanitize(data['image_alt'], 'string'), + "image_credit" => Osuny::Sanitizer.sanitize(data['image_credit'], 'string') + } + end + def build_git_dependencies add_dependency image&.blob end diff --git a/app/models/communication/block/template/image.rb b/app/models/communication/block/template/image.rb index a306ec700532e92f1d0e2284d8e453c4edd0a0a3..f6968d1ee305526e76f9b1c2b0bd41145a42263d 100644 --- a/app/models/communication/block/template/image.rb +++ b/app/models/communication/block/template/image.rb @@ -1,4 +1,13 @@ class Communication::Block::Template::Image < Communication::Block::Template + def sanitized_data + { + "text" => Osuny::Sanitizer.sanitize(text), + "image" => data['image'], + "image_alt" => Osuny::Sanitizer.sanitize(data['image_alt'], 'string'), + "image_credit" => Osuny::Sanitizer.sanitize(data['image_credit'], 'string') + } + end + def build_git_dependencies add_dependency image&.blob end diff --git a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb index 860e81f9048569a1d23b038547b15e12f5aafc30..d015f65d7a8d8721fc67439ed8947a313fb36767 100644 --- a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb @@ -63,7 +63,7 @@ for="image_credit"> <%= t 'admin.communication.blocks.components.image.credit.label' %> </label> - <input id="image_alt" + <input id="image_credit" type="text" class="form-control" v-model="data.image_credit" diff --git a/app/views/admin/communication/blocks/templates/embed/_edit.html.erb b/app/views/admin/communication/blocks/templates/embed/_edit.html.erb index 980ce3623f822ef230247fdb8b2322a59266997b..517a37fbe63b9a7144a5b0f4d4ba84a178a0e907 100644 --- a/app/views/admin/communication/blocks/templates/embed/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/embed/_edit.html.erb @@ -9,7 +9,6 @@ rows="10" class="form-control" v-model="data.code" - data-summernote-config="mini-list" placeholder="<%= t '.code_placeholder' %>"></textarea> </div> </div>