Add cookies consent banner

Allow enabling from settings admin section.

Note that we set the z-index to 20 in order to will be greater than
the others z-index elements in the application like <header> on
mobile devices.
This commit is contained in:
taitus
2024-12-10 11:30:47 +01:00
parent 73ec07174e
commit 4c0b6455f6
17 changed files with 95 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
.cookies-consent-banner {
@include brand-border;
background: inherit;
bottom: $line-height / 3;
left: $line-height / 3;
padding: 2rem;
position: fixed;
right: $line-height / 3;
z-index: 20;
}

View File

@@ -0,0 +1,5 @@
<h2><%= t("admin.settings.index.cookies_consent_banner.title") %></h2>
<%= render Admin::Settings::TableComponent.new(setting_name: "feature") do %>
<%= render Admin::Settings::RowComponent.new("feature.cookies_consent", type: :feature, tab: tab) %>
<% end %>

View File

@@ -0,0 +1,5 @@
class Admin::Settings::CookiesConsentTabComponent < ApplicationComponent
def tab
"#tab-cookies-consent"
end
end

View File

@@ -0,0 +1,4 @@
<div id="cookies_consent_banner" class="cookies-consent-banner">
<h2><%= t("cookies_consent.title") %></h2>
<p><%= t("cookies_consent.message") %></p>
</div>

View File

@@ -0,0 +1,5 @@
class Layout::CookiesConsent::BannerComponent < ApplicationComponent
def render?
feature?(:cookies_consent)
end
end

View File

@@ -88,6 +88,7 @@ class Setting < ApplicationRecord
"feature.sdg": true, "feature.sdg": true,
"feature.machine_learning": false, "feature.machine_learning": false,
"feature.remove_investments_supports": true, "feature.remove_investments_supports": true,
"feature.cookies_consent": false,
"homepage.widgets.feeds.debates": true, "homepage.widgets.feeds.debates": true,
"homepage.widgets.feeds.processes": true, "homepage.widgets.feeds.processes": true,
"homepage.widgets.feeds.proposals": true, "homepage.widgets.feeds.proposals": true,

View File

@@ -53,4 +53,9 @@
<% end %> <% end %>
</li> </li>
<li class="tabs-title" id="cookies-consent-tab">
<%= link_to "#tab-cookies-consent" do %>
<%= t("admin.settings.index.cookies_consent.title") %>
<% end %>
</li>
</ul> </ul>

View File

@@ -33,4 +33,8 @@
<div class="tabs-panel" id="tab-sdg-configuration"> <div class="tabs-panel" id="tab-sdg-configuration">
<%= render Admin::Settings::SDGConfigurationTabComponent.new %> <%= render Admin::Settings::SDGConfigurationTabComponent.new %>
</div> </div>
<div class="tabs-panel" id="tab-cookies-consent">
<%= render Admin::Settings::CookiesConsentTabComponent.new %>
</div>
</div> </div>

View File

@@ -28,5 +28,6 @@
<div class="footer"> <div class="footer">
<%= render Layout::FooterComponent.new %> <%= render Layout::FooterComponent.new %>
</div> </div>
<%= render Layout::CookiesConsent::BannerComponent.new %>
</body> </body>
</html> </html>

View File

@@ -1352,6 +1352,10 @@ en:
sdg: sdg:
title: SDG configuration title: SDG configuration
how_to_enable: 'To show the configuration options from Sustainable Development Goals you must enable "SDG" on "Features" tab.' how_to_enable: 'To show the configuration options from Sustainable Development Goals you must enable "SDG" on "Features" tab.'
cookies_consent:
title: Cookies consent
cookies_consent_banner:
title: Cookies consent banner
remote_census_general_name: General Information remote_census_general_name: General Information
remote_census_request_name: Request Data remote_census_request_name: Request Data
remote_census_response_name: Response Data remote_census_response_name: Response Data

View File

@@ -933,3 +933,6 @@ en:
machine_learning: machine_learning:
comments_summary: "Comments summary" comments_summary: "Comments summary"
info_text: "Content generated by AI / Machine Learning" info_text: "Content generated by AI / Machine Learning"
cookies_consent:
message: "Cookies help us deliver our services. By using our services, you agree to our use of cookies."
title: "Cookies policy"

