Bugzilla – Attachment 135315 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: Delete cookies when consent removed
Bug-27378-Delete-cookies-when-consent-removed.patch (text/plain), 13.11 KB, created by
Martin Renvoize (ashimema)
on 2022-05-24 15:09:08 UTC
(
hide
)
Description:
Bug 27378: Delete cookies when consent removed
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-05-24 15:09:08 UTC
Size:
13.11 KB
patch
obsolete
>From 8df6c60093db691d1bfee410770045b7c6389611 Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Fri, 5 Feb 2021 14:39:32 +0000 >Subject: [PATCH] Bug 27378: Delete cookies when consent removed > >We have provided the ability for a user to remove previously granted >consent, but we were not removing the cookie associated with that >consent. This was a complete oversight on my part. > >I've introduced an additional bit of metadata for each "consent" defined >in the ConsentJS syspref, this allows the admin defining a "consent" to >specify a string (which is treated as a regex) that allows us to >identify a cookie name associated with that consent. So, for example, if >Google Analytics was being added, an identifying string might be '_ga'. >This allows us to subsequently remove a cookie that a previously >granted consent has set. > >This commit also adds some missing 'html' filters in >koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc and >koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc > >Signed-ff-by: Barry Cannon <bc@interleaf.ie> >--- > .../prog/en/includes/intranet-bottom.inc | 2 +- > .../intranet-tmpl/prog/js/cookieconsent.js | 16 +++++++ > .../prog/js/pages/preferences.js | 46 +++++++++++++++++-- > .../bootstrap/en/includes/opac-bottom.inc | 2 +- > .../opac-tmpl/bootstrap/js/cookieconsent.js | 15 ++++++ > 5 files changed, 76 insertions(+), 5 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 5a94f7d53a..9bcca6d5b4 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 %]" data-consent-code="[% consent.code %]" data-requires-consent="[% consent.staffConsent ? 'true' : 'false' %]"></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-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 c718c73e39..ff00a738d7 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js >@@ -102,6 +102,21 @@ > const code = atob($(this).data('consent-code')); > const func = Function(code); > func(); >+ } else { >+ // 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'); >+ 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'; >+ } >+ }); >+ >+ } > } > }); > } >@@ -125,6 +140,7 @@ > e.preventDefault(); > localStorage.setItem('cookieConsent', []); > hideContainer(); >+ runConsentedCode(); > }); > > // "Accept selected" handler >diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >index 89e32d1769..1f20fd57e4 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >@@ -340,7 +340,38 @@ $( document ).ready( function () { > const id = 'ConsentJS_' + idx; > const code = item.code && item.code.length > 0 ? atob(item.code) : ''; > const itemId = item.id && item.id.length > 0 ? item.id : ''; >- return '<div id="' + id + '" class="consentJSItem" data-id="' + itemId + '"><div class="consentRow"><div class="consentItem"><label class="required" for="name_' + id + '">' + __('Name') + ':</label><input id="name_' + id + '" class="metaName" type="text" value="' + item.name + '"><span class="required">' + __('Required') + '</span></div><div class="consentItem"><label class="required" for="description_' + id + '">' + __('Description') + ':</label><input id="description_' + id + '" class="metaDescription" type="text" value="' + item.description + '"><span class="required">' + __('Required') + '</span></div><div class="consentItem"><label for="opacConsent_' + id + '">' + __('Requires consent in OPAC') + ':</label>' + checkBox('opacConsent_' + id, 'opacConsent', item.opacConsent) + '</div><div class="consentItem"><label for="staffConsent_' + id + '">' + __('Requires consent in staff interface') + ':</label>' + checkBox('staffConsent_' + id, 'staffConsent', item.staffConsent) + '</div></div><div class="consentRow codeRow"><textarea style="display:none;" id="pref_' + id + '" class="preference preference-code codemirror" rows="10" cols="40">' + code + '</textarea><div><a id="expand_' + id + '" class="expand-textarea" data-target="' + id + '" data-syntax="javascript" href="#">' + __('Click to expand') + '</a><a id="collapse_' + id + '" class="collapse-textarea" data-target="' + id + '" data-syntax="javascript" href="#" style="display:none">' + __('Click to collapse') + '</a></div></div><a class="consentDelete" data-target="' + id + '" href="#">Delete</a></div>'; >+ return '<div id="' + id + '" class="consentJSItem" data-id="' + itemId + '">' + >+ ' <div class="consentRow">' + >+ ' <div class="consentItem">' + >+ ' <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' + >+ ' <input id="name_' + id + '" class="metaName" type="text" value="' + item.name + '"><span class="required">' + __('Required') + '</span>' + >+ ' </div >' + >+ ' <div class="consentItem">' + >+ ' <label class="required" for="description_' + id + '">' + __('Description') + ':</label>' + >+ ' <input id="description_' + id + '" class="metaDescription" type="text" value="' + item.description + '"><span class="required">' + __('Required') + '</span>' + >+ ' </div>' + >+ ' <div class="consentItem">' + >+ ' <label for="opacConsent_' + id + '">' + __('Requires consent in OPAC') + ':</label>' + >+ checkBox('opacConsent_' + id, 'opacConsent', item.opacConsent) + >+ ' </div>' + >+ ' <div class="consentItem">' + >+ ' <label for="staffConsent_' + id + '">' + __('Requires consent in staff interface') + ':</label>' + >+ checkBox('staffConsent_' + id, 'staffConsent', item.staffConsent) + >+ ' </div >' + >+ ' <div class="consentItem">' + >+ ' <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 >' + >+ ' <div class="consentRow codeRow">' + >+ ' <textarea style="display:none;" id="pref_' + id + '" class="preference preference-code codemirror" rows="10" cols="40">' + code + '</textarea>' + >+ ' <div>' + >+ ' <a id="expand_' + id + '" class="expand-textarea" data-target="' + id + '" data-syntax="javascript" href="#">' + __('Click to expand') + '</a>' + >+ ' <a id="collapse_' + id + '" class="collapse-textarea" data-target="' + id + '" data-syntax="javascript" href="#" style="display:none">' + __('Click to collapse') + '</a>' + >+ ' </div >' + >+ ' </div>' + >+ ' <a class="consentDelete" data-target="' + id + '" href="#">Delete</a>' + >+ '</div > '; > } > > // Return the markup for all consentJS items concatenated >@@ -360,6 +391,7 @@ $( document ).ready( function () { > return { > name: '', > description: '', >+ matchPattern: '', > code: '', > consentInOpac: false, > consentInStaff: false >@@ -437,18 +469,25 @@ $( document ).ready( function () { > '_' + Math.random().toString(36).substr(2, 9); > const name = $(this).find('.metaName').val(); > const desc = $(this).find('.metaDescription').val(); >+ const matchPattern = $(this).find('.metaMatchPattern').val(); > const opacConsent = $(this).find('.opacConsent').is(':checked') > const staffConsent = $(this).find('.staffConsent').is(':checked'); > const code = $(this).find('.preference-code').val(); >- // If the name, description and code are empty, then they've >+ // If the name, description, match pattern code are empty, then they've > // added a new entry, but not filled it in, we can skip it >- if (name.length === 0 && desc.length === 0 && code.length === 0) { >+ if ( >+ name.length === 0 && >+ desc.length === 0 && >+ matchPattern.length === 0 && >+ code.length === 0 >+ ) { > return; > } > // They've filled in at least some info > if ( > (name.length === 0) || > (desc.length === 0) || >+ (matchPattern.length === 0) || > (code.length === 0) > ) { > invalid.push(this); >@@ -457,6 +496,7 @@ $( document ).ready( function () { > id: id, > name: name, > description: desc, >+ matchPattern: matchPattern, > 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 cb4a9f5385..679e1ac29a 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 %]" data-consent-code="[% consent.code %]" data-requires-consent="[% consent.opacConsent ? 'true' : 'false' %]"></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-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 8f7a8c0252..b0e67ed6a7 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/cookieconsent.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/cookieconsent.js >@@ -116,6 +116,20 @@ > const code = atob($(this).data('consent-code')); > const func = Function(code); > func(); >+ } else { >+ // 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'); >+ 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'; >+ } >+ }); >+ } > } > }); > } >@@ -140,6 +154,7 @@ > e.preventDefault(); > localStorage.setItem('cookieConsent', []); > hideContainer(); >+ runConsentedCode(); > showYourCookies(); > }); > >-- >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