From 409f084bd468813b593e94677ea80dd9fe94155c Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 2 Sep 2018 14:59:58 +0100 Subject: [PATCH 1/2] Added matomo opt out iframe to cookies policy page --- .../pages/cookies_policy_modal.css.scss | 5 ++ app/helpers/cookies_policy_helper.rb | 13 ++++ .../cookies_policy.html.haml | 6 ++ config/locales/en.yml | 1 + spec/features/consumer/cookies_spec.rb | 71 ++++++++++++++----- spec/helpers/cookies_policy_helper_spec.rb | 42 +++++++++++ 6 files changed, 119 insertions(+), 19 deletions(-) create mode 100644 spec/helpers/cookies_policy_helper_spec.rb diff --git a/app/assets/stylesheets/darkswarm/pages/cookies_policy_modal.css.scss b/app/assets/stylesheets/darkswarm/pages/cookies_policy_modal.css.scss index 942a4396e0..8cf87b1ebb 100644 --- a/app/assets/stylesheets/darkswarm/pages/cookies_policy_modal.css.scss +++ b/app/assets/stylesheets/darkswarm/pages/cookies_policy_modal.css.scss @@ -16,6 +16,11 @@ } } + iframe { + border: 0; + width: 100%; + } + &.fade { -ms-transform: translate(0, 0) !important; -webkit-transform: translate(0, 0) !important; diff --git a/app/helpers/cookies_policy_helper.rb b/app/helpers/cookies_policy_helper.rb index 2afd28d9db..98db25d698 100644 --- a/app/helpers/cookies_policy_helper.rb +++ b/app/helpers/cookies_policy_helper.rb @@ -5,4 +5,17 @@ module CookiesPolicyHelper cookie_desc: cookie_desc, cookie_domain: cookie_domain } end + + def matomo_iframe_src + Spree::Config.matomo_url\ + "/index.php?module=CoreAdminHome&action=optOut"\ + "&language=#{locale_language}"\ + "&backgroundColor=&fontColor=222222&fontSize=16px&fontFamily=%22Roboto%22%2C%20Arial%2C%20sans-serif" + end + + # removes country from locale if needed + # for example, both locales en and en_GB return language en + def locale_language + I18n.locale[0..1] + end end diff --git a/app/views/angular_templates/cookies_policy.html.haml b/app/views/angular_templates/cookies_policy.html.haml index e43d1ded9e..982ba89d53 100644 --- a/app/views/angular_templates/cookies_policy.html.haml +++ b/app/views/angular_templates/cookies_policy.html.haml @@ -69,6 +69,12 @@ = render_cookie_entry( "_pk_hsr, _pk_cvar, _pk_id and _pk_ses", t( "legal.cookies_policy.cookie_matomo_heatmap_desc" ) ) = render_cookie_entry( "piwik_ignore, _pk_cvar, _pk_id and _pk_ses", t( "legal.cookies_policy.cookie_matomo_ignore_desc" ) ) + - if Spree::Config.cookies_policy_matomo_section && Spree::Config.matomo_url.present? + %p + = t 'legal.cookies_policy.statistics_cookies_matomo_optout' + %p + %iframe{ src: matomo_iframe_src } + %h2 = t 'legal.cookies_policy.disabling_cookies_header' %p diff --git a/config/locales/en.yml b/config/locales/en.yml index 7d3ce3b831..bae387e957 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1299,6 +1299,7 @@ en: statistics_cookies_desc: "The following are not strictly necessary, but help to provide you with the best user experience by allowing us to analyse user behaviour, identify which features you use most, or don’t use, understand user experience issues, etc." statistics_cookies_analytics_desc_html: "To collect and analyse platform usage data, we use Google Analytics, as it was the default service connected with Spree (the e-commerce open source software that we built on) but our vision is to switch to Matomo (ex Piwik, open source analytics tool that is GDPR compliant and protects your privacy) as soon as we can." statistics_cookies_matomo_desc_html: "To collect and analyse platform usage data, we use Matomo (ex Piwik), an open source analytics tool that is GDPR compliant and protects your privacy." + statistics_cookies_matomo_optout: "Do you want to opt-out of Matomo analytics? We don’t collect any personal data, and Matomo helps us to improve our service, but we respect your choice :-)" cookie_analytics_utma_desc: "Used to distinguish users and sessions. The cookie is created when the javascript library executes and no existing __utma cookies exists. The cookie is updated every time data is sent to Google Analytics." cookie_analytics_utmt_desc: "Used to throttle request rate." cookie_analytics_utmb_desc: "Used to determine new sessions/visits. The cookie is created when the javascript library executes and no existing __utmb cookies exists. The cookie is updated every time data is sent to Google Analytics." diff --git a/spec/features/consumer/cookies_spec.rb b/spec/features/consumer/cookies_spec.rb index c2dbe5a078..d86b89f4ad 100644 --- a/spec/features/consumer/cookies_spec.rb +++ b/spec/features/consumer/cookies_spec.rb @@ -10,7 +10,7 @@ feature "Cookies", js: true do Spree::Config[:cookies_consent_banner_toggle] = original_banner_toggle end - describe "in the homepage" do + context "in the homepage" do before do Spree::Config[:cookies_consent_banner_toggle] = true visit_root_path_and_wait @@ -46,7 +46,7 @@ feature "Cookies", js: true do end end - describe "in product listing page" do + context "in product listing page" do before do Spree::Config[:cookies_consent_banner_toggle] = true end @@ -57,7 +57,7 @@ feature "Cookies", js: true do end end - describe "disabled in the settings" do + context "disabled in the settings" do scenario "it is not showing" do Spree::Config[:cookies_consent_banner_toggle] = false visit root_path @@ -70,38 +70,59 @@ feature "Cookies", js: true do # keeps config unchanged around do |example| - original_config_value = Spree::Config[:cookies_policy_matomo_section] + original_matomo_config = Spree::Config[:cookies_policy_matomo_section] + original_matomo_url_config = Spree::Config[:matomo_url] example.run - Spree::Config[:cookies_policy_matomo_section] = original_config_value + Spree::Config[:cookies_policy_matomo_section] = original_matomo_config + Spree::Config[:matomo_url] = original_matomo_url_config end - scenario "showing session_id cookies description with correct instance domain" do + scenario "shows session_id cookies description with correct instance domain" do visit '/#/policies/cookies' expect(page).to have_content('_session_id') .and have_content('127.0.0.1') end - describe "with Matomo section configured" do - scenario "shows Matomo cookies details" do + context "without Matomo section configured" do + scenario "does not show Matomo cookies details and does not show Matomo optout text" do + Spree::Config[:cookies_policy_matomo_section] = false + visit_cookies_policy_page + expect(page).to have_no_content matomo_description_text + expect(page).to have_no_content matomo_opt_out_iframe + end + end + + context "with Matomo section configured" do + before do Spree::Config[:cookies_policy_matomo_section] = true - visit '/#/policies/cookies' + end + + scenario "shows Matomo cookies details" do + visit_cookies_policy_page expect(page).to have_content matomo_description_text end - end - describe "without Matomo section configured" do - scenario "does not show Matomo cookies details" do - Spree::Config[:cookies_policy_matomo_section] = false - visit '/#/policies/cookies' - expect(page).to have_no_content matomo_description_text + context "with Matomo integration enabled" do + scenario "shows Matomo optout iframe" do + Spree::Config[:matomo_url] = "https://0000.innocraft.cloud/" + visit_cookies_policy_page + expect(page).to have_content matomo_opt_out_iframe + expect(page).to have_selector("iframe") + end + end + + context "with Matomo integration disabled" do + scenario "does not show Matomo iframe" do + Spree::Config[:cookies_policy_matomo_section] = true + Spree::Config[:matomo_url] = "" + visit_cookies_policy_page + expect(page).to have_no_content matomo_opt_out_iframe + expect(page).to have_no_selector("iframe") + end end end end - def matomo_description_text - I18n.t('legal.cookies_policy.cookie_matomo_basics_desc') - end - def expect_visible_cookies_policy_page expect(page).to have_content I18n.t('legal.cookies_policy.header') end @@ -142,4 +163,16 @@ feature "Cookies", js: true do find("a.close-reveal-modal").click sleep 2 end + + def visit_cookies_policy_page + visit '/#/policies/cookies' + end + + def matomo_description_text + I18n.t('legal.cookies_policy.cookie_matomo_basics_desc') + end + + def matomo_opt_out_iframe + I18n.t('legal.cookies_policy.statistics_cookies_matomo_optout') + end end diff --git a/spec/helpers/cookies_policy_helper_spec.rb b/spec/helpers/cookies_policy_helper_spec.rb new file mode 100644 index 0000000000..2e4fbfa25d --- /dev/null +++ b/spec/helpers/cookies_policy_helper_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +describe CookiesPolicyHelper, type: :helper do + + # keeps global state unchanged + around do |example| + original_locale = I18n.locale + original_matomo_url = Spree::Config.matomo_url + example.run + Spree::Config.matomo_url = original_matomo_url + I18n.locale = original_locale + end + + describe "matomo optout iframe src" do + scenario "includes matomo URL" do + Spree::Config.matomo_url = "http://matomo.org/" + expect(helper.matomo_iframe_src).to include Spree::Config.matomo_url + end + + scenario "is not nil, when matomo url is nil" do + Spree::Config.matomo_url = nil + expect(helper.matomo_iframe_src).to_not eq nil + end + end + + describe "language from locale" do + scenario "when locale is the language" do + I18n.locale = "en" + expect(helper.locale_language).to eq "en" + end + + scenario "is empty when locale is empty" do + I18n.locale = "" + expect(helper.locale_language).to be_empty + end + + scenario "is only the language, when locale includes country" do + I18n.locale = "en_GB" + expect(helper.locale_language).to eq "en" + end + end +end From 478dd6807293fc361ab5833cc96c2a64485e6ed8 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 11 Sep 2018 17:25:11 +0100 Subject: [PATCH 2/2] In cookies policy helper, added string interpolation to variable to avoid variable (Spree::Config entry) to break the concatenation. Added unit test to validate the error case --- app/helpers/cookies_policy_helper.rb | 2 +- spec/helpers/cookies_policy_helper_spec.rb | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/helpers/cookies_policy_helper.rb b/app/helpers/cookies_policy_helper.rb index 98db25d698..5bcec92383 100644 --- a/app/helpers/cookies_policy_helper.rb +++ b/app/helpers/cookies_policy_helper.rb @@ -7,7 +7,7 @@ module CookiesPolicyHelper end def matomo_iframe_src - Spree::Config.matomo_url\ + "#{Spree::Config.matomo_url}"\ "/index.php?module=CoreAdminHome&action=optOut"\ "&language=#{locale_language}"\ "&backgroundColor=&fontColor=222222&fontSize=16px&fontFamily=%22Roboto%22%2C%20Arial%2C%20sans-serif" diff --git a/spec/helpers/cookies_policy_helper_spec.rb b/spec/helpers/cookies_policy_helper_spec.rb index 2e4fbfa25d..b09f578a32 100644 --- a/spec/helpers/cookies_policy_helper_spec.rb +++ b/spec/helpers/cookies_policy_helper_spec.rb @@ -12,9 +12,18 @@ describe CookiesPolicyHelper, type: :helper do end describe "matomo optout iframe src" do - scenario "includes matomo URL" do - Spree::Config.matomo_url = "http://matomo.org/" - expect(helper.matomo_iframe_src).to include Spree::Config.matomo_url + describe "when matomo url is set" do + before do + Spree::Config.matomo_url = "http://matomo.org/" + end + + scenario "includes the matomo URL" do + expect(helper.matomo_iframe_src).to include Spree::Config.matomo_url + end + + scenario "is not equal to the matomo URL" do + expect(helper.matomo_iframe_src).to_not eq Spree::Config.matomo_url + end end scenario "is not nil, when matomo url is nil" do