diff --git a/app/assets/javascripts/cookies_consent.js b/app/assets/javascripts/cookies_consent.js index 5d0e533c7..6f37b42ba 100644 --- a/app/assets/javascripts/cookies_consent.js +++ b/app/assets/javascripts/cookies_consent.js @@ -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(); diff --git a/app/assets/stylesheets/layout/cookies_consent_banner.scss b/app/assets/stylesheets/layout/cookies_consent_banner.scss index e0b59dbd3..06047112f 100644 --- a/app/assets/stylesheets/layout/cookies_consent_banner.scss +++ b/app/assets/stylesheets/layout/cookies_consent_banner.scss @@ -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 { diff --git a/app/assets/stylesheets/layout/cookies_consent_management.scss b/app/assets/stylesheets/layout/cookies_consent_management.scss index 10aebdde9..1636300a7 100644 --- a/app/assets/stylesheets/layout/cookies_consent_management.scss +++ b/app/assets/stylesheets/layout/cookies_consent_management.scss @@ -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; + } + } } } diff --git a/app/components/layout/cookies_consent/banner_component.html.erb b/app/components/layout/cookies_consent/banner_component.html.erb index ef6432b58..6c2fa346e 100644 --- a/app/components/layout/cookies_consent/banner_component.html.erb +++ b/app/components/layout/cookies_consent/banner_component.html.erb @@ -5,6 +5,9 @@
<%= link_to t("cookies_consent.more_info_link"), more_info_link %>
<% end %> + <% if vendors.any? %> + + <% end %> diff --git a/app/components/layout/cookies_consent/base_component.rb b/app/components/layout/cookies_consent/base_component.rb index 41b32eee7..922334a0d 100644 --- a/app/components/layout/cookies_consent/base_component.rb +++ b/app/components/layout/cookies_consent/base_component.rb @@ -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 diff --git a/app/components/layout/cookies_consent/management_component.html.erb b/app/components/layout/cookies_consent/management_component.html.erb index dad0cbabb..a640fcbd5 100644 --- a/app/components/layout/cookies_consent/management_component.html.erb +++ b/app/components/layout/cookies_consent/management_component.html.erb @@ -25,6 +25,9 @@ diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 407809720..5635ada01 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -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" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 8cbe6a81b..341001fbe 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -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" diff --git a/spec/components/layout/cookies_consent/banner_component_spec.rb b/spec/components/layout/cookies_consent/banner_component_spec.rb index 60359d85b..b947351d9 100644 --- a/spec/components/layout/cookies_consent/banner_component_spec.rb +++ b/spec/components/layout/cookies_consent/banner_component_spec.rb @@ -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 diff --git a/spec/components/layout/cookies_consent/management_component_spec.rb b/spec/components/layout/cookies_consent/management_component_spec.rb index 4d8f4c036..2eb79c925 100644 --- a/spec/components/layout/cookies_consent/management_component_spec.rb +++ b/spec/components/layout/cookies_consent/management_component_spec.rb @@ -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 diff --git a/spec/system/cookies_consent_spec.rb b/spec/system/cookies_consent_spec.rb index 59d46a2da..f70a9f672 100644 --- a/spec/system/cookies_consent_spec.rb +++ b/spec/system/cookies_consent_spec.rb @@ -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