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

(-)a/C4/Auth.pm (-2 / +14 lines)
Lines 437-444 sub get_template_and_user { Link Here
437
            }
437
            }
438
            C4::Search::History::set_to_session( { cgi => $in->{'query'}, search_history => [] } );
438
            C4::Search::History::set_to_session( { cgi => $in->{'query'}, search_history => [] } );
439
439
440
        } elsif ( $in->{type} eq 'intranet' and C4::Context->preference('EnableSearchHistory') ) {
440
        } elsif ( $in->{type} eq 'intranet' ) {
441
            $template->param( EnableSearchHistory => 1 );
441
            if ( C4::Context->preference('EnableSearchHistory') ) {
442
                $template->param( EnableSearchHistory => 1 );
443
            }
444
            if ( C4::Context->preference('BorrowersViewLog') ) {
445
                if ( defined $in->{'query'}->param('borrowernumber') ) {
446
                    my $log_info = $in->{'template_name'};
447
                    $log_info =~ s/\.tt$//;
448
                    logaction(
449
                        'MEMBERS', 'VIEW', $in->{'query'}->param('borrowernumber'),
450
                        $log_info, $in->{'type'}
451
                    );
452
                }
453
            }
442
        }
454
        }
443
    } else {    # if this is an anonymous session, setup to display public lists...
455
    } else {    # if this is an anonymous session, setup to display public lists...
444
456
(-)a/Koha/REST/V1/Patrons.pm (+10 lines)
Lines 56-61 sub list { Link Here
56
        my $patrons_rs = Koha::Patrons->search($query);
56
        my $patrons_rs = Koha::Patrons->search($query);
57
        my $patrons    = $c->objects->search($patrons_rs);
57
        my $patrons    = $c->objects->search($patrons_rs);
58
58
59
        if ( C4::Context->preference('BorrowersViewLog') && $patrons ) {
60
            foreach my $patron (@$patrons) {
61
                C4::Log::logaction( 'MEMBERS', 'VIEW', $patron->{patron_id}, 'list' );
62
            }
63
        }
64
59
        return $c->render(
65
        return $c->render(
60
            status  => 200,
66
            status  => 200,
61
            openapi => $patrons
67
            openapi => $patrons
Lines 81-86 sub get { Link Here
81
        return $c->render_resource_not_found("Patron")
87
        return $c->render_resource_not_found("Patron")
82
            unless $patron;
88
            unless $patron;
83
89
90
        if ( C4::Context->preference('BorrowersViewLog') ) {
91
            C4::Log::logaction( 'MEMBERS', 'VIEW', $patron->{patron_id}, 'get' );
92
        }
93
84
        return $c->render(
94
        return $c->render(
85
            status  => 200,
95
            status  => 200,
86
            openapi => $patron
96
            openapi => $patron
(-)a/t/db_dependent/api/v1/patrons.t (-3 / +64 lines)
Lines 83-89 subtest 'list() tests' => sub { Link Here
83
83
84
    subtest 'librarian access tests' => sub {
84
    subtest 'librarian access tests' => sub {
85
85
86
        plan tests => 15;
86
        plan tests => 16;
87
87
88
        $schema->storage->txn_begin;
88
        $schema->storage->txn_begin;
89
89
Lines 210-215 subtest 'list() tests' => sub { Link Here
210
                ->json_is( '/0/patron_id' => $patron->id, 'Filtering by date-time works' );
210
                ->json_is( '/0/patron_id' => $patron->id, 'Filtering by date-time works' );
211
        };
211
        };
212
212
213
        subtest 'BorrowersViewLog' => sub {
214
            plan tests => 6;
215
216
            t::lib::Mocks::mock_preference( 'BorrowersViewLog', 1 );
217
218
            $t->get_ok("//$userid:$password@/api/v1/patrons")->status_is(200);
219
220
            my $count = Koha::ActionLogs->search({
221
                module => 'MEMBERS',
222
                action => 'VIEW',
223
                user => $librarian->borrowernumber,
224
                interface => 'api'
225
            })->count;
226
227
            ok($count>0, "BorrowersViewLog generated some view log entries");
228
229
            t::lib::Mocks::mock_preference( 'BorrowersViewLog', 0 );
230
231
            $t->get_ok("//$userid:$password@/api/v1/patrons")->status_is(200);
232
233
            my $off_count = Koha::ActionLogs->search({
234
                module => 'MEMBERS',
235
                action => 'VIEW',
236
                user => $librarian->borrowernumber,
237
                interface => 'api'
238
            })->count;
239
240
            is($off_count, $count, "BorrowersViewLog does not generate log entries when disabled");
241
        };
242
213
        $schema->storage->txn_rollback;
243
        $schema->storage->txn_rollback;
214
    };
244
    };
215
245
Lines 277-283 subtest 'get() tests' => sub { Link Here
277
307
278
    subtest 'librarian access tests' => sub {
308
    subtest 'librarian access tests' => sub {
279
309
280
        plan tests => 8;
310
        plan tests => 9;
281
311
282
        $schema->storage->txn_begin;
312
        $schema->storage->txn_begin;
283
313
Lines 325-330 subtest 'get() tests' => sub { Link Here
325
            ->json_is( '/patron_id' => $patron->id )->json_is( '/category_id' => $patron->categorycode )
355
            ->json_is( '/patron_id' => $patron->id )->json_is( '/category_id' => $patron->categorycode )
326
            ->json_is( '/surname'   => $patron->surname )->json_is( '/patron_card_lost' => Mojo::JSON->false );
356
            ->json_is( '/surname'   => $patron->surname )->json_is( '/patron_card_lost' => Mojo::JSON->false );
327
357
358
        subtest 'BorrowersViewLog' => sub {
359
            plan tests => 6;
360
361
            t::lib::Mocks::mock_preference( 'BorrowersViewLog', 1 );
362
363
            $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id)->status_is(200);
364
365
            my $count = Koha::ActionLogs->search({
366
                module => 'MEMBERS',
367
                action => 'VIEW',
368
                user => $librarian->borrowernumber,
369
                object => $patron->id,
370
                interface => 'api'
371
            })->count;
372
373
            ok($count>0, "BorrowersViewLog generated some view log entries for this patron");
374
375
            t::lib::Mocks::mock_preference( 'BorrowersViewLog', 0 );
376
377
            $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id)->status_is(200);
378
379
            my $off_count = Koha::ActionLogs->search({
380
                module => 'MEMBERS',
381
                action => 'VIEW',
382
                user => $librarian->borrowernumber,
383
                object => $patron->id,
384
                interface => 'api'
385
            })->count;
386
387
            is($off_count, $count, "BorrowersViewLog does not generate log entries when disabled");
388
        };
389
328
        $schema->storage->txn_rollback;
390
        $schema->storage->txn_rollback;
329
    };
391
    };
330
392
331
- 

Return to bug 25673