Bugzilla – Attachment 124964 Details for
Bug 27378
Enable compliance with EU Cookie Legislation via cookie consent
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27378: Add cookie domain and path
Bug-27378-Add-cookie-domain-and-path.patch (text/plain), 10.15 KB, created by
Andrew Isherwood
on 2021-09-17 11:07:40 UTC
(
hide
)
Description:
Bug 27378: Add cookie domain and path
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2021-09-17 11:07:40 UTC
Size:
10.15 KB
patch
obsolete
>From f537685afed0ec725453601a2378b6261073cd3c Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Fri, 5 Feb 2021 16:19:00 +0000 >Subject: [PATCH] Bug 27378: Add cookie domain and path > >A subtlety I missed was that some tracking services, such as Google >Analytics, specify a cookie domain and path that differ from the >default. E.g. on a site with a domain of demostaff.koha-ptfs.co.uk, the >GA cookie will have a domain of '.koha-ptfs.co.uk' and a path of '/', >even though the cookie may have been set at a different path. > >Both of these things makes sense, but of course unless we also specify >both of those things when we try to delete a previously set cookie, we >cannot. > >Therefore, I have added two more bits of metadata to each "consent", >Cookie Domain and Cookie Path. It is necessary for an admin creating a >"consent" entry to know and specify these values. They can be >established by looking a cookie set by the service being configured. > >This adds more complexity to setting up a consent, but we cannot remove >previously set cookies without it. > >Signed-ff-by: Barry Cannon <bc@interleaf.ie> >--- > .../prog/en/includes/intranet-bottom.inc | 2 +- > .../intranet-tmpl/prog/js/cookieconsent.js | 4 +++- > .../intranet-tmpl/prog/js/pages/preferences.js | 17 +++++++++++++++++ > .../bootstrap/en/includes/opac-bottom.inc | 2 +- > .../opac-tmpl/bootstrap/js/cookieconsent.js | 4 +++- > 5 files changed, 25 insertions(+), 4 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc >index 9bcca6d5b4..3cbf7f4c1f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc >@@ -136,7 +136,7 @@ > [% IF Koha.Preference( 'CookieConsent' ) && Koha.Preference( 'ConsentJS' ).length > 0 %] > [% consents = JSConsents.all() %] > [% FOREACH consent IN consents %] >- <div class="consentCode" style="display:none" aria-hidden="true" data-consent-id="[% consent.id | html %]" data-consent-code="[% consent.code | html %]" data-consent-match-pattern="[% consent.matchPattern | html %]" data-requires-consent="[% consent.staffConsent ? 'true' : 'false' | html %]"></div> >+ <div class="consentCode" style="display:none" aria-hidden="true" data-consent-id="[% consent.id | html %]" data-consent-code="[% consent.code | html %]" data-consent-match-pattern="[% consent.matchPattern | html %]" data-consent-cookie-domain="[% consent.cookieDomain | html %]" data-consent-cookie-path="[% consent.cookiePath | html %]" data-requires-consent="[% consent.staffConsent ? 'true' : 'false' | html %]"></div> > [% END %] > [% END %] > [% IF Koha.Preference( 'CookieConsent' ) %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js b/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js >index ff00a738d7..b74dba1066 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js >@@ -106,13 +106,15 @@ > // This code doesn't have consent to run, we may need to remove > // any cookies it has previously set > const matchPattern = $(this).data('consent-match-pattern'); >+ const cookieDomain = $(this).data('consent-cookie-domain'); >+ const cookiePath = $(this).data('consent-cookie-path'); > if (matchPattern.length > 0) { > const regex = new RegExp(matchPattern); > const allCookies = document.cookie.split('; '); > allCookies.forEach(function (cookie) { > const name = cookie.split('=')[0]; > if (regex.test(name)) { >- document.cookie = name + '=; expires=Thu, 01 Jan 1970 00: 00: 01 GMT'; >+ document.cookie = name + '=; expires=Thu, 01 Jan 1970 00: 00: 01 GMT; domain=' + cookieDomain + '; path=' + cookiePath; > } > }); > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >index 012ec96d01..91d1a34ffc 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >@@ -356,6 +356,14 @@ $( document ).ready( function () { > ' <label for="matchPattern_' + id + '">' + __('String used to identify cookie name') + ':</label>' + > ' <input id="matchPattern_' + id + '" class="metaMatchPattern" type="text" value="' + item.matchPattern + '"><span class="required">' + __('Required') + '</span>' + > ' </div >' + >+ ' <div class="consentItem">' + >+ ' <label for="cookieDomain' + id + '">' + __('Cookie domain') + ':</label>' + >+ ' <input id="cookieDomain' + id + '" class="metaCookieDomain" type="text" value="' + item.cookieDomain + '"><span class="required">' + __('Required') + '</span>' + >+ ' </div >' + >+ ' <div class="consentItem">' + >+ ' <label for="cookiePath' + id + '">' + __('Cookie path') + ':</label>' + >+ ' <input id="cookiePath' + id + '" class="metaCookiePath" type="text" value="' + item.cookiePath + '"><span class="required">' + __('Required') + '</span>' + >+ ' </div >' + > ' </div >' + > ' <div class="consentRow codeRow">' + > ' <textarea style="display:none;" id="pref_' + id + '" class="preference preference-code codemirror" rows="10" cols="40">' + code + '</textarea>' + >@@ -386,6 +394,8 @@ $( document ).ready( function () { > name: '', > description: '', > matchPattern: '', >+ cookieDomain: '', >+ cookiePath: '', > code: '', > consentInOpac: false, > consentInStaff: false >@@ -464,6 +474,8 @@ $( document ).ready( function () { > const name = $(this).find('.metaName').val(); > const desc = $(this).find('.metaDescription').val(); > const matchPattern = $(this).find('.metaMatchPattern').val(); >+ const cookieDomain = $(this).find('.metaCookieDomain').val(); >+ const cookiePath = $(this).find('.metaCookiePath').val(); > const opacConsent = $(this).find('.opacConsent').is(':checked') > const staffConsent = $(this).find('.staffConsent').is(':checked'); > const code = $(this).find('.preference-code').val(); >@@ -473,6 +485,8 @@ $( document ).ready( function () { > name.length === 0 && > desc.length === 0 && > matchPattern.length === 0 && >+ cookieDomain.length === 0 && >+ cookiePath.length === 0 && > code.length === 0 > ) { > return; >@@ -482,6 +496,7 @@ $( document ).ready( function () { > (name.length === 0) || > (desc.length === 0) || > (matchPattern.length === 0) || >+ (cookiePath.length === 0) || > (code.length === 0) > ) { > invalid.push(this); >@@ -491,6 +506,8 @@ $( document ).ready( function () { > name: name, > description: desc, > matchPattern: matchPattern, >+ cookieDomain: cookieDomain, >+ cookiePath: cookiePath, > opacConsent: opacConsent, > staffConsent: staffConsent, > code: btoa(code) >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >index 6c6c99fce9..da4e09ce62 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >@@ -124,7 +124,7 @@ > [% IF Koha.Preference( 'CookieConsent' ) && Koha.Preference( 'ConsentJS' ).length > 0 %] > [% consents = JSConsents.all() %] > [% FOREACH consent IN consents %] >- <div class="consentCode" style="display:none" aria-hidden="true" data-consent-id="[% consent.id | html %]" data-consent-code="[% consent.code | html %]" data-consent-match-pattern="[% consent.matchPattern | html %]" data-requires-consent="[% consent.opacConsent ? 'true' : 'false' | html %]"></div> >+ <div class="consentCode" style="display:none" aria-hidden="true" data-consent-id="[% consent.id | html %]" data-consent-code="[% consent.code | html %]" data-consent-match-pattern="[% consent.matchPattern | html %]" data-consent-cookie-domain="[% consent.cookieDomain | html %]" data-consent-cookie-path="[% consent.cookiePath | html %]" data-requires-consent="[% consent.opacConsent ? 'true' : 'false' | html %]"></div> > [% END %] > [% END %] > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/cookieconsent.js b/koha-tmpl/opac-tmpl/bootstrap/js/cookieconsent.js >index b0e67ed6a7..ec4372216c 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/cookieconsent.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/cookieconsent.js >@@ -120,13 +120,15 @@ > // This code doesn't have consent to run, we may need to remove > // any cookies it has previously set > const matchPattern = $(this).data('consent-match-pattern'); >+ const cookieDomain = $(this).data('consent-cookie-domain'); >+ const cookiePath = $(this).data('consent-cookie-path'); > if (matchPattern.length > 0) { > const regex = new RegExp(matchPattern); > const allCookies = document.cookie.split('; '); > allCookies.forEach(function (cookie) { > const name = cookie.split('=')[0]; > if (regex.test(name)) { >- document.cookie = name + '=; expires=Thu, 01 Jan 1970 00: 00: 01 GMT'; >+ document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; domain=' + cookieDomain +'; path=' + cookiePath; > } > }); > } >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27378
:
115544
|
115545
|
115546
|
115547
|
115548
|
115756
|
116397
|
116398
|
116399
|
116400
|
116401
|
116402
|
116403
|
116416
|
116417
|
116418
|
116419
|
116420
|
116421
|
116422
|
116423
|
116978
|
116979
|
116980
|
116981
|
116982
|
116983
|
116984
|
116985
|
116986
|
121728
|
121729
|
121730
|
121731
|
121732
|
121733
|
121734
|
121735
|
121995
|
121996
|
121997
|
121998
|
121999
|
122000
|
122001
|
122002
|
122635
|
122636
|
122637
|
122638
|
122639
|
122640
|
122641
|
122642
|
124957
|
124958
|
124959
|
124960
|
124961
|
124962
|
124963
|
124964
|
124965
|
130072
|
130073
|
130074
|
130075
|
130076
|
130077
|
130078
|
130079
|
130080
|
135309
|
135310
|
135311
|
135312
|
135313
|
135314
|
135315
|
135316
|
135317
|
135318
|
151735
|
151736
|
151737
|
151738
|
151739
|
151740
|
151741
|
151742
|
151743
|
151744
|
151745
|
151746
|
151747
|
151748
|
151749
|
151750
|
151751
|
151752
|
151753
|
151826
|
151827
|
151828
|
151829
|
151830
|
151831
|
151832
|
151833
|
151834
|
151835
|
151836
|
151837
|
151838
|
151839
|
151840
|
151841
|
151842
|
151843
|
151844
|
153326
|
153327
|
153328
|
153329
|
153330
|
153331
|
153332
|
153333
|
153334
|
153335
|
153336
|
154015
|
154016
|
154017
|
154018
|
154019
|
154020
|
154021
|
154022
|
154023
|
154024
|
154025
|
154093
|
154264
|
154265
|
154266
|
154267
|
154268
|
154269
|
154270
|
154271
|
154272
|
154273
|
154274
|
154275
|
154276