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

(-)a/Koha/Template/Plugin/Categories.pm (+11 lines)
Lines 33-38 sub GetName { Link Here
33
    return Koha::Patron::Categories->find( $categorycode )->description;
33
    return Koha::Patron::Categories->find( $categorycode )->description;
34
}
34
}
35
35
36
sub can_any_reset_password {
37
    return ( grep { $_->effective_reset_password } @{ Koha::Patron::Categories->search->as_list } )
38
        ? 1
39
        : 0;
40
}
41
36
1;
42
1;
37
43
38
=head1 NAME
44
=head1 NAME
Lines 57-62 the following TT code: [% Categories.all() %] Link Here
57
In a template, you can get the name of a patron category using
63
In a template, you can get the name of a patron category using
58
[% Categories.GetName( categorycode ) %].
64
[% Categories.GetName( categorycode ) %].
59
65
66
=head2 can_any_reset_password
67
68
Returns I<true> is any patron category has the I<effective_reset_password> evaluate to I<true>.
69
Returns I<false> otherwise.
70
60
=head1 AUTHOR
71
=head1 AUTHOR
61
72
62
Jonathan Druart <jonathan.druart@biblibre.com>
73
Jonathan Druart <jonathan.druart@biblibre.com>
(-)a/t/db_dependent/Template/Plugin/Categories.t (-2 / +25 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 4;
20
use Test::More tests => 5;
21
use t::lib::Mocks;
21
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
22
23
23
use Koha::Patron::Categories;
24
use Koha::Patron::Categories;
Lines 57-59 is( Koha::Template::Plugin::Categories->GetName( Link Here
57
58
58
$schema->storage->txn_rollback;
59
$schema->storage->txn_rollback;
59
60
60
- 
61
subtest 'can_any_reset_password() tests' => sub {
62
63
    plan tests => 3;
64
65
    $schema->storage->txn_begin;
66
67
    # Make sure all existing categories have reset_password set to 0
68
    Koha::Patron::Categories->update({ reset_password => 0 });
69
70
    ok( !Koha::Template::Plugin::Categories->new->can_any_reset_password, 'No category is allowed to reset password' );
71
72
    t::lib::Mocks::mock_preference( 'OpacResetPassword', 0 );
73
74
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { reset_password => 1 } });
75
76
    ok( Koha::Template::Plugin::Categories->new->can_any_reset_password, 'There\'s at least a category that is allowed to reset password' );
77
78
    $category->reset_password( undef )->store;
79
80
    ok( !Koha::Template::Plugin::Categories->new->can_any_reset_password, 'No category is allowed to reset password' );
81
82
    $schema->storage->txn_rollback;
83
};

Return to bug 21890