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:
taitus
2024-12-10 11:36:38 +01:00
parent f4c3c4e639
commit 1958a77842
9 changed files with 64 additions and 7 deletions

View File

@@ -113,6 +113,7 @@
//= require globalize
//= require settings
//= require cookies
//= require cookies_consent
//= require columns_selector
//= require budget_edit_associations
//= require budget_hide_money
@@ -179,6 +180,7 @@ var initialize_modules = function() {
App.SDGRelatedListSelector.initialize();
App.SDGManagementRelationSearch.initialize();
App.AuthenticityTokenRefresh.initialize();
App.CookiesConsent.initialize();
};
var destroy_non_idempotent_modules = function() {

View 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);

View File

@@ -7,4 +7,16 @@
position: fixed;
right: $line-height / 3;
z-index: 20;
button {
@include breakpoint(small only) {
display: block;
width: 100%;
}
&.accept-essential-cookies {
@include regular-button;
margin-bottom: 0;
}
}
}

View File

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

View File

@@ -1,5 +1,13 @@
class Layout::CookiesConsent::BannerComponent < ApplicationComponent
delegate :cookies, to: :helpers
def render?
feature?(:cookies_consent)
feature?(:cookies_consent) && cookies_consent_unset?
end
private
def cookies_consent_unset?
cookies["cookies_consent"].blank?
end
end

View File

@@ -934,5 +934,6 @@ en:
comments_summary: "Comments summary"
info_text: "Content generated by AI / Machine Learning"
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."
title: "Cookies policy"

View File

@@ -934,5 +934,6 @@ es:
comments_summary: "Resumen de comentarios"
info_text: "Contenido generado mediante IA / Machine Learning"
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."
title: "Política de cookies"

View File

@@ -3,6 +3,14 @@ require "rails_helper"
describe Layout::CookiesConsent::BannerComponent do
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
Setting["feature.cookies_consent"] = nil
@@ -11,10 +19,11 @@ describe Layout::CookiesConsent::BannerComponent do
expect(page).not_to be_rendered
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
expect(page).to be_rendered
expect(page).to have_css "h2", text: "Cookies policy"
expect(page).to have_button "Accept essential cookies"
end
end

View File

@@ -3,13 +3,22 @@ require "rails_helper"
describe "Cookies consent" do
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
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
expect(page).to have_css "h2", text: "Cookies policy"
expect(page).not_to have_content "Cookies policy"
end
end
end