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

(-)a/Koha/Reviews.pm (+23 lines)
Lines 35-40 Koha::Reviews - Koha Review Object set class Link Here
35
35
36
=cut
36
=cut
37
37
38
=head2 search_limited
39
40
my $reviews = Koha::Reviews->search_limited( $params, $attributes );
41
42
Search for reviews according to logged in patron restrictions
43
44
=cut
45
46
sub search_limited {
47
    my ( $self, $params, $attributes ) = @_;
48
49
    my $userenv = C4::Context->userenv;
50
    my @restricted_branchcodes;
51
    if ( $userenv ) {
52
        my $logged_in_user = Koha::Patrons->find( $userenv->{number} );
53
        @restricted_branchcodes = $logged_in_user->libraries_where_can_see_patrons;
54
    }
55
    # TODO This 'borrowernumber' relation name is confusing and needs to be renamed
56
    $params->{'borrowernumber.branchcode'} = { -in => \@restricted_branchcodes } if @restricted_branchcodes;
57
    $attributes->{join} = 'borrowernumber';
58
    return $self->search( $params, $attributes );
59
}
60
38
=head3 type
61
=head3 type
39
62
40
=cut
63
=cut
(-)a/mainpage.pl (-1 / +1 lines)
Lines 63-69 my $branch = Link Here
63
  ? C4::Context->userenv()->{'branch'}
63
  ? C4::Context->userenv()->{'branch'}
64
  : undef;
64
  : undef;
