From a2ab75e04045e96ad71c85dc7c6a4dc78cc1e8e7 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 11 Jul 2023 16:43:59 +0000 Subject: [PATCH] Bug 27378: (QA follow-up) Add filtering for OPAC only and staff only cookies This patch fixes an issue where cookies selected as OPAC only would still show in the staff client and vise versa. The cookies are now filtered and only the correct cookies will be used in the OPAC and staff client --- Koha/Template/Plugin/JSConsents.pm | 13 ++++++++----- .../prog/en/includes/intranet-bottom.inc | 10 +++++----- .../opac-tmpl/bootstrap/en/includes/masthead.inc | 6 +++--- .../opac-tmpl/bootstrap/en/includes/opac-bottom.inc | 4 ++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Koha/Template/Plugin/JSConsents.pm b/Koha/Template/Plugin/JSConsents.pm index 8a559904ad..2148cc12c3 100644 --- a/Koha/Template/Plugin/JSConsents.pm +++ b/Koha/Template/Plugin/JSConsents.pm @@ -25,11 +25,14 @@ use JSON qw{ decode_json }; use C4::Context; sub all { - my ( $self ) = @_; - my $consents = C4::Context->preference( 'CookieConsentedJS' ); - if (length $consents > 0) { - my $decoded = decode_base64($consents); - return decode_json $decoded; + my ( $self, $filter ) = @_; + + my $consents = C4::Context->preference('CookieConsentedJS'); + if ( length $consents > 0 ) { + my $decoded_consents = decode_base64($consents); + my $consents_array = decode_json $decoded_consents; + my @filtered_consents = grep { $_->{$filter} } @{$consents_array}; + return \@filtered_consents; } else { return []; } 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 7627476516..cd3abdfb5a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc @@ -94,7 +94,7 @@ [% END %]
- [% IF ( Koha.Preference( 'CookieConsentedJS' ).length > 0 ) %] + [% IF ( JSConsents.all('staffConsent').size ) %] [% END %] @@ -116,7 +116,7 @@
[% END %]
- [% consents = JSConsents.all() %] + [% consents = JSConsents.all('staffConsent') %] [% FOREACH consent IN consents %]
@@ -133,7 +133,7 @@