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

(-)a/Koha/Notice/Messages.pm (+24 lines)
Lines 53-58 sub get_failed_notices { Link Here
53
    );
53
    );
54
}
54
}
55
55
56
=head3 search_limited
57
58
    my $messages = Koha::Notice::Messages->search_limited( $params, $attributes );
59
60
Search for generated and queued notices according to logged in patron restrictions
61
62
=cut
63
64
sub search_limited {
65
    my ( $self, $params, $attributes ) = @_;
66
67
    my $userenv = C4::Context->userenv;
68
    my @restricted_branchcodes;
69
    if ( $userenv and $userenv->{number} ) {
70
        my $logged_in_user = Koha::Patrons->find( $userenv->{number} );
71
        @restricted_branchcodes = $logged_in_user->libraries_where_can_see_patrons;
72
    }
73
74
    # TODO This 'borrowernumber' relation name is confusing and needs to be renamed
75
    $params->{'borrowernumber.branchcode'} = { -in => \@restricted_branchcodes } if @restricted_branchcodes;
76
    $attributes->{join}                    = 'borrowernumber';
77
    return $self->search( $params, $attributes );
78
}
79
56
=head3 type
80
=head3 type
57
81
58
=cut
82
=cut
(-)a/t/db_dependent/Koha/Notice/Message.t (-1 / +41 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 2;
22
use Test::More tests => 3;
23
23
24
use C4::Letters qw( GetPreparedLetter EnqueueLetter );
24
use C4::Letters qw( GetPreparedLetter EnqueueLetter );
25
25
Lines 239-242 subtest 'patron() tests' => sub { Link Here
239
    $schema->storage->txn_rollback;
239
    $schema->storage->txn_rollback;
240
};
240
};
241
241
242
subtest 'search_limited' => sub {
243
    plan tests => 2;
244
245
    $schema->storage->txn_begin;
246
247
    my $patron   = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } );
248
    my $patron_2 = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } );
249
250
    my $message = $builder->build_object(
251
        {
252
            class => 'Koha::Notice::Messages',
253
            value => { borrowernumber => $patron->borrowernumber }
254
        }
255
    );
256
257
    my $message_2 = $builder->build_object(
258
        {
259
            class => 'Koha::Notice::Messages',
260
            value => { borrowernumber => $patron_2->borrowernumber }
261
        }
262
    );
263
264
    my $nb_messages = Koha::Notice::Messages->count;
265
266
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store;
267
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
268
    Koha::Library::Group->new( { parent_id => $group_1->id, branchcode => $patron->branchcode } )->store();
269
    Koha::Library::Group->new( { parent_id => $group_2->id, branchcode => $patron_2->branchcode } )->store();
270
    t::lib::Mocks::mock_userenv( { patron => $patron } );    # Is superlibrarian
271
    is(
272
        Koha::Notice::Messages->search_limited->count, $nb_messages,
273
        'Koha::Notice::Messages->search_limited should return all generated notices for superlibrarian'
274
    );
275
    t::lib::Mocks::mock_userenv( { patron => $patron_2 } );    # Is restricted
276
    is(
277
        Koha::Notice::Messages->search_limited->count, 1,
278
        'Koha:Notice::Messages->search_limited should not return all generated notices for restricted patron'
279
    );
280
};
281
242
1;
282
1;
(-)a/tools/notices.pl (-3 / +2 lines)
Lines 65-73 if ( $op and $op eq 'cud-search' ) { Link Here
65
    }
65
    }
66
    $where{'me.status'} = $status if ($status);
66
    $where{'me.status'} = $status if ($status);
67
67
68
    my $notices = Koha::Notice::Messages->search(
68
    my $notices = Koha::Notice::Messages->search_limited(
69
        {%where},
69
        {%where},
70
        { join => 'borrowernumber', order_by => { -desc => 'time_queued' } }
70
        { order_by => { -desc => 'time_queued' } }
71
    );
71
    );
72
72
73
    $template->param(
73
    $template->param(
74
- 

Return to bug 33260