Allow accepting all cookies in consent banner and management component
Create cookie consent "all" when accept all cookies 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:
@@ -6,6 +6,11 @@
|
||||
$("#cookies_consent_management").foundation("close");
|
||||
},
|
||||
initialize: function() {
|
||||
$(".accept-all-cookies").on("click", function() {
|
||||
App.Cookies.saveCookie("cookies_consent", "all", 365);
|
||||
App.CookiesConsent.hide();
|
||||
});
|
||||
|
||||
$(".accept-essential-cookies").on("click", function() {
|
||||
App.Cookies.saveCookie("cookies_consent", "essential", 365);
|
||||
App.CookiesConsent.hide();
|
||||
|
||||
@@ -14,9 +14,14 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&.accept-all-cookies,
|
||||
&.accept-essential-cookies {
|
||||
@include regular-button;
|
||||
margin-bottom: 0;
|
||||
|
||||
@include breakpoint(small only) {
|
||||
margin-bottom: $line-height / 3;
|
||||
}
|
||||
}
|
||||
|
||||
&.manage-cookies {
|
||||
|
||||
@@ -24,10 +24,17 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&.accept-all-cookies,
|
||||
&.accept-essential-cookies {
|
||||
@include regular-button;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&.accept-all-cookies {
|
||||
@include breakpoint(small only) {
|
||||
margin-bottom: $line-height / 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
<p><%= link_to t("cookies_consent.more_info_link"), more_info_link %></p>
|
||||
<% end %>
|
||||
|
||||
<% if vendors.any? %>
|
||||
<button type="button" class="accept-all-cookies"><%= t("cookies_consent.accept_all_cookies") %></button>
|
||||
<% end %>
|
||||
<button type="button" class="accept-essential-cookies"><%= t("cookies_consent.accept_essential_cookies") %></button>
|
||||
<button type="button" data-open="cookies_consent_management" class="manage-cookies"><%= t("cookies_consent.management") %></button>
|
||||
</div>
|
||||
|
||||
@@ -6,4 +6,8 @@ class Layout::CookiesConsent::BaseComponent < ApplicationComponent
|
||||
def more_info_link
|
||||
Setting["cookies_consent.more_info_link"]
|
||||
end
|
||||
|
||||
def vendors
|
||||
Cookies::Vendor.all
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<% if vendors.any? %>
|
||||
<button type="button" class="accept-all-cookies"><%= t("cookies_consent.accept_all_cookies") %></button>
|
||||
<% end %>
|
||||
<button type="button" class="accept-essential-cookies"><%= t("cookies_consent.accept_essential_cookies") %></button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -935,6 +935,7 @@ en:
|
||||
comments_summary: "Comments summary"
|
||||
info_text: "Content generated by AI / Machine Learning"
|
||||
cookies_consent:
|
||||
accept_all_cookies: "Accept all"
|
||||
accept_essential_cookies: "Accept essential cookies"
|
||||
message: "Cookies help us deliver our services. By using our services, you agree to our use of cookies."
|
||||
more_info_link: "More information about cookies"
|
||||
|
||||
@@ -935,6 +935,7 @@ es:
|
||||
comments_summary: "Resumen de comentarios"
|
||||
info_text: "Contenido generado mediante IA / Machine Learning"
|
||||
cookies_consent:
|
||||
accept_all_cookies: "Aceptar todo"
|
||||
accept_essential_cookies: "Aceptar cookies esenciales"
|
||||
message: "Las cookies nos ayudan a ofrecer nuestros servicios. Al utilizar nuestros servicios, aceptas el uso de cookies."
|
||||
more_info_link: "Más información sobre cookies"
|
||||
|
||||
@@ -21,12 +21,14 @@ describe Layout::CookiesConsent::BannerComponent do
|
||||
|
||||
it "renders the banner content when feature `cookies_consent` is enabled and cookies were not accepted" do
|
||||
Setting["cookies_consent.more_info_link"] = "/cookies_policy"
|
||||
create(:cookies_vendor)
|
||||
|
||||
render_inline Layout::CookiesConsent::BannerComponent.new
|
||||
|
||||
expect(page).to be_rendered
|
||||
expect(page).to have_css "h2", text: "Cookies policy"
|
||||
expect(page).to have_link "More information about cookies", href: "/cookies_policy"
|
||||
expect(page).to have_button "Accept all"
|
||||
expect(page).to have_button "Accept essential cookies"
|
||||
expect(page).to have_button "Manage cookies"
|
||||
end
|
||||
@@ -39,4 +41,11 @@ describe Layout::CookiesConsent::BannerComponent do
|
||||
expect(page).not_to have_link "More information about cookies"
|
||||
expect(page).to be_rendered
|
||||
end
|
||||
|
||||
it "does not render an `Accept all` button when there aren't any cookie vendors" do
|
||||
render_inline Layout::CookiesConsent::BannerComponent.new
|
||||
|
||||
expect(page).not_to have_button "Accept all"
|
||||
expect(page).to be_rendered
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,6 +13,7 @@ describe Layout::CookiesConsent::ManagementComponent do
|
||||
|
||||
it "is rendered when the cookies consent is enabled" do
|
||||
Setting["cookies_consent.more_info_link"] = "/cookies_policy"
|
||||
create(:cookies_vendor)
|
||||
|
||||
render_inline Layout::CookiesConsent::ManagementComponent.new
|
||||
|
||||
@@ -21,6 +22,7 @@ describe Layout::CookiesConsent::ManagementComponent do
|
||||
expect(page).to have_link "More information about cookies", href: "/cookies_policy"
|
||||
expect(page).to have_css "h3", text: "Essential cookies"
|
||||
expect(page).to have_css ".switch-input[type='checkbox'][name='essential_cookies'][disabled][checked]"
|
||||
expect(page).to have_button "Accept all"
|
||||
expect(page).to have_button "Accept essential cookies"
|
||||
end
|
||||
|
||||
@@ -32,4 +34,11 @@ describe Layout::CookiesConsent::ManagementComponent do
|
||||
expect(page).not_to have_link "More information about cookies"
|
||||
expect(page).to be_rendered
|
||||
end
|
||||
|
||||
it "does not render an `Accept all` button when there aren't any cookie vendors" do
|
||||
render_inline Layout::CookiesConsent::ManagementComponent.new
|
||||
|
||||
expect(page).not_to have_button "Accept all"
|
||||
expect(page).to be_rendered
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,6 +20,23 @@ describe "Cookies consent" do
|
||||
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
end
|
||||
|
||||
scenario "Hides the banner when accepting all cookies and for consecutive visits" do
|
||||
visit root_path
|
||||
|
||||
expect(cookie_by_name("cookies_consent")).to be nil
|
||||
|
||||
within ".cookies-consent-banner" do
|
||||
click_button "Accept all"
|
||||
end
|
||||
|
||||
expect(cookie_by_name("cookies_consent")[:value]).to eq "all"
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
|
||||
refresh
|
||||
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
end
|
||||
end
|
||||
|
||||
context "Management modal" do
|
||||
@@ -44,5 +61,27 @@ describe "Cookies consent" do
|
||||
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
end
|
||||
|
||||
scenario "Allow users to accept all cookies from the cookies management modal" do
|
||||
visit root_path
|
||||
|
||||
expect(cookie_by_name("cookies_consent")).to be nil
|
||||
|
||||
within ".cookies-consent-banner" do
|
||||
click_button "Manage cookies"
|
||||
end
|
||||
|
||||
within ".cookies-consent-management" do
|
||||
click_button "Accept all"
|
||||
end
|
||||
|
||||
expect(cookie_by_name("cookies_consent")[:value]).to eq "all"
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
expect(page).not_to have_content "Cookies management"
|
||||
|
||||
refresh
|
||||
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user