Allow accept essential cookies from consent banner
Set cookie duration to 365 days based on the AEPD's cookie usage guidelines. Note from the document: "Cookies with a duration of up to 24 months are considered acceptable as long as they are periodically updated." Reference: https://www.aepd.es/guias/guia-cookies.pdf
This commit is contained in:
@@ -113,6 +113,7 @@
|
|||||||
//= require globalize
|
//= require globalize
|
||||||
//= require settings
|
//= require settings
|
||||||
//= require cookies
|
//= require cookies
|
||||||
|
//= require cookies_consent
|
||||||
//= require columns_selector
|
//= require columns_selector
|
||||||
//= require budget_edit_associations
|
//= require budget_edit_associations
|
||||||
//= require budget_hide_money
|
//= require budget_hide_money
|
||||||
@@ -179,6 +180,7 @@ var initialize_modules = function() {
|
|||||||
App.SDGRelatedListSelector.initialize();
|
App.SDGRelatedListSelector.initialize();
|
||||||
App.SDGManagementRelationSearch.initialize();
|
App.SDGManagementRelationSearch.initialize();
|
||||||
App.AuthenticityTokenRefresh.initialize();
|
App.AuthenticityTokenRefresh.initialize();
|
||||||
|
App.CookiesConsent.initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
var destroy_non_idempotent_modules = function() {
|
var destroy_non_idempotent_modules = function() {
|
||||||
|
|||||||
14
app/assets/javascripts/cookies_consent.js
Normal file
14
app/assets/javascripts/cookies_consent.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
App.CookiesConsent = {
|
||||||
|
hide: function() {
|
||||||
|
$("#cookies_consent_banner").hide();
|
||||||
|
},
|
||||||
|
initialize: function() {
|
||||||
|
$(".accept-essential-cookies").on("click", function() {
|
||||||
|
App.Cookies.saveCookie("cookies_consent", "essential", 365);
|
||||||
|
App.CookiesConsent.hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}).call(this);
|
||||||
@@ -7,4 +7,16 @@
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
right: $line-height / 3;
|
right: $line-height / 3;
|
||||||
z-index: 20;
|
z-index: 20;
|
||||||
|
|
||||||
|
button {
|
||||||
|
@include breakpoint(small only) {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.accept-essential-cookies {
|
||||||
|
@include regular-button;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<div id="cookies_consent_banner" class="cookies-consent-banner">
|
<div id="cookies_consent_banner" class="cookies-consent-banner">
|
||||||
<h2><%= t("cookies_consent.title") %></h2>
|
<h2><%= t("cookies_consent.title") %></h2>
|
||||||
<p><%= t("cookies_consent.message") %></p>
|
<p><%= t("cookies_consent.message") %></p>
|
||||||
|
<button type="button" class="accept-essential-cookies"><%= t("cookies_consent.accept_essential_cookies") %></button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
class Layout::CookiesConsent::BannerComponent < ApplicationComponent
|
class Layout::CookiesConsent::BannerComponent < ApplicationComponent
|
||||||
|
delegate :cookies, to: :helpers
|
||||||
|
|
||||||
def render?
|
def render?
|
||||||
feature?(:cookies_consent)
|
feature?(:cookies_consent) && cookies_consent_unset?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def cookies_consent_unset?
|
||||||
|
cookies["cookies_consent"].blank?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -934,5 +934,6 @@ en:
|
|||||||
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:
|
cookies_consent:
|
||||||
|
accept_essential_cookies: "Accept essential cookies"
|
||||||
message: "Cookies help us deliver our services. By using our services, you agree to our use of cookies."
|
message: "Cookies help us deliver our services. By using our services, you agree to our use of cookies."
|
||||||
title: "Cookies policy"
|
title: "Cookies policy"
|
||||||
|
|||||||
@@ -934,5 +934,6 @@ es:
|
|||||||
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:
|
cookies_consent:
|
||||||
|
accept_essential_cookies: "Aceptar cookies esenciales"
|
||||||
message: "Las cookies nos ayudan a ofrecer nuestros servicios. Al utilizar nuestros servicios, aceptas el uso de cookies."
|
message: "Las cookies nos ayudan a ofrecer nuestros servicios. Al utilizar nuestros servicios, aceptas el uso de cookies."
|
||||||
title: "Política de cookies"
|
title: "Política de cookies"
|
||||||
|
|||||||
@@ -3,6 +3,14 @@ require "rails_helper"
|
|||||||
describe Layout::CookiesConsent::BannerComponent do
|
describe Layout::CookiesConsent::BannerComponent do
|
||||||
before { Setting["feature.cookies_consent"] = true }
|
before { Setting["feature.cookies_consent"] = true }
|
||||||
|
|
||||||
|
it "does not render the banner when cookies were accepted" do
|
||||||
|
vc_test_request.cookies[:cookies_consent] = "essential"
|
||||||
|
|
||||||
|
render_inline Layout::CookiesConsent::BannerComponent.new
|
||||||
|
|
||||||
|
expect(page).not_to be_rendered
|
||||||
|
end
|
||||||
|
|
||||||
it "does not render the banner when feature `cookies_consent` is disabled" do
|
it "does not render the banner when feature `cookies_consent` is disabled" do
|
||||||
Setting["feature.cookies_consent"] = nil
|
Setting["feature.cookies_consent"] = nil
|
||||||
|
|
||||||
@@ -11,10 +19,11 @@ describe Layout::CookiesConsent::BannerComponent do
|
|||||||
expect(page).not_to be_rendered
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders the banner content when feature `cookies_consent` is enabled" do
|
it "renders the banner content when feature `cookies_consent` is enabled and cookies were not accepted" do
|
||||||
render_inline Layout::CookiesConsent::BannerComponent.new
|
render_inline Layout::CookiesConsent::BannerComponent.new
|
||||||
|
|
||||||
expect(page).to be_rendered
|
expect(page).to be_rendered
|
||||||
expect(page).to have_css "h2", text: "Cookies policy"
|
expect(page).to have_css "h2", text: "Cookies policy"
|
||||||
|
expect(page).to have_button "Accept essential cookies"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,13 +3,22 @@ require "rails_helper"
|
|||||||
describe "Cookies consent" do
|
describe "Cookies consent" do
|
||||||
before { Setting["feature.cookies_consent"] = true }
|
before { Setting["feature.cookies_consent"] = true }
|
||||||
|
|
||||||
scenario "Shows the cookies consent banner and for consecutive visits" do
|
context "Banner consent" do
|
||||||
|
scenario "Hides the banner when accepting essential cookies and for consecutive visits" do
|
||||||
visit root_path
|
visit root_path
|
||||||
|
|
||||||
expect(page).to have_css "h2", text: "Cookies policy"
|
expect(cookie_by_name("cookies_consent")).to be nil
|
||||||
|
|
||||||
|
within ".cookies-consent-banner" do
|
||||||
|
click_button "Accept essential cookies"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(cookie_by_name("cookies_consent")[:value]).to eq "essential"
|
||||||
|
expect(page).not_to have_content "Cookies policy"
|
||||||
|
|
||||||
refresh
|
refresh
|
||||||
|
|
||||||
expect(page).to have_css "h2", text: "Cookies policy"
|
expect(page).not_to have_content "Cookies policy"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user