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

(-)a/C4/Auth.pm (-5 / +1 lines)
Lines 1492-1501 sub checkauth { Link Here
1492
    my $auth_template_name = ( $type eq 'opac' ) ? 'opac-auth.tt' : 'auth.tt';
1492
    my $auth_template_name = ( $type eq 'opac' ) ? 'opac-auth.tt' : 'auth.tt';
1493
    my $template           = C4::Templates::gettemplate( $auth_template_name, $type, $query );
1493
    my $template           = C4::Templates::gettemplate( $auth_template_name, $type, $query );
1494
1494
1495
    my $borrowernumber      = $patron and $patron->borrowernumber;
1496
    my $anonymous_patron    = C4::Context->preference('AnonymousPatron');
1497
    my $is_anonymous_patron = $patron && ( $patron->borrowernumber eq $anonymous_patron );
1498
1499
    $template->param(
1495
    $template->param(
1500
        login                                 => 1,
1496
        login                                 => 1,
1501
        INPUTS                                => \@inputs,
1497
        INPUTS                                => \@inputs,
Lines 1530-1536 sub checkauth { Link Here
1530
        opac_css_override                     => $ENV{'OPAC_CSS_OVERRIDE'},
1526
        opac_css_override                     => $ENV{'OPAC_CSS_OVERRIDE'},
1531
        too_many_login_attempts               => ( $patron and $patron->account_locked ),
1527
        too_many_login_attempts               => ( $patron and $patron->account_locked ),
1532
        password_has_expired                  => ( $patron and $patron->password_expired ),
1528
        password_has_expired                  => ( $patron and $patron->password_expired ),
1533
        is_anonymous_patron                   => ($is_anonymous_patron),
1529
        is_anonymous_patron                   => ( $patron and $patron->is_anonymous ),
1534
        password_expiration_date              => ( $patron and $patron->password_expiration_date ),
1530
        password_expiration_date              => ( $patron and $patron->password_expiration_date ),
1535
        date_enrolled                         => ( $patron and $patron->dateenrolled ),
1531
        date_enrolled                         => ( $patron and $patron->dateenrolled ),
1536
        auth_error                            => $auth_error,
1532
        auth_error                            => $auth_error,
(-)a/Koha/Patron.pm (-9 / +19 lines)
Lines 473-481 ListOwnershipUponPatronDeletion pref, but entries from the borrower to other lis Link Here
473
sub delete {
473
sub delete {
474
    my ($self) = @_;
474
    my ($self) = @_;
475
475
476
    my $anonymous_patron = C4::Context->preference("AnonymousPatron");
477
    Koha::Exceptions::Patron::FailedDeleteAnonymousPatron->throw()
476
    Koha::Exceptions::Patron::FailedDeleteAnonymousPatron->throw()
478
        if $anonymous_patron && $self->id eq $anonymous_patron;
477
        if $self->is_anonymous;
479
478
480
    # Check if patron is protected
479
    # Check if patron is protected
481
    Koha::Exceptions::Patron::FailedDeleteProtectedPatron->throw() if defined $self->protected && $self->protected == 1;
480
    Koha::Exceptions::Patron::FailedDeleteProtectedPatron->throw() if defined $self->protected && $self->protected == 1;
Lines 736-743 sub siblings { Link Here
736
sub merge_with {
735
sub merge_with {
737
    my ( $self, $patron_ids ) = @_;
736
    my ( $self, $patron_ids ) = @_;
738
737
739
    my $anonymous_patron = C4::Context->preference("AnonymousPatron");
738
    return if $self->is_anonymous;
740
    return if $anonymous_patron && $self->id eq $anonymous_patron;
741
739
742
    # Do not merge other patrons into a protected patron
740
    # Do not merge other patrons into a protected patron
743
    return if $self->protected;
741
    return if $self->protected;
Lines 755-766 sub merge_with { Link Here
755
        sub {
753
        sub {
756
            foreach my $patron_id (@patron_ids) {
754
            foreach my $patron_id (@patron_ids) {
757
755
758
                next if $anonymous_patron && $patron_id eq $anonymous_patron;
759
760
                my $patron = Koha::Patrons->find($patron_id);
756
                my $patron = Koha::Patrons->find($patron_id);
761
757
762
                next unless $patron;
758
                next unless $patron;
763
759
760
                next if $patron->is_anonymous;
761
764
                # Do not merge protected patrons into other patrons
762
                # Do not merge protected patrons into other patrons
765
                next if $patron->protected;
763
                next if $patron->protected;
766
764
Lines 3048-3058 This method tells if the Koha:Patron object can be deleted. Possible return valu Link Here
3048
sub safe_to_delete {
3046
sub safe_to_delete {
3049
    my ($self) = @_;
3047
    my ($self) = @_;
3050
3048
3051
    my $anonymous_patron = C4::Context->preference('AnonymousPatron');
3052
3053
    my $error;
3049
    my $error;
3054
3050
3055
    if ( $anonymous_patron && $self->id eq $anonymous_patron ) {
3051
    if ( $self->is_anonymous ) {
3056
        $error = 'is_anonymous_patron';
3052
        $error = 'is_anonymous_patron';
3057
    } elsif ( $self->checkouts->count ) {
3053
    } elsif ( $self->checkouts->count ) {
3058
        $error = 'has_checkouts';
3054
        $error = 'has_checkouts';
Lines 3405-3410 sub is_patron_inside_charge_limits { Link Here
3405
    return $patron_charge_limits;
3401
    return $patron_charge_limits;
3406
}
3402
}
3407
3403
3404
=head3 is_anonymous
3405
3406
my $is_anonymous_patron= $patron->is_anonymous();
3407
3408
Returns true if the patron the anonymous patron (AnonymousPatron)
3409
3410
=cut
3411
3412
sub is_anonymous {
3413
    my ($self) = @_;
3414
    my $anonymous_patron = C4::Context->preference('AnonymousPatron');
3415
    return ( $anonymous_patron && $self->borrowernumber eq $anonymous_patron ) ? 1 : 0;
3416
}
3417
3408
=head2 Internal methods
3418
=head2 Internal methods
3409
3419
3410
=head3 _type
3420
=head3 _type
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 626-632 if ($patron) { Link Here
626
        $template->param( is_debarred => 1 );
626
        $template->param( is_debarred => 1 );
627
        $noissues = 1;
627
        $noissues = 1;
628
    }
628
    }
629
    if ( $patron->borrowernumber eq C4::Context->preference("AnonymousPatron") ) {
629
    if ( $patron->is_anonymous ) {
630
        $template->param( is_anonymous => 1 );
630
        $template->param( is_anonymous => 1 );
631
        $noissues = 1;
631
        $noissues = 1;
632
    }
632
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt (-1 / +1 lines)
Lines 45-51 Link Here
45
45
46
    [% UNLESS Koha.Preference('IntranetReadingHistoryHolds') %]
46
    [% UNLESS Koha.Preference('IntranetReadingHistoryHolds') %]
47
        <div class="alert alert-warning">Staff members are not allowed to access patron's holds history</div>
47
        <div class="alert alert-warning">Staff members are not allowed to access patron's holds history</div>
48
    [% ELSIF is_anonymous %]
48
    [% ELSIF patron.is_anonymous %]
49
        <div class="alert alert-warning">This is the anonymous patron, so no holds history is displayed.</div>
49
        <div class="alert alert-warning">This is the anonymous patron, so no holds history is displayed.</div>
50
    [% ELSE %]
50
    [% ELSE %]
51
51
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-1 / +1 lines)
Lines 50-56 Link Here
50
50
51
    [% INCLUDE 'members-toolbar.inc' %]
51
    [% INCLUDE 'members-toolbar.inc' %]
52
52
53
    [% IF is_anonymous %]
53
    [% IF patron.is_anonymous %]
54
        <div class="alert alert-warning">This is the anonymous patron.</div>
54
        <div class="alert alert-warning">This is the anonymous patron.</div>
55
    [% END %]
55
    [% END %]
56
56
(-)a/members/holdshistory.pl (-7 lines)
Lines 44-56 unless ($patron) { Link Here
44
    exit;
44
    exit;
45
}
45
}
46
46
47
if ( $borrowernumber eq C4::Context->preference('AnonymousPatron') ) {
48
49
    # use of 'eq' in the above comparison is intentional -- the
50
    # system preference value could be blank
51
    $template->param( is_anonymous => 1 );
52
}
53
54
$template->param(
47
$template->param(
55
    holdshistoryview => 1,
48
    holdshistoryview => 1,
56
    patron           => $patron,
49
    patron           => $patron,
(-)a/members/moremember.pl (-4 lines)
Lines 78-87 output_and_exit_if_error( Link Here
78
78
79
my $category_type = $patron->category->category_type;
79
my $category_type = $patron->category->category_type;
80
80
81
if ( $patron->borrowernumber eq C4::Context->preference("AnonymousPatron") ) {
82
    $template->param( is_anonymous => 1 );
83
}
84
85
for (qw(gonenoaddress lost borrowernotes is_debarred)) {
81
for (qw(gonenoaddress lost borrowernotes is_debarred)) {
86
    $patron->$_ and $template->param( flagged => 1 ) and last;
82
    $patron->$_ and $template->param( flagged => 1 ) and last;
87
}
83
}
(-)a/members/readingrec.pl (-4 / +1 lines)
Lines 86-95 if ( $op eq 'export_barcodes' ) { Link Here
86
}
86
}
87
87
88
# Do not request the old issues of anonymous patron
88
# Do not request the old issues of anonymous patron
89
if ( $patron->borrowernumber eq C4::Context->preference('AnonymousPatron') ) {
89
if ( $patron->is_anonymous ) {
90
91
    # use of 'eq' in the above comparison is intentional -- the
92
    # system preference value could be blank
93
    $template->param( is_anonymous => 1 );
90
    $template->param( is_anonymous => 1 );
94
} else {
91
} else {
95
    $template->param(
92
    $template->param(
(-)a/t/db_dependent/Auth.t (-1 / +2 lines)
Lines 7-13 use CGI qw ( -utf8 ); Link Here
7
use Test::MockObject;
7
use Test::MockObject;
8
use Test::MockModule;
8
use Test::MockModule;
9
use List::MoreUtils qw/all any none/;
9
use List::MoreUtils qw/all any none/;
10
use Test::More tests => 23;
10
use Test::More tests => 24;
11
use Test::NoWarnings;
11
use Test::Warn;
12
use Test::Warn;
12
use t::lib::Mocks;
13
use t::lib::Mocks;
13
use t::lib::TestBuilder;
14
use t::lib::TestBuilder;
(-)a/t/db_dependent/Koha/Patron.t (-2 / +25 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 40;
22
use Test::More tests => 42;
23
use Test::NoWarnings;
23
use Test::Exception;
24
use Test::Exception;
24
use Test::Warn;
25
use Test::Warn;
25
use Time::Fake;
26
use Time::Fake;
Lines 3094-3096 subtest 'can_place_holds() tests' => sub { Link Here
3094
        $schema->storage->txn_rollback;
3095
        $schema->storage->txn_rollback;
3095
    };
3096
    };
3096
};
3097
};
3097
- 
3098
3099
subtest 'is_anonymous' => sub {
3100
    plan tests => 3;
3101
3102
    $schema->storage->txn_begin;
3103
3104
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
3105
3106
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
3107
3108
    is( $patron->is_anonymous, 0, 'is_anonymous returns 0 if pref is empty' );
3109
3110
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $patron->borrowernumber );
3111
3112
    is( $patron->is_anonymous, 1, q{is_anonymous returns 1 if pref is equal to patron's id} );
3113
3114
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $patron->borrowernumber + 1 );
3115
3116
    is( $patron->is_anonymous, 0, q{is_anonymous returns 0 if pref is not equal to patron's id} );
3117
3118
    $schema->storage->txn_begin;
3119
3120
    }

Return to bug 40401