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

(-)a/Koha/Patron.pm (-1 / +102 lines)
Lines 1460-1465 sub can_see_patrons_from { Link Here
1460
    );
1460
    );
1461
}
1461
}
1462
1462
1463
=head3 libraries_where_can_see_patrons
1464
1465
my $libraries = $patron-libraries_where_can_see_patrons;
1466
1467
Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos.
1468
The branchcodes are arbitrarily returned sorted.
1469
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1470
1471
An empty array means no restriction, the patron can see patron's infos from any libraries.
1472
1473
=cut
1474
1475
sub libraries_where_can_see_patrons {
1476
    my ($self) = @_;
1477
1478
    return $self->libraries_where_can_see_things(
1479
        {
1480
            permission    => 'borrowers',
1481
            subpermission => 'view_borrower_infos_from_any_libraries',
1482
            group_feature => 'ft_hide_patron_info',
1483
        }
1484
    );
1485
}
1486
1487
=head3 can_edit_item
1488
1489
my $can_edit = $patron->can_edit_item( $item );
1490
1491
Return true if the patron (usually the logged in user) can edit the given item
1492
1493
The parameter can be a Koha::Item, an item hashref, or a branchcode.
1494
1495
=cut
1496
1497
sub can_edit_item {
1498
    my ( $self, $item ) = @_;
1499
1500
    my $userenv = C4::Context->userenv();
1501
1502
    my $ref = ref($item);
1503
1504
    my $branchcode =
1505
        $ref eq 'Koha::Item' ? $item->homebranch
1506
      : $ref eq 'HASH'       ? $item->{homebranch}
1507
      : $ref eq q{}          ? $item
1508
      :                        undef;
1509
1510
    return unless $branchcode;
1511
1512
    return 1 if C4::Context->IsSuperLibrarian();
1513
1514
    if ( C4::Context->preference('IndependentBranches') ) {
1515
        return $userenv->{branch} eq $branchcode;
1516
    }
1517
1518
    return $self->can_edit_items_from($branchcode);
1519
}
1520
1521
=head3 can_edit_items_from
1522
1523
my $can_edit = $patron->can_edit_items_from( $branchcode );
1524
1525
Return true if this user can edit items from the give home branchcode
1526
1527
=cut
1528
1529
sub can_edit_items_from {
1530
    my ( $self, $branchcode ) = @_;
1531
1532
    return $self->can_see_things_from(
1533
        {
1534
            branchcode    => $branchcode,
1535
            permission    => 'editcatalogue',
1536
            subpermission => 'edit_any_item',
1537
        }
1538
    );
1539
}
1540
1541
=head3 libraries_where_can_edit_items
1542
1543
my $libraries = $patron->libraries_where_can_edit_items;
1544
1545
Return the list of branchcodes(!) of libraries the patron is allowed to items for.
1546
The branchcodes are arbitrarily returned sorted.
1547
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1548
1549
An empty array means no restriction, the user can edit any item.
1550
1551
=cut
1552
1553
sub libraries_where_can_edit_items {
1554
    my ($self) = @_;
1555
1556
    return $self->libraries_where_can_see_things(
1557
        {
1558
            permission    => 'editcatalogue',
1559
            subpermission => 'edit_any_item',
1560
            group_feature => 'ft_limit_item_editing',
1561
        }
1562
    );
1563
}
1564
1463
=head3 can_see_things_from
1565
=head3 can_see_things_from
1464
1566
1465
my $can_see = $thing->can_see_things_from( $branchcode );
1567
my $can_see = $thing->can_see_things_from( $branchcode );
1466
- 

Return to bug 20256