diff --git a/app/assets/images/communication/blocks/templates/form.jpg b/app/assets/images/communication/blocks/templates/form.jpg new file mode 100644 index 000000000..5263c2e59 Binary files /dev/null and b/app/assets/images/communication/blocks/templates/form.jpg differ diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index ba2f24034..572f82629 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -38,7 +38,7 @@ class Communication::Block < ApplicationRecord basic: [:title, :chapter, :image, :video, :sound, :datatable], storytelling: [:key_figures, :features, :gallery, :call_to_action, :testimonials, :timeline], references: [:pages, :posts, :persons, :organizations, :agenda, :exhibitions, :programs, :locations, :projects, :papers, :volumes, :jobs, :categories], - utilities: [:files, :definitions, :contact, :links, :license, :embed] + utilities: [:form, :files, :definitions, :contact, :links, :license, :embed] } include AsIndirectObject diff --git a/app/models/communication/block/template/form.rb b/app/models/communication/block/template/form.rb new file mode 100644 index 000000000..75e7f2673 --- /dev/null +++ b/app/models/communication/block/template/form.rb @@ -0,0 +1,38 @@ +class Communication::Block::Template::Form < Communication::Block::Template::Base + + has_component :url, :string + has_component :form_title, :string + + # Quand on ajoutera d'autres plateformes, faire un service comme les vidéos + def iframe + "" + end + + def iframe_preview + "" + end + + def script + "" + end + + def identifier + @identifier ||= url.remove('https://tally.so/r/') + end + + def platform + @platform ||= url.include?('tally.so') ? :tally : nil + end + + def csp_domains + [ + 'tally.so' + ] + end + + protected + + def embed_url + @embed_url ||= "https://tally.so/embed/#{identifier}?alignLeft=1&hideTitle=1&transparentBackground=1&dynamicHeight=1" + end +end diff --git a/app/models/communication/block/with_template.rb b/app/models/communication/block/with_template.rb index 3d6ce3fe5..e9563d233 100644 --- a/app/models/communication/block/with_template.rb +++ b/app/models/communication/block/with_template.rb @@ -40,6 +40,7 @@ module Communication::Block::WithTemplate volumes: 3310, jobs: 3400, categories: 3500, + form: 4041, license: 4040, links: 4050 }, prefix: :template diff --git a/app/models/communication/website/with_realm_communication.rb b/app/models/communication/website/with_realm_communication.rb index 0b6a34582..c55fdb25e 100644 --- a/app/models/communication/website/with_realm_communication.rb +++ b/app/models/communication/website/with_realm_communication.rb @@ -12,4 +12,18 @@ module Communication::Website::WithRealmCommunication alias :blocks :communication_blocks end + def all_blocks + @all_blocks ||= Communication::Block.where(id: all_blocks_ids) + end + + protected + + def all_blocks_ids + @all_blocks_ids ||= ( + blocks.pluck(:id) + + blocks_from_education.pluck(:id) + + blocks_from_research.pluck(:id) + + blocks_from_university.pluck(:id) + ).compact_blank.uniq + end end diff --git a/app/models/communication/website/with_security.rb b/app/models/communication/website/with_security.rb index 26da7008c..69a4136db 100644 --- a/app/models/communication/website/with_security.rb +++ b/app/models/communication/website/with_security.rb @@ -5,6 +5,7 @@ def allowed_domains list = allowed_domains_default list.concat allowed_domains_plausible list.concat allowed_domains_from_all_blocks_video + list.concat allowed_domains_from_all_blocks_form list.concat allowed_domains_from_all_blocks_embed list.uniq.compact end @@ -27,15 +28,8 @@ def allowed_domains_plausible end def allowed_domains_from_all_blocks_video - allowed_domains_from_blocks_video(blocks) + - allowed_domains_from_blocks_video(blocks_from_education) + - allowed_domains_from_blocks_video(blocks_from_research) + - allowed_domains_from_blocks_video(blocks_from_university) - end - - def allowed_domains_from_blocks_video(blocks) list = [] - blocks.template_video.each do |block| + all_blocks.template_video.each do |block| video_url = block.template.url next unless video_url.present? list.concat Video::Provider.find(video_url).csp_domains @@ -43,16 +37,17 @@ def allowed_domains_from_blocks_video(blocks) list end - def allowed_domains_from_all_blocks_embed - allowed_domains_from_blocks_embed(blocks) + - allowed_domains_from_blocks_embed(blocks_from_education) + - allowed_domains_from_blocks_embed(blocks_from_research) + - allowed_domains_from_blocks_embed(blocks_from_university) + def allowed_domains_from_all_blocks_form + list = [] + all_blocks.template_form.published.each do |block| + list += block.template.csp_domains + end + list end - def allowed_domains_from_blocks_embed(blocks) + def allowed_domains_from_all_blocks_embed list = [] - blocks.template_embed.published.each do |block| + all_blocks.template_embed.published.each do |block| code = block.template.code # https://stackoverflow.com/questions/25095176/extracting-all-urls-from-a-page-using-ruby code.scan(/[[:lower:]]+:\/\/[^\s"]+/).each do |url| @@ -63,6 +58,8 @@ def allowed_domains_from_blocks_embed(blocks) list end + # @SebouChu tu crois pas qu'on devrait mettre ça dans le template Embed ? + # Comme ça il fournit ses domaines et basta, non ? def load_allowed_domain_from_url(url) url = CGI.unescapeHTML(url) url = ActionController::Base.helpers.strip_tags(url) diff --git a/app/views/admin/communication/blocks/group/_editor.html.erb b/app/views/admin/communication/blocks/group/_editor.html.erb index 21db90d7f..16ab9be26 100644 --- a/app/views/admin/communication/blocks/group/_editor.html.erb +++ b/app/views/admin/communication/blocks/group/_editor.html.erb @@ -26,4 +26,8 @@ reorder_url = reorder_admin_communication_blocks_path( data-reorder-url="<%= reorder_url %>"> <%= render 'admin/communication/blocks/group/editor/paste', about: about %> -<%= render 'admin/communication/blocks/group/editor/reset', about: about %> \ No newline at end of file +<%= render 'admin/communication/blocks/group/editor/reset', about: about %> + +<% content_for :javascript do %> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/communication/blocks/templates/form/_edit.html.erb b/app/views/admin/communication/blocks/templates/form/_edit.html.erb new file mode 100644 index 000000000..87816420f --- /dev/null +++ b/app/views/admin/communication/blocks/templates/form/_edit.html.erb @@ -0,0 +1,3 @@ +

