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-32 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 49;
22
use Test::More tests => 50;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
25
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::Biblio;
27
use Koha::Biblio;
28
use Koha::Patron;
28
use Koha::Patron;
29
use Koha::Library;
29
30
use t::lib::TestBuilder;
30
31
31
BEGIN {
32
BEGIN {
32
    use_ok('Koha::ArticleRequest');
33
    use_ok('Koha::ArticleRequest');
Lines 69-77 my $patron = Koha::Patron->new( Link Here
69
    {
70
    {
70
        categorycode => $category->{categorycode},
71
        categorycode => $category->{categorycode},
71
        branchcode   => $branch->{branchcode},
72
        branchcode   => $branch->{branchcode},
73
        flags        => 1,# superlibrarian
72
    }
74
    }
73
)->store();
75
)->store();
74
ok( $patron->id, 'Koha::Patron created' );
76
ok( $patron->id, 'Koha::Patron created' );
77
my $patron_2 = $builder->build({ source => 'Borrower', value => { flags => 0 } });
78
$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} );
79
80
my $nb_article_requests = Koha::ArticleRequests->count;
75
81
76
my $article_request = Koha::ArticleRequest->new(
82
my $article_request = Koha::ArticleRequest->new(
77
    {
83
    {
Lines 177-180 ok( !$item->can_article_request($patron), 'Item is not requestable with rule t Link Here
177
is( $item->article_request_type($patron), 'no', 'Item article request type is no' );
183
is( $item->article_request_type($patron), 'no', 'Item article request type is no' );
178
$rule->delete();
184
$rule->delete();
179
185
186
subtest 'search_limited' => sub {
187
    plan tests => 4;
188
    C4::Context->_new_userenv('xxx');
189
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store;
190
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
191
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron->branchcode })->store();
192
    Koha::Library::Group->new({ parent_id => $group_2->id,  branchcode => $patron_2->branchcode })->store();
193
    set_logged_in_user( $patron ); # Is superlibrarian
194
    is( Koha::ArticleRequests->count, $nb_article_requests + 1, 'Koha::ArticleRequests should return all article requests' );
195
    is( Koha::ArticleRequests->search_limited->count, $nb_article_requests + 1, 'Koha::ArticleRequests->search_limited should return all article requests for superlibrarian' );
196
    set_logged_in_user( $patron_2 ); # Is restricted
197
    is( Koha::ArticleRequests->count, $nb_article_requests + 1, 'Koha::ArticleRequests should return all article requests' );
198
    is( Koha::ArticleRequests->search_limited->count, $nb_article_requests, 'Koha::ArticleRequests->search_limited should not return all article requests for restricted patron' );
199
};
200
180
$schema->storage->txn_rollback();
201
$schema->storage->txn_rollback();
181
- 
202
203
sub set_logged_in_user {
204
    my ($patron) = @_;
205
    C4::Context->set_userenv(
206
        $patron->borrowernumber, $patron->userid,
207
        $patron->cardnumber,     'firstname',
208
        'surname',               $patron->library->branchcode,
209
        'Midway Public Library', $patron->flags,
210
        '',                      ''
211
    );
212
}

Return to bug 18403