Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/models/communication/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions app/models/communication/block/template/form.rb
Original file line number Diff line number Diff line change
@@ -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
"<iframe data-tally-src=\"#{embed_url}\" loading=\"lazy\" width=\"100%\" height=\"100\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" title=\"#{form_title}\"></iframe>"
end

def iframe_preview
"<iframe src=\"#{embed_url}\" loading=\"lazy\" width=\"100%\" height=\"100\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" title=\"#{form_title}\"></iframe>"
end

def script
"<script src=\"https://tally.so/widgets/embed.js\" onload=\"Tally.loadEmbeds()\"></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
1 change: 1 addition & 0 deletions app/models/communication/block/with_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Communication::Block::WithTemplate
volumes: 3310,
jobs: 3400,
categories: 3500,
form: 4041,
license: 4040,
links: 4050
}, prefix: :template
Expand Down
14 changes: 14 additions & 0 deletions app/models/communication/website/with_realm_communication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 12 additions & 15 deletions app/models/communication/website/with_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,32 +28,26 @@ 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
end
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|
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ reorder_url = reorder_admin_communication_blocks_path(
data-reorder-url="<%= reorder_url %>">
</div>
<%= render 'admin/communication/blocks/group/editor/paste', about: about %>
<%= render 'admin/communication/blocks/group/editor/reset', about: about %>
<%= render 'admin/communication/blocks/group/editor/reset', about: about %>

<% content_for :javascript do %>
<script src="https://tally.so/widgets/embed.js"></script>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p><%= t('admin.communication.blocks.templates.form.edit.warning_html') %></p>
<%= block_component_edit block, :url %>
<%= block_component_edit block, :form_title %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="block block-form">
<div class="container">
<div class="block-content">
<%= raw block.template.iframe %>
<%= raw block.template.script %>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= raw block.template.iframe_preview %>
Original file line number Diff line number Diff line change
@@ -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 %>
1 change: 1 addition & 0 deletions config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
14 changes: 14 additions & 0 deletions config/locales/communication/blocks/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://tally.so" target="_blank">Tally</a> forms.
gallery:
description: A gallery of images, with an accessible description, a text and a credit for each image.
edit:
Expand Down Expand Up @@ -916,6 +929,7 @@ en:
exhibitions: Exhibitions
features: Features
files: Files
form: Form
gallery: Gallery
image: Image
jobs: Job offers
Expand Down
14 changes: 14 additions & 0 deletions config/locales/communication/blocks/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://tally.so" target="_blank">Tally</a>.
gallery:
description: Une galerie d'images, avec pour chaque image une description accessible, un texte et un crédit.
edit:
Expand Down Expand Up @@ -917,6 +930,7 @@ fr:
exhibitions: Expositions
features: Fonctionnalités
files: Fichiers
form: Formulaire
gallery: Galerie
image: Image
jobs: Offres d'emploi
Expand Down
Loading