@@ -, +, @@
---
Koha/Template/Plugin/JSConsents.pm | 4 ++-
.../bug_27378-add_cookie_consents.pl | 14 ++++++----
.../prog/en/includes/intranet-bottom.inc | 2 +-
.../bootstrap/en/includes/masthead.inc | 2 +-
.../Koha/Template/Plugin/JSConsents.t | 28 ++++++++++++++++---
5 files changed, 38 insertions(+), 12 deletions(-)
--- a/Koha/Template/Plugin/JSConsents.pm
+++ a/Koha/Template/Plugin/JSConsents.pm
@@ -21,6 +21,7 @@ use Template::Plugin;
use base qw( Template::Plugin );
use MIME::Base64 qw{ decode_base64 };
use JSON qw{ decode_json };
+use Encode qw{ encode_utf8 };
use C4::Context;
@@ -30,7 +31,8 @@ sub all {
my $consents = C4::Context->preference('CookieConsentedJS');
if ( length $consents > 0 ) {
my $decoded_consents = decode_base64($consents);
- my $consents_array = decode_json $decoded_consents;
+ my $convert_to_utf8 = encode_utf8($decoded_consents);
+ my $consents_array = decode_json $convert_to_utf8;
my @filtered_consents = grep { $_->{$filter} } @{$consents_array};
return \@filtered_consents;
} else {
--- a/installer/data/mysql/atomicupdate/bug_27378-add_cookie_consents.pl
+++ a/installer/data/mysql/atomicupdate/bug_27378-add_cookie_consents.pl
@@ -1,16 +1,20 @@
use Modern::Perl;
return {
- bug_number => "27378",
+ bug_number => "27378",
description => "Adds the sysprefs for cookie consents",
- up => sub {
+ up => sub {
my ($args) = @_;
- my ($dbh, $out) = @$args{qw(dbh out)};
+ my ( $dbh, $out ) = @$args{qw(dbh out)};
- $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('CookieConsentedJS', '', 'Add Javascript code that will run if cookie consent is provided (e.g. tracking code).', '', 'Free'); | );
+ $dbh->do(
+ q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('CookieConsentedJS', '', 'Add Javascript code that will run if cookie consent is provided (e.g. tracking code).', '', 'Free'); |
+ );
say $out "Added new system preference 'CookieConsentedJS'";
- $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('CookieConsent', '0', 'Require cookie consent to be displayed', '', 'YesNo'); | );
+ $dbh->do(
+ q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('CookieConsent', '0', 'Require cookie consent to be displayed', '', 'YesNo'); |
+ );
say $out "Added new system preference 'CookieConsent'";
},
};
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc
+++ a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc
@@ -137,7 +137,7 @@
[% END %]
-
+ Cancel
--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc
+++ a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc
@@ -503,7 +503,7 @@
[% END %]
-
+ Cancel
--- a/t/db_dependent/Koha/Template/Plugin/JSConsents.t
+++ a/t/db_dependent/Koha/Template/Plugin/JSConsents.t
@@ -9,7 +9,7 @@ use Test::More tests => 3;
use t::lib::Mocks;
BEGIN {
- use_ok('Koha::Template::Plugin::JSConsents', "Can use Koha::Template::Plugin::JSConsents");
+ use_ok( 'Koha::Template::Plugin::JSConsents', "Can use Koha::Template::Plugin::JSConsents" );
}
ok( my $consents = Koha::Template::Plugin::JSConsents->new(), 'Able to instantiate template plugin' );
@@ -17,9 +17,29 @@ ok( my $consents = Koha::Template::Plugin::JSConsents->new(), 'Able to instantia
subtest "all" => sub {
plan tests => 1;
- t::lib::Mocks::mock_preference( 'CookieConsentedJS', 'eyAidGVzdCI6ICJvbmUiIH0=' );
-
- is_deeply( $consents->all(), { test => 'one' }, 'Returns a Base64 decoded JSON object converted into a data structure');
+ t::lib::Mocks::mock_preference(
+ 'CookieConsentedJS',
+ 'W3siaWQiOiJfbGFrZGhjOW11IiwibmFtZSI6InRlc3QiLCJkZXNjcmlwdGlvbiI6InRlc3QiLCJtYXRjaFBhdHRlcm4iOiJ0ZXN0MSIsImNvb2tpZURvbWFpbiI6ImxvY2FsaG9zdCIsImNvb2tpZVBhdGgiOiIvIiwib3BhY0NvbnNlbnQiOnRydWUsInN0YWZmQ29uc2VudCI6dHJ1ZSwiY29kZSI6IktHWjFibU4wYVc5dUtDa2dleUFLSUNBZ0lHTnZibk52YkdVdWJHOW5LQ2RJWld4c2J5Qm1jbTl0SUhSbGMzUXhKeWs3SUFvZ0lDQWdaRzlqZFcxbGJuUXVZMjl2YTJsbElEMGdJblJsYzNReFBYUmxjM1JwYm1jN0lHUnZiV0ZwYmoxc2IyTmhiR2h2YzNRN0lIQmhkR2c5THpzZ1UyRnRaVk5wZEdVOVRtOXVaVHNnVTJWamRYSmxJanNnQ24wcEtDazcifV0='
+ );
+
+ is_deeply(
+ $consents->all('opacConsent'),
+ [
+ {
+ 'name' => 'test',
+ 'cookiePath' => '/',
+ 'code' =>
+ 'KGZ1bmN0aW9uKCkgeyAKICAgIGNvbnNvbGUubG9nKCdIZWxsbyBmcm9tIHRlc3QxJyk7IAogICAgZG9jdW1lbnQuY29va2llID0gInRlc3QxPXRlc3Rpbmc7IGRvbWFpbj1sb2NhbGhvc3Q7IHBhdGg9LzsgU2FtZVNpdGU9Tm9uZTsgU2VjdXJlIjsgCn0pKCk7',
+ 'staffConsent' => 1,
+ 'matchPattern' => 'test1',
+ 'description' => 'test',
+ 'cookieDomain' => 'localhost',
+ 'opacConsent' => 1,
+ 'id' => '_lakdhc9mu'
+ }
+ ],
+ 'Returns a Base64 decoded JSON object converted into a data structure'
+ );
};
1;
--