View | Details | Raw Unified | Return to bug 27378
Collapse All | Expand All

(-)a/Koha/Template/Plugin/JSConsents.pm (-1 / +3 lines)
Lines 21-26 use Template::Plugin; Link Here
21
use base qw( Template::Plugin );
21
use base qw( Template::Plugin );
22
use MIME::Base64 qw{ decode_base64 };
22
use MIME::Base64 qw{ decode_base64 };
23
use JSON qw{ decode_json };
23
use JSON qw{ decode_json };
24
use Encode qw{ encode_utf8 };
24
25
25
use C4::Context;
26
use C4::Context;
26
27
Lines 30-36 sub all { Link Here
30
    my $consents = C4::Context->preference('CookieConsentedJS');
31
    my $consents = C4::Context->preference('CookieConsentedJS');
31
    if ( length $consents > 0 ) {
32
    if ( length $consents > 0 ) {
32
        my $decoded_consents  = decode_base64($consents);
33
        my $decoded_consents  = decode_base64($consents);
33
        my $consents_array    = decode_json $decoded_consents;
34
        my $convert_to_utf8   = encode_utf8($decoded_consents);
35
        my $consents_array    = decode_json $convert_to_utf8;
34
        my @filtered_consents = grep { $_->{$filter} } @{$consents_array};
36
        my @filtered_consents = grep { $_->{$filter} } @{$consents_array};
35
        return \@filtered_consents;
37
        return \@filtered_consents;
36
    } else {
38
    } else {
(-)a/installer/data/mysql/atomicupdate/bug_27378-add_cookie_consents.pl (-5 / +9 lines)
Lines 1-16 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "27378",
4
    bug_number  => "27378",
5
    description => "Adds the sysprefs for cookie consents",
5
    description => "Adds the sysprefs for cookie consents",
6
    up => sub {
6
    up          => sub {
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        $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'); | );
10
        $dbh->do(
11
            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'); |
12
        );
11
        say $out "Added new system preference 'CookieConsentedJS'";
13
        say $out "Added new system preference 'CookieConsentedJS'";
12
14
13
        $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('CookieConsent', '0', 'Require cookie consent to be displayed', '', 'YesNo'); | );
15
        $dbh->do(
16
            q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('CookieConsent', '0', 'Require cookie consent to be displayed', '', 'YesNo'); |
17
        );
14
        say $out "Added new system preference 'CookieConsent'";
18
        say $out "Added new system preference 'CookieConsent'";
15
    },
19
    },
16
};
20
};
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc (-1 / +1 lines)
Lines 137-143 Link Here
137
                                <button type="button" class="btn btn-primary consentAcceptEssential">Accept only essential cookies</button>
137
                                <button type="button" class="btn btn-primary consentAcceptEssential">Accept only essential cookies</button>
138
                                <button type="button" class="btn btn-success" id="consentAcceptSelected">Accept selected non-essential cookies</button>
138
                                <button type="button" class="btn btn-success" id="consentAcceptSelected">Accept selected non-essential cookies</button>
139
                            [% END %]
139
                            [% END %]
140
                            <button type="button" class="btn btn-secondary consentCloseModal">Cancel</button>
140
                            <a type="button" href="#" class="btn btn-secondary consentCloseModal">Cancel</a>
141
                        </div>
141
                        </div>
142
                    </div>
142
                    </div>
143
                </div> <!-- /.modal-content -->
143
                </div> <!-- /.modal-content -->
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc (-1 / +1 lines)
Lines 503-509 Link Here
503
                                <button type="button" class="btn btn-primary consentAcceptEssential">Accept only essential cookies</button>
503
                                <button type="button" class="btn btn-primary consentAcceptEssential">Accept only essential cookies</button>
504
                                <button type="button" class="btn btn-warning" id="consentAcceptSelected">Accept selected non-essential cookies</button>
504
                                <button type="button" class="btn btn-warning" id="consentAcceptSelected">Accept selected non-essential cookies</button>
505
                            [% END %]
505
                            [% END %]
506
                            <button type="button" class="btn btn-secondary consentCloseModal">Cancel</button>