<%= t('admin.communication.blocks.templates.form.edit.warning_html') %>

+<%= block_component_edit block, :url %> +<%= block_component_edit block, :form_title %> \ No newline at end of file diff --git a/app/views/admin/communication/blocks/templates/form/_show.html.erb b/app/views/admin/communication/blocks/templates/form/_show.html.erb new file mode 100644 index 000000000..6b7468513 --- /dev/null +++ b/app/views/admin/communication/blocks/templates/form/_show.html.erb @@ -0,0 +1,8 @@ +
+
+
+ <%= raw block.template.iframe %> + <%= raw block.template.script %> +
+
+
\ No newline at end of file diff --git a/app/views/admin/communication/blocks/templates/form/_snippet.html.erb b/app/views/admin/communication/blocks/templates/form/_snippet.html.erb new file mode 100644 index 000000000..406a83158 --- /dev/null +++ b/app/views/admin/communication/blocks/templates/form/_snippet.html.erb @@ -0,0 +1 @@ +<%= raw block.template.iframe_preview %> \ No newline at end of file diff --git a/app/views/admin/communication/blocks/templates/form/_static.html.erb b/app/views/admin/communication/blocks/templates/form/_static.html.erb new file mode 100644 index 000000000..02c7560c1 --- /dev/null +++ b/app/views/admin/communication/blocks/templates/form/_static.html.erb @@ -0,0 +1,11 @@ +<%= block_component_static block, :url %> +<%= block_component_static block, :form_title %> +<% if block.template.url.present? %> + form: + platform: "<%= block.template.platform %>" + identifier: "<%= block.template.identifier %>" + iframe: >- + <%= raw block.template.iframe %> + script: >- + <%= raw block.template.script %> +<% end %> diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index a059a34d2..f89374694 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -13,6 +13,7 @@ script_urls = %w( https://example.osuny.org/js/ https://plausible.io + https://tally.so https://d2wy8f7a9ursnm.cloudfront.net/v7/ ) script_urls << "https://cdn.jsdelivr.net/npm/summernote@#{SummernoteRails::Rails::VERSION.split('.').take(3).join('.')}/dist/lang/" diff --git a/config/locales/communication/blocks/en.yml b/config/locales/communication/blocks/en.yml index 69d7fa270..fcd88bd9a 100644 --- a/config/locales/communication/blocks/en.yml +++ b/config/locales/communication/blocks/en.yml @@ -373,6 +373,19 @@ en: label: Title placeholder: Enter title here remove_file: Remove a file + form: + description: A form, so users can send data or ask questions. + edit: + form_title: + hint: Helps people with disabilities + label: Form title + placeholder: Type the form title + url: + hint: | + Ex: https://tally.so/r/jaY00R + label: Form URL + placeholder: Enter the form URL + warning_html: This block lets you integrate Tally forms. gallery: description: A gallery of images, with an accessible description, a text and a credit for each image. edit: @@ -916,6 +929,7 @@ en: exhibitions: Exhibitions features: Features files: Files + form: Form gallery: Gallery image: Image jobs: Job offers diff --git a/config/locales/communication/blocks/fr.yml b/config/locales/communication/blocks/fr.yml index 950689282..4a4fa7b57 100644 --- a/config/locales/communication/blocks/fr.yml +++ b/config/locales/communication/blocks/fr.yml @@ -374,6 +374,19 @@ fr: label: Titre placeholder: Entrer le titre du fichier remove_file: Supprimer le fichier + form: + description: Un formulaire permettant aux internautes d'envoyer des informations ou de poser des questions. + edit: + form_title: + hint: Utile pour l'accessibilité aux personnes en situation de handicap + label: Titre du formulaire + placeholder: Indiquer le titre du formulaire + url: + hint: | + Ex: https://tally.so/r/jaY00R + label: URL du formulaire + placeholder: Entrer l'URL du formulaire + warning_html: Le bloc permet d'intégrer les formulaires Tally. gallery: description: Une galerie d'images, avec pour chaque image une description accessible, un texte et un crédit. edit: @@ -917,6 +930,7 @@ fr: exhibitions: Expositions features: Fonctionnalités files: Fichiers + form: Formulaire gallery: Galerie image: Image jobs: Offres d'emploi