65
65
66
my $pendingcomments    = Koha::Reviews->search({ approved => 0 })->count;
66
my $pendingcomments    = Koha::Reviews->search_limited({ approved => 0 })->count;
67
my $pendingtags        = get_count_by_tag_status(0);
67
my $pendingtags        = get_count_by_tag_status(0);
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 );
(-)a/reviews/reviewswaiting.pl (-2 / +2 lines)
Lines 42-48 my $status = $query->param('status') || 0; Link Here
42
my $reviewid = $query->param('reviewid');
42
my $reviewid = $query->param('reviewid');
43
my $page     = $query->param('page') || 1;
43
my $page     = $query->param('page') || 1;
44
my $count    = C4::Context->preference('numSearchResults') || 20;
44
my $count    = C4::Context->preference('numSearchResults') || 20;
45
my $total    = Koha::Reviews->search({ approved => $status })->count;
45
my $total    = Koha::Reviews->search_limited({ approved => $status })->count;
46
46
47
if ( $op eq 'approve' ) {
47
if ( $op eq 'approve' ) {
48
    my $review = Koha::Reviews->find( $reviewid );
48
    my $review = Koha::Reviews->find( $reviewid );
Lines 57-63 elsif ( $op eq 'delete' ) { Link Here
57
    $review->delete if $review;
57
    $review->delete if $review;
58
}
58
}
59
59
60
my $reviews = Koha::Reviews->search(
60
my $reviews = Koha::Reviews->search_limited(
61
    { approved => $status },
61
    { approved => $status },
62
    {
62
    {
63
        rows => $count,
63
        rows => $count,
(-)a/t/db_dependent/Koha/Reviews.t (-6 / +31 lines)
Lines 19-27 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 8;
23
23
24
use Koha::Review;
24
use Koha::Patrons;
25
use Koha::Reviews;
25
use Koha::Reviews;
26
use Koha::Database;
26
use Koha::Database;
27
27
Lines 31-54 my $schema = Koha::Database->new->schema; Link Here
31
$schema->storage->txn_begin;
31
$schema->storage->txn_begin;
32
32
33
my $builder = t::lib::TestBuilder->new;
33
my $builder = t::lib::TestBuilder->new;
34
my $patron_1 = $builder->build({ source => 'Borrower' });
34
my $patron_1 = $builder->build({ source => 'Borrower', value => { flags => undef } });
35
my $patron_2 = $builder->build({ source => 'Borrower' });
35
my $patron_2 = $builder->build({ source => 'Borrower' });
36
$patron_1 = Koha::Patrons->find( $patron_1->{borrowernumber} );
37
$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} );
36
my $biblio_1 = $builder->build({ source => 'Biblio' });
38
my $biblio_1 = $builder->build({ source => 'Biblio' });
37
my $biblio_2 = $builder->build({ source => 'Biblio' });
39
my $biblio_2 = $builder->build({ source => 'Biblio' });
38
my $nb_of_reviews = Koha::Reviews->search->count;
40
my $nb_of_reviews = Koha::Reviews->search->count;
39
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count;
41
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count;
40
my $new_review_1_1 = Koha::Review->new({
42
my $new_review_1_1 = Koha::Review->new({
41
    borrowernumber => $patron_1->{borrowernumber},
43
    borrowernumber => $patron_1->borrowernumber,
42
    biblionumber => $biblio_1->{biblionumber},
44
    biblionumber => $biblio_1->{biblionumber},
43
    review => 'a kind review',
45
    review => 'a kind review',
44
})->store;
46
})->store;
45
my $new_review_1_2 = Koha::Review->new({
47
my $new_review_1_2 = Koha::Review->new({
46
    borrowernumber => $patron_1->{borrowernumber},
48
    borrowernumber => $patron_1->borrowernumber,
47
    biblionumber => $biblio_2->{biblionumber},
49
    biblionumber => $biblio_2->{biblionumber},
48
    review => 'anoter kind review',
50
    review => 'anoter kind review',
49
})->store;
51
})->store;
50
my $new_review_2_1 = Koha::Review->new({
52
my $new_review_2_1 = Koha::Review->new({
51
    borrowernumber => $patron_2->{borrowernumber},
53
    borrowernumber => $patron_2->borrowernumber,
52
    biblionumber => $biblio_1->{biblionumber},
54
    biblionumber => $biblio_1->{biblionumber},
53
    review => 'just anoter review',
55
    review => 'just anoter review',
54
})->store;
56
})->store;
Lines 65-73 is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews, 'The Link Here
65
my $retrieved_review_1_1 = Koha::Reviews->find( $new_review_1_1->reviewid );
67
my $retrieved_review_1_1 = Koha::Reviews->find( $new_review_1_1->reviewid );
66
is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id should return the correct review' );
68
is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id should return the correct review' );
67
69
70
subtest 'search_limited' => sub {
71
    plan tests => 2;
72
    C4::Context->_new_userenv('xxx');
73
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store;
74
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
75
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron_1->branchcode })->store();
76
    Koha::Library::Group->new({ parent_id => $group_2->id,  branchcode => $patron_2->branchcode })->store();
77
    set_logged_in_user( $patron_1 );
78
    is( Koha::Reviews->search->count, $nb_of_approved_reviews + 3, 'Koha::Reviews->search should return all reviews' );
79
    is( Koha::Reviews->search_limited->count, $nb_of_approved_reviews + 2, 'Koha::Reviews->search_limited should return reviews depending on patron permissions' );
80
};
81
68
$retrieved_review_1_1->delete;
82
$retrieved_review_1_1->delete;
69
is( Koha::Reviews->search->count, $nb_of_reviews + 2, 'Delete should have deleted the review' );
83
is( Koha::Reviews->search->count, $nb_of_reviews + 2, 'Delete should have deleted the review' );
70
84
71
$schema->storage->txn_rollback;
85
$schema->storage->txn_rollback;
72
86
87
sub set_logged_in_user {
88
    my ($patron) = @_;
89
    C4::Context->set_userenv(
90
        $patron->borrowernumber, $patron->userid,
91
        $patron->cardnumber,     'firstname',
92
        'surname',               $patron->library->branchcode,
93
        'Midway Public Library', $patron->flags,
94
        '',                      ''
95
    );
96
}
97
73
1;
98
1;
(-)a/tools/tools-home.pl (-2 / +1 lines)
Lines 35-41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
35
    }
35
    }
36
);
36
);
37
37
38
my $pendingcomments = Koha::Reviews->search({ approved => 0 })->count;
38
my $pendingcomments = Koha::Reviews->search_limited({ approved => 0 })->count;
39
my $pendingtags = get_count_by_tag_status(0);
39
my $pendingtags = get_count_by_tag_status(0);
40
40
41
$template->param(
41
$template->param(
42
- 

Return to bug 18403