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

(-)a/Koha/ArticleRequests.pm (-8 / +31 lines)
Lines 38-43 Koha::ArticleRequests - Koha ArticleRequests Object class Link Here
38
38
39
=cut
39
=cut
40
40
41
=head3 search_limited
42
43
my $article_requests = Koha::ArticleRequests->search_limited( $params, $attributes );
44
45
Search for article requests according to logged in patron restrictions
46
47
=cut
48
49
sub search_limited {
50
    my ( $self, $params, $attributes ) = @_;
51
52
    my $userenv = C4::Context->userenv;
53
    my @restricted_branchcodes;
54
    if ( $userenv ) {
55
        my $logged_in_user = Koha::Patrons->find( $userenv->{number} );
56
        @restricted_branchcodes = $logged_in_user->libraries_where_can_see_patrons;
57
    }
58
    # TODO This 'borrowernumber' relation name is confusing and needs to be renamed
59
    $params->{'borrowernumber.branchcode'} = { -in => \@restricted_branchcodes } if @restricted_branchcodes;
60
    $attributes->{join} = 'borrowernumber';
61
    return $self->search( $params, $attributes );
62
}
63
41
=head3 pending
64
=head3 pending
42
65
43
=cut
66
=cut
Lines 45-52 Koha::ArticleRequests - Koha ArticleRequests Object class Link Here
45
sub pending {
68
sub pending {
46
    my ( $self, $branchcode ) = @_;
69
    my ( $self, $branchcode ) = @_;
47
    my $params = { status => Koha::ArticleRequest::Status::Pending };
70
    my $params = { status => Koha::ArticleRequest::Status::Pending };
48
    $params->{branchcode} = $branchcode if $branchcode;
71
    $params->{'me.branchcode'} = $branchcode if $branchcode;
49
    return Koha::ArticleRequests->search( $params );
72
    return Koha::ArticleRequests->search_limited( $params );
50
}
73
}
51
74
52
=head3 processing
75
=head3 processing
Lines 56-63 sub pending { Link Here
56
sub processing {
79
sub processing {
57
    my ( $self, $branchcode ) = @_;
80
    my ( $self, $branchcode ) = @_;
58
    my $params = { status => Koha::ArticleRequest::Status::Processing };
81
    my $params = { status => Koha::ArticleRequest::Status::Processing };
59
    $params->{branchcode} = $branchcode if $branchcode;
82
    $params->{'me.branchcode'} = $branchcode if $branchcode;
60
    return Koha::ArticleRequests->search( $params );
83
    return Koha::ArticleRequests->search_limited( $params );
61
}
84
}
62
85
63
=head3 completed
86
=head3 completed
Lines 67-74 sub processing { Link Here
67
sub completed {
90
sub completed {
68
    my ( $self, $branchcode ) = @_;
91
    my ( $self, $branchcode ) = @_;
69
    my $params = { status => Koha::ArticleRequest::Status::Completed };
92
    my $params = { status => Koha::ArticleRequest::Status::Completed };
70
    $params->{branchcode} = $branchcode if $branchcode;
93
    $params->{'me.branchcode'} = $branchcode if $branchcode;
71
    return Koha::ArticleRequests->search( $params );
94
    return Koha::ArticleRequests->search_limited( $params );
72
}
95
}
73
96
74
=head3 canceled
97
=head3 canceled
Lines 78-85 sub completed { Link Here
78
sub canceled {
101
sub canceled {
79
    my ( $self, $branchcode ) = @_;
102
    my ( $self, $branchcode ) = @_;
80
    my $params = { status => Koha::ArticleRequest::Status::Canceled };
103
    my $params = { status => Koha::ArticleRequest::Status::Canceled };
81
    $params->{branchcode} = $branchcode if $branchcode;
104
    $params->{'me.branchcode'} = $branchcode if $branchcode;
82
    return Koha::ArticleRequests->search( $params );
105
    return Koha::ArticleRequests->search_limited( $params );
83
}
106
}
84
107
85
=head3 _type
108
=head3 _type
(-)a/mainpage.pl (-2 / +2 lines)
Lines 68-79 my $pendingtags = get_count_by_tag_status(0); Link Here
68
my $pendingsuggestions = CountSuggestion("ASKED");
68
my $pendingsuggestions = CountSuggestion("ASKED");
69
my $pending_borrower_modifications = Koha::Patron::Modifications->pending_count( $branch );
69
my $pending_borrower_modifications = Koha::Patron::Modifications->pending_count( $branch );
70
my $pending_discharge_requests = Koha::Patron::Discharge::count({ pending => 1 });
70
my $pending_discharge_requests = Koha::Patron::Discharge::count({ pending => 1 });
71
my $pending_article_requests = Koha::ArticleRequests->count(
71
my $pending_article_requests = Koha::ArticleRequests->search_limited(
72
    {
72
    {
73
        status => Koha::ArticleRequest::Status::Pending,
73
        status => Koha::ArticleRequest::Status::Pending,
74
        $branch ? ( branchcode => $branch ) : (),
74
        $branch ? ( branchcode => $branch ) : (),
75
    }
75
    }
76
);
76
)->count;
77
77
78
$template->param(
78
$template->param(
79
    pendingcomments                => $pendingcomments,
79
    pendingcomments                => $pendingcomments,
(-)a/t/db_dependent/ArticleRequests.t (-3 / +34 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 54;
22
use Test::More tests => 55;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
25
Lines 27-33 use Koha::Database; Link Here
27
use Koha::Biblio;
27
use Koha::Biblio;
28
use Koha::Notice::Messages;
28
use Koha::Notice::Messages;
29
use Koha::Patron;
29
use Koha::Patron;
30
use Koha::Library;
30
31
use t::lib::TestBuilder;
31
32
32
BEGIN {
33
BEGIN {
33
    use_ok('Koha::ArticleRequest');
34
    use_ok('Koha::ArticleRequest');
Lines 70-78 my $patron = Koha::Patron->new( Link Here
70
    {
71
    {
71
        categorycode => $category->{categorycode},
72
        categorycode => $category->{categorycode},
72
        branchcode   => $branch->{branchcode},
73
        branchcode   => $branch->{branchcode},
74
        flags        => 1,# superlibrarian
73
    }
75
    }
74
)->store();
76
)->store();
75
ok( $patron->id, 'Koha::Patron created' );
77
ok( $patron->id, 'Koha::Patron created' );
78
my $patron_2 = $builder->build({ source => 'Borrower', value => { flags => 0 } });
79
$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} );
80
81
my $nb_article_requests = Koha::ArticleRequests->count;
76
82
77
# store
83
# store
78
Koha::Notice::Messages->delete;
84
Koha::Notice::Messages->delete;
Lines 198-201 ok( !$item->can_article_request($patron), 'Item is not requestable with rule t Link Here
198
is( $item->article_request_type($patron), 'no', 'Item article request type is no' );
204
is( $item->article_request_type($patron), 'no', 'Item article request type is no' );
199
$rule->delete();
205
$rule->delete();
200
206
207
subtest 'search_limited' => sub {
208
    plan tests => 4;
209
    C4::Context->_new_userenv('xxx');
210
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store;
211
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
212
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron->branchcode })->store();
213
    Koha::Library::Group->new({ parent_id => $group_2->id,  branchcode => $patron_2->branchcode })->store();
214
    set_logged_in_user( $patron ); # Is superlibrarian
215
    is( Koha::ArticleRequests->count, $nb_article_requests + 1, 'Koha::ArticleRequests should return all article requests' );
216
    is( Koha::ArticleRequests->search_limited->count, $nb_article_requests + 1, 'Koha::ArticleRequests->search_limited should return all article requests for superlibrarian' );
217
    set_logged_in_user( $patron_2 ); # Is restricted
218
    is( Koha::ArticleRequests->count, $nb_article_requests + 1, 'Koha::ArticleRequests should return all article requests' );
219
    is( Koha::ArticleRequests->search_limited->count, $nb_article_requests, 'Koha::ArticleRequests->search_limited should not return all article requests for restricted patron' );
220
};
221
201
$schema->storage->txn_rollback();
222
$schema->storage->txn_rollback();
202
- 
223
224
sub set_logged_in_user {
225
    my ($patron) = @_;
226
    C4::Context->set_userenv(
227
        $patron->borrowernumber, $patron->userid,
228
        $patron->cardnumber,     'firstname',
229
        'surname',               $patron->library->branchcode,
230
        'Midway Public Library', $patron->flags,
231
        '',                      ''
232
    );
233
}

Return to bug 18403