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

(-)a/Koha/Patron.pm (-1 / +102 lines)
Lines 1494-1499 sub can_see_patrons_from { Link Here
1494
    );
1494
    );
1495
}
1495
}
1496
1496
1497
=head3 libraries_where_can_see_patrons
1498
1499
my $libraries = $patron-libraries_where_can_see_patrons;
1500
1501
Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos.
1502
The branchcodes are arbitrarily returned sorted.
1503
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1504
1505
An empty array means no restriction, the patron can see patron's infos from any libraries.
1506
1507
=cut
1508
1509
sub libraries_where_can_see_patrons {
1510
    my ($self) = @_;
1511
1512
    return $self->libraries_where_can_see_things(
1513
        {
1514
            permission    => 'borrowers',
1515
            subpermission => 'view_borrower_infos_from_any_libraries',
1516
            group_feature => 'ft_hide_patron_info',
1517
        }
1518
    );
1519
}
1520
1521
=head3 can_edit_item
1522
1523
my $can_edit = $patron->can_edit_item( $item );
1524
1525
Return true if the patron (usually the logged in user) can edit the given item
1526
1527
The parameter can be a Koha::Item, an item hashref, or a branchcode.
1528
1529
=cut
1530
1531
sub can_edit_item {
1532
    my ( $self, $item ) = @_;
1533
1534
    my $userenv = C4::Context->userenv();
1535
1536
    my $ref = ref($item);
1537
1538
    my $branchcode =
1539
        $ref eq 'Koha::Item' ? $item->homebranch
1540
      : $ref eq 'HASH'       ? $item->{homebranch}
1541
      : $ref eq q{}          ? $item
1542
      :                        undef;
1543
1544
    return unless $branchcode;
1545
1546
    return 1 if C4::Context->IsSuperLibrarian();
1547
1548
    if ( C4::Context->preference('IndependentBranches') ) {
1549
        return $userenv->{branch} eq $branchcode;
1550
    }
1551
1552
    return $self->can_edit_items_from($branchcode);
1553
}
1554
1555
=head3 can_edit_items_from
1556
1557
my $can_edit = $patron->can_edit_items_from( $branchcode );
1558
1559
Return true if this user can edit items from the give home branchcode
1560
1561
=cut
1562
1563
sub can_edit_items_from {
1564
    my ( $self, $branchcode ) = @_;
1565
1566
    return $self->can_see_things_from(
1567
        {
1568
            branchcode    => $branchcode,
1569
            permission    => 'editcatalogue',
1570
            subpermission => 'edit_any_item',
1571
        }
1572
    );
1573
}
1574
1575
=head3 libraries_where_can_edit_items
1576
1577
my $libraries = $patron->libraries_where_can_edit_items;
1578
1579
Return the list of branchcodes(!) of libraries the patron is allowed to items for.
1580
The branchcodes are arbitrarily returned sorted.
1581
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1582
1583
An empty array means no restriction, the user can edit any item.
1584
1585
=cut
1586
1587
sub libraries_where_can_edit_items {
1588
    my ($self) = @_;
1589
1590
    return $self->libraries_where_can_see_things(
1591
        {
1592
            permission    => 'editcatalogue',
1593
            subpermission => 'edit_any_item',
1594
            group_feature => 'ft_limit_item_editing',
1595
        }
1596
    );
1597
}
1598
1497
=head3 can_see_things_from
1599
=head3 can_see_things_from
1498
1600
1499
my $can_see = $thing->can_see_things_from( $branchcode );
1601
my $can_see = $thing->can_see_things_from( $branchcode );
1500
- 

Return to bug 20256