506
                            <a type="button" href="#" class="btn btn-secondary consentCloseModal">Cancel</a>
507
                        </div>
507
                        </div>
508
                    </div>
508
                    </div>
509
                </div> <!-- /.modal-content -->
509
                </div> <!-- /.modal-content -->
(-)a/t/db_dependent/Koha/Template/Plugin/JSConsents.t (-5 / +24 lines)
Lines 9-15 use Test::More tests => 3; Link Here
9
use t::lib::Mocks;
9
use t::lib::Mocks;
10
10
11
BEGIN {
11
BEGIN {
12
    use_ok('Koha::Template::Plugin::JSConsents', "Can use Koha::Template::Plugin::JSConsents");
12
    use_ok( 'Koha::Template::Plugin::JSConsents', "Can use Koha::Template::Plugin::JSConsents" );
13
}
13
}
14
14
15
ok( my $consents = Koha::Template::Plugin::JSConsents->new(), 'Able to instantiate template plugin' );
15
ok( my $consents = Koha::Template::Plugin::JSConsents->new(), 'Able to instantiate template plugin' );
Lines 17-25 ok( my $consents = Koha::Template::Plugin::JSConsents->new(), 'Able to instantia Link Here
17
subtest "all" => sub {
17
subtest "all" => sub {
18
    plan tests => 1;
18
    plan tests => 1;
19
19
20
    t::lib::Mocks::mock_preference( 'CookieConsentedJS', 'eyAidGVzdCI6ICJvbmUiIH0=' );
20
    t::lib::Mocks::mock_preference(
21
21
        'CookieConsentedJS',
22
    is_deeply( $consents->all(), { test => 'one' }, 'Returns a Base64 decoded JSON object converted into a data structure');
22
        'W3siaWQiOiJfbGFrZGhjOW11IiwibmFtZSI6InRlc3QiLCJkZXNjcmlwdGlvbiI6InRlc3QiLCJtYXRjaFBhdHRlcm4iOiJ0ZXN0MSIsImNvb2tpZURvbWFpbiI6ImxvY2FsaG9zdCIsImNvb2tpZVBhdGgiOiIvIiwib3BhY0NvbnNlbnQiOnRydWUsInN0YWZmQ29uc2VudCI6dHJ1ZSwiY29kZSI6IktHWjFibU4wYVc5dUtDa2dleUFLSUNBZ0lHTnZibk52YkdVdWJHOW5LQ2RJWld4c2J5Qm1jbTl0SUhSbGMzUXhKeWs3SUFvZ0lDQWdaRzlqZFcxbGJuUXVZMjl2YTJsbElEMGdJblJsYzNReFBYUmxjM1JwYm1jN0lHUnZiV0ZwYmoxc2IyTmhiR2h2YzNRN0lIQmhkR2c5THpzZ1UyRnRaVk5wZEdVOVRtOXVaVHNnVTJWamRYSmxJanNnQ24wcEtDazcifV0='
23
    );
24
25
    is_deeply(
26
        $consents->all('opacConsent'),
27
        [
28
            {
29
                'name'       => 'test',
30
                'cookiePath' => '/',
31
                'code' =>
32
                    'KGZ1bmN0aW9uKCkgeyAKICAgIGNvbnNvbGUubG9nKCdIZWxsbyBmcm9tIHRlc3QxJyk7IAogICAgZG9jdW1lbnQuY29va2llID0gInRlc3QxPXRlc3Rpbmc7IGRvbWFpbj1sb2NhbGhvc3Q7IHBhdGg9LzsgU2FtZVNpdGU9Tm9uZTsgU2VjdXJlIjsgCn0pKCk7',
33
                'staffConsent' => 1,
34
                'matchPattern' => 'test1',
35
                'description'  => 'test',
36
                'cookieDomain' => 'localhost',
37
                'opacConsent'  => 1,
38
                'id'           => '_lakdhc9mu'
39
            }
40
        ],
41
        'Returns a Base64 decoded JSON object converted into a data structure'
42
    );
23
};
43
};
24
44
25
1;
45
1;
26
- 

Return to bug 27378