Allow managing versions of cookies consent
This can be useful when adding a new cookie or making modifications that require asking the user again.
This commit is contained in:
@@ -11,9 +11,13 @@
|
||||
vendors: function() {
|
||||
return $(".cookies-vendors input[type=checkbox]");
|
||||
},
|
||||
cookieName: function() {
|
||||
var versionName = $("#cookies_consent_management").data("version-name");
|
||||
return "cookies_consent_" + versionName;
|
||||
},
|
||||
initialize: function() {
|
||||
$(".accept-all-cookies").on("click", function() {
|
||||
App.Cookies.saveCookie("cookies_consent", "all", 365);
|
||||
App.Cookies.saveCookie(App.CookiesConsent.cookieName(), "all", 365);
|
||||
App.CookiesConsent.vendors().each(function() {
|
||||
App.Cookies.saveCookie(this.name, true, 365);
|
||||
App.CookiesConsent.setCookiesConsent(this.id, true);
|
||||
@@ -22,7 +26,7 @@
|
||||
});
|
||||
|
||||
$(".accept-essential-cookies").on("click", function() {
|
||||
App.Cookies.saveCookie("cookies_consent", "essential", 365);
|
||||
App.Cookies.saveCookie(App.CookiesConsent.cookieName(), "essential", 365);
|
||||
App.CookiesConsent.vendors().each(function() {
|
||||
App.Cookies.saveCookie(this.name, false, 365);
|
||||
App.CookiesConsent.setCookiesConsent(this.id, false);
|
||||
@@ -31,7 +35,7 @@
|
||||
});
|
||||
|
||||
$(".save-cookies-preferences").on("click", function() {
|
||||
App.Cookies.saveCookie("cookies_consent", "custom", 365);
|
||||
App.Cookies.saveCookie(App.CookiesConsent.cookieName(), "custom", 365);
|
||||
App.CookiesConsent.vendors().each(function() {
|
||||
App.Cookies.saveCookie(this.name, this.checked, 365);
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<%= render Admin::Settings::TableComponent.new(setting_name: "feature") do %>
|
||||
<%= render Admin::Settings::RowComponent.new("feature.cookies_consent", type: :feature, tab: tab) %>
|
||||
<%= render Admin::Settings::RowComponent.new("cookies_consent.more_info_link", type: :text, tab: tab) %>
|
||||
<%= render Admin::Settings::RowComponent.new("cookies_consent.version_name", type: :text, tab: tab) %>
|
||||
<% end %>
|
||||
|
||||
<%= render Admin::Cookies::Vendors::TableComponent.new %>
|
||||
|
||||
@@ -8,6 +8,6 @@ class Layout::CookiesConsent::BannerComponent < Layout::CookiesConsent::BaseComp
|
||||
private
|
||||
|
||||
def cookies_consent_unset?
|
||||
cookies["cookies_consent"].blank?
|
||||
cookies["cookies_consent_#{version_name}"].blank?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,4 +10,8 @@ class Layout::CookiesConsent::BaseComponent < ApplicationComponent
|
||||
def vendors
|
||||
Cookies::Vendor.all
|
||||
end
|
||||
|
||||
def version_name
|
||||
Setting["cookies_consent.version_name"].to_s.strip
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<section id="cookies_consent_management" class="cookies-consent-management reveal" data-reveal aria-labelledby="modal_heading">
|
||||
<section id="cookies_consent_management"
|
||||
class="cookies-consent-management reveal"
|
||||
data-reveal
|
||||
aria-labelledby="modal_heading"
|
||||
data-version-name="<%= version_name %>">
|
||||
<header>
|
||||
<h2 id="modal_heading"><%= t("cookies_management.title") %></h2>
|
||||
<button class="close-button" aria-label="<%= t("admin.shared.close_modal") %>" type="button" data-close>
|
||||
|
||||
@@ -162,6 +162,7 @@ class Setting < ApplicationRecord
|
||||
"featured_proposals_number": 3,
|
||||
"feature.dashboard.notification_emails": nil,
|
||||
"cookies_consent.more_info_link": "",
|
||||
"cookies_consent.version_name": "v1",
|
||||
"machine_learning.comments_summary": false,
|
||||
"machine_learning.related_content": false,
|
||||
"machine_learning.tags": false,
|
||||
|
||||
@@ -231,3 +231,5 @@ en:
|
||||
cookies_consent:
|
||||
more_info_link: Link to cookies policy
|
||||
more_info_link_description: Link shown in the consent banner to the cookie policy page.
|
||||
version_name: Version name
|
||||
version_name_description: Change the version name to force all users to go through the cookie consent process again. This feature can be handy when introducing drastic cookie policy changes requiring a new user acknowledgement.
|
||||
|
||||
@@ -231,3 +231,5 @@ es:
|
||||
cookies_consent:
|
||||
more_info_link: Enlace a la política de cookies
|
||||
more_info_link_description: Enlace que se muestra en el banner de consentimiento a la página de política de cookies
|
||||
version_name: Nombre de la versión
|
||||
version_name_description: Cambia el nombre de la versión para obligar a todos los usuarios a realizar el proceso de consentimiento de cookies de nuevo. Esto puede ser particularmente útil cuando se introducen cambios drásticos en la política de cookies que requieren de un nuevo consentimiento explícito por parte de los usuarios.
|
||||
|
||||
@@ -4,7 +4,7 @@ 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"
|
||||
vc_test_request.cookies[:cookies_consent_v1] = "essential"
|
||||
|
||||
render_inline Layout::CookiesConsent::BannerComponent.new
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ require "rails_helper"
|
||||
describe "Cookies consent" do
|
||||
before do
|
||||
Setting["feature.cookies_consent"] = true
|
||||
Setting["cookies_consent.version_name"] = "v1"
|
||||
script = "$('body').append('Running third party script');"
|
||||
create(:cookies_vendor, name: "Third party", cookie: "third_party", script: script)
|
||||
end
|
||||
@@ -11,7 +12,7 @@ describe "Cookies consent" do
|
||||
scenario "Hides the banner when accepting essential cookies and for consecutive visits" do
|
||||
visit root_path
|
||||
|
||||
expect(cookie_by_name("cookies_consent")).to be nil
|
||||
expect(cookie_by_name("cookies_consent_v1")).to be nil
|
||||
expect(cookie_by_name("third_party")).to be nil
|
||||
expect(page).not_to have_content "Running third party script"
|
||||
|
||||
@@ -19,7 +20,7 @@ describe "Cookies consent" do
|
||||
click_button "Accept essential cookies"
|
||||
end
|
||||
|
||||
expect(cookie_by_name("cookies_consent")[:value]).to eq "essential"
|
||||
expect(cookie_by_name("cookies_consent_v1")[:value]).to eq "essential"
|
||||
expect(cookie_by_name("third_party")[:value]).to eq "false"
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
expect(page).not_to have_content "Running third party script"
|
||||
@@ -33,7 +34,7 @@ describe "Cookies consent" do
|
||||
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
|
||||
expect(cookie_by_name("cookies_consent_v1")).to be nil
|
||||
expect(cookie_by_name("third_party")).to be nil
|
||||
expect(page).not_to have_content "Running third party script"
|
||||
|
||||
@@ -41,7 +42,7 @@ describe "Cookies consent" do
|
||||
click_button "Accept all"
|
||||
end
|
||||
|
||||
expect(cookie_by_name("cookies_consent")[:value]).to eq "all"
|
||||
expect(cookie_by_name("cookies_consent_v1")[:value]).to eq "all"
|
||||
expect(cookie_by_name("third_party")[:value]).to eq "true"
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
expect(page).not_to have_content "Running third party script"
|
||||
@@ -57,7 +58,7 @@ describe "Cookies consent" do
|
||||
scenario "Allow users to accept essential cookies and hide management modal" do
|
||||
visit root_path
|
||||
|
||||
expect(cookie_by_name("cookies_consent")).to be nil
|
||||
expect(cookie_by_name("cookies_consent_v1")).to be nil
|
||||
expect(cookie_by_name("third_party")).to be nil
|
||||
expect(page).not_to have_content "Running third party script"
|
||||
|
||||
@@ -69,7 +70,7 @@ describe "Cookies consent" do
|
||||
click_button "Accept essential cookies"
|
||||
end
|
||||
|
||||
expect(cookie_by_name("cookies_consent")[:value]).to eq "essential"
|
||||
expect(cookie_by_name("cookies_consent_v1")[:value]).to eq "essential"
|
||||
expect(cookie_by_name("third_party")[:value]).to eq "false"
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
expect(page).not_to have_content "Cookies management"
|
||||
@@ -84,7 +85,7 @@ describe "Cookies consent" do
|
||||
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
|
||||
expect(cookie_by_name("cookies_consent_v1")).to be nil
|
||||
expect(cookie_by_name("third_party")).to be nil
|
||||
expect(page).not_to have_content "Running third party script"
|
||||
|
||||
@@ -96,7 +97,7 @@ describe "Cookies consent" do
|
||||
click_button "Accept all"
|
||||
end
|
||||
|
||||
expect(cookie_by_name("cookies_consent")[:value]).to eq "all"
|
||||
expect(cookie_by_name("cookies_consent_v1")[:value]).to eq "all"
|
||||
expect(cookie_by_name("third_party")[:value]).to eq "true"
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
expect(page).not_to have_content "Cookies management"
|
||||
@@ -111,7 +112,7 @@ describe "Cookies consent" do
|
||||
scenario "Allow users to accept custom cookies from the cookies management modal" do
|
||||
visit root_path
|
||||
|
||||
expect(cookie_by_name("cookies_consent")).to be nil
|
||||
expect(cookie_by_name("cookies_consent_v1")).to be nil
|
||||
expect(cookie_by_name("third_party")).to be nil
|
||||
|
||||
within ".cookies-consent-banner" do
|
||||
@@ -126,7 +127,7 @@ describe "Cookies consent" do
|
||||
click_button "Save preferences"
|
||||
end
|
||||
|
||||
expect(cookie_by_name("cookies_consent")[:value]).to eq "custom"
|
||||
expect(cookie_by_name("cookies_consent_v1")[:value]).to eq "custom"
|
||||
expect(cookie_by_name("third_party")[:value]).to eq "true"
|
||||
expect(page).not_to have_content "Cookies policy"
|
||||
expect(page).not_to have_content "Cookies management"
|
||||
|
||||
Reference in New Issue
Block a user