View File

@@ -134,6 +134,8 @@ en:
remove_investments_supports_description: "Allow users to remove supports on participatory budgets investments during the selecting projects phase." remove_investments_supports_description: "Allow users to remove supports on participatory budgets investments during the selecting projects phase."
sdg: SDG sdg: SDG
sdg_description: Enable Sustainable Development Goals sections in the administration menu and in the Global Settings. sdg_description: Enable Sustainable Development Goals sections in the administration menu and in the Global Settings.
cookies_consent: Cookies consent banner
cookies_consent_description: Enable the cookies consent banner to inform users about the cookies the application uses.
remote_census: remote_census:
general: general:
endpoint: "Endpoint" endpoint: "Endpoint"

View File

@@ -1352,6 +1352,10 @@ es:
sdg: sdg:
title: Configuración ODS title: Configuración ODS
how_to_enable: 'Para mostrar las opciones de configuración de los Objetivos de Desarrollo Sostenible se debe activar "ODS" en la pestaña "Funcionalidades".' how_to_enable: 'Para mostrar las opciones de configuración de los Objetivos de Desarrollo Sostenible se debe activar "ODS" en la pestaña "Funcionalidades".'
cookies_consent:
title: Consentimiento de cookies
cookies_consent_banner:
title: Banner de consentimiento de cookies
remote_census_general_name: Datos Generales remote_census_general_name: Datos Generales
remote_census_request_name: Datos Petición remote_census_request_name: Datos Petición
remote_census_response_name: Datos Respuesta remote_census_response_name: Datos Respuesta

View File

@@ -933,3 +933,6 @@ es:
machine_learning: machine_learning:
comments_summary: "Resumen de comentarios" comments_summary: "Resumen de comentarios"
info_text: "Contenido generado mediante IA / Machine Learning" info_text: "Contenido generado mediante IA / Machine Learning"
cookies_consent:
message: "Las cookies nos ayudan a ofrecer nuestros servicios. Al utilizar nuestros servicios, aceptas el uso de cookies."
title: "Política de cookies"

View File

@@ -134,6 +134,8 @@ es:
remove_investments_supports_description: "Permite que los usuarios retiren su apoyo en los proyectos de gasto de los presupuestos participativos durante la fase de apoyos." remove_investments_supports_description: "Permite que los usuarios retiren su apoyo en los proyectos de gasto de los presupuestos participativos durante la fase de apoyos."
sdg: ODS sdg: ODS
sdg_description: Habilitar secciones relacionadas con Objetivos de Desarrollo Sostenible en el menú de administración y en la sección de Configuración Global. sdg_description: Habilitar secciones relacionadas con Objetivos de Desarrollo Sostenible en el menú de administración y en la sección de Configuración Global.
cookies_consent: Banner de consentimiento de cookies
cookies_consent_description: Activa el banner de consentimiento de cookies para informar a los usuarios sobre las cookies que utiliza la aplicación.
remote_census: remote_census:
general: general:
endpoint: "Endpoint" endpoint: "Endpoint"

View File

@@ -0,0 +1,20 @@
require "rails_helper"
describe Layout::CookiesConsent::BannerComponent do
before { Setting["feature.cookies_consent"] = true }
it "does not render the banner when feature `cookies_consent` is disabled" do
Setting["feature.cookies_consent"] = nil
render_inline Layout::CookiesConsent::BannerComponent.new
expect(page).not_to be_rendered
end
it "renders the banner content when feature `cookies_consent` is enabled" do
render_inline Layout::CookiesConsent::BannerComponent.new
expect(page).to be_rendered
expect(page).to have_css "h2", text: "Cookies policy"
end
end

View File

@@ -0,0 +1,15 @@
require "rails_helper"
describe "Cookies consent" do
before { Setting["feature.cookies_consent"] = true }
scenario "Shows the cookies consent banner and for consecutive visits" do
visit root_path
expect(page).to have_css "h2", text: "Cookies policy"
refresh
expect(page).to have_css "h2", text: "Cookies policy"
end
end