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:
10
app/assets/stylesheets/layout/cookies_consent_banner.scss
Normal file
10
app/assets/stylesheets/layout/cookies_consent_banner.scss
Normal 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;
|
||||
}
|
||||
@@ -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 %>
|
||||
@@ -0,0 +1,5 @@
|
||||
class Admin::Settings::CookiesConsentTabComponent < ApplicationComponent
|
||||
def tab
|
||||
"#tab-cookies-consent"
|
||||
end
|
||||
end
|
||||
@@ -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>
|
||||
@@ -0,0 +1,5 @@
|
||||
class Layout::CookiesConsent::BannerComponent < ApplicationComponent
|
||||
def render?
|
||||
feature?(:cookies_consent)
|
||||
end
|
||||
end
|
||||
@@ -88,6 +88,7 @@ class Setting < ApplicationRecord
|
||||
"feature.sdg": true,
|
||||
"feature.machine_learning": false,
|
||||
"feature.remove_investments_supports": true,
|
||||
"feature.cookies_consent": false,
|
||||
"homepage.widgets.feeds.debates": true,
|
||||
"homepage.widgets.feeds.processes": true,
|
||||
"homepage.widgets.feeds.proposals": true,
|
||||
|
||||
@@ -53,4 +53,9 @@
|
||||
<% end %>
|
||||
</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>
|
||||
|
||||
@@ -33,4 +33,8 @@
|
||||
<div class="tabs-panel" id="tab-sdg-configuration">
|
||||
<%= render Admin::Settings::SDGConfigurationTabComponent.new %>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="tab-cookies-consent">
|
||||
<%= render Admin::Settings::CookiesConsentTabComponent.new %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -28,5 +28,6 @@
|
||||
<div class="footer">
|
||||
<%= render Layout::FooterComponent.new %>
|
||||
</div>
|
||||
<%= render Layout::CookiesConsent::BannerComponent.new %>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1352,6 +1352,10 @@ en:
|
||||
sdg:
|
||||
title: SDG configuration
|
||||
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_request_name: Request Data
|
||||
remote_census_response_name: Response Data
|
||||
|
||||
@@ -933,3 +933,6 @@ en:
|
||||
machine_learning:
|
||||
comments_summary: "Comments summary"
|
||||
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"
|
||||
|
||||
@@ -134,6 +134,8 @@ en:
|
||||
remove_investments_supports_description: "Allow users to remove supports on participatory budgets investments during the selecting projects phase."
|
||||
sdg: SDG
|
||||
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:
|
||||
general:
|
||||
endpoint: "Endpoint"
|
||||
|
||||
@@ -1352,6 +1352,10 @@ es:
|
||||
sdg:
|
||||
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".'
|
||||
cookies_consent:
|
||||
title: Consentimiento de cookies
|
||||
cookies_consent_banner:
|
||||
title: Banner de consentimiento de cookies
|
||||
remote_census_general_name: Datos Generales
|
||||
remote_census_request_name: Datos Petición
|
||||
remote_census_response_name: Datos Respuesta
|
||||
|
||||
@@ -933,3 +933,6 @@ es:
|
||||
machine_learning:
|
||||
comments_summary: "Resumen de comentarios"
|
||||
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"
|
||||
|
||||
@@ -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."
|
||||
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.
|
||||
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:
|
||||
general:
|
||||
endpoint: "Endpoint"
|
||||
|
||||
@@ -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
|
||||
15
spec/system/cookies_consent_spec.rb
Normal file
15
spec/system/cookies_consent_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user