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

(-)a/Koha/Patron.pm (+27 lines)
Lines 1364-1369 sub can_see_patrons_from { Link Here
1364
    return $can;
1364
    return $can;
1365
}
1365
}
1366
1366
1367
=head3 can_log_into
1368
1369
my $can_log_into = $patron->can_log_into( $library );
1370
1371
Given a I<Koha::Library> object, it returns a boolean representing
1372
the fact the patron can log into a the library.
1373
1374
=cut
1375
1376
sub can_log_into {
1377
    my ( $self, $library ) = @_;
1378
1379
    my $can = 0;
1380
1381
    if ( C4::Context->preference('IndependentBranches') ) {
1382
        $can = 1
1383
          if $self->is_superlibrarian
1384
          or $self->branchcode eq $library->id;
1385
    }
1386
    else {
1387
        # no restrictions
1388
        $can = 1;
1389
    }
1390
1391
   return $can;
1392
}
1393
1367
=head3 libraries_where_can_see_patrons
1394
=head3 libraries_where_can_see_patrons
1368
1395
1369
my $libraries = $patron-libraries_where_can_see_patrons;
1396
my $libraries = $patron-libraries_where_can_see_patrons;
(-)a/t/db_dependent/Koha/Patron.t (-2 / +36 lines)
Lines 19-25 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
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 662-664 subtest 'extended_attributes' => sub { Link Here
662
662
663
    $schema->storage->txn_rollback;
663
    $schema->storage->txn_rollback;
664
};
664
};
665
- 
665
666
subtest 'can_log_into() tests' => sub {
667
668
    plan tests => 5;
669
670
    $schema->storage->txn_begin;
671
672
    my $patron = $builder->build_object(
673
        {
674
            class => 'Koha::Patrons',
675
            value => {
676
                flags => undef
677
            }
678
        }
679
    );
680
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
681
682
    t::lib::Mocks::mock_preference('IndependentBranches', 1);
683
684
    ok( $patron->can_log_into( $patron->library ), 'Patron can log into its own library' );
685
    ok( !$patron->can_log_into( $library ), 'Patron cannot log into different library, IndependentBranches on' );
686
687
    # make it a superlibrarian
688
    $patron->set({ flags => 1 })->store->discard_changes;
689
    ok( $patron->can_log_into( $library ), 'Superlibrarian can log into different library, IndependentBranches on' );
690
691
    t::lib::Mocks::mock_preference('IndependentBranches', 0);
692
693
    # No special permissions
694
    $patron->set({ flags => undef })->store->discard_changes;
695
    ok( $patron->can_log_into( $patron->library ), 'Patron can log into its own library' );
696
    ok( $patron->can_log_into( $library ), 'Patron can log into any library' );
697
698
    $schema->storage->txn_rollback;
699
};

Return to bug 28157