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

(-)a/Koha/Patron.pm (-1 / +102 lines)
Lines 1366-1371 sub can_see_patrons_from { Link Here
1366
    );
1366
    );
1367
}
1367
}
1368
1368
1369
=head3 libraries_where_can_see_patrons
1370
1371
my $libraries = $patron-libraries_where_can_see_patrons;
1372
1373
Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos.
1374
The branchcodes are arbitrarily returned sorted.
1375
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1376
1377
An empty array means no restriction, the patron can see patron's infos from any libraries.
1378
1379
=cut
1380
1381
sub libraries_where_can_see_patrons {
1382
    my ($self) = @_;
1383
1384
    return $self->libraries_where_can_see_things(
1385
        {
1386
            permission    => 'borrowers',
1387
            subpermission => 'view_borrower_infos_from_any_libraries',
1388
            group_feature => 'ft_hide_patron_info',
1389
        }
1390
    );
1391
}
1392
1393
=head3 can_edit_item
1394
1395
my $can_edit = $patron->can_edit_item( $item );
1396
1397
Return true if the patron (usually the logged in user) can edit the given item
1398
1399
The parameter can be a Koha::Item, an item hashref, or a branchcode.
1400
1401
=cut
1402
1403
sub can_edit_item {
1404
    my ( $self, $item ) = @_;
1405
1406
    my $userenv = C4::Context->userenv();
1407
1408
    my $ref = ref($item);
1409
1410
    my $branchcode =
1411
        $ref eq 'Koha::Item' ? $item->homebranch
1412
      : $ref eq 'HASH'       ? $item->{homebranch}
1413
      : $ref eq q{}          ? $item
1414
      :                        undef;
1415
1416
    return unless $branchcode;
1417
1418
    return 1 if C4::Context->IsSuperLibrarian();
1419
1420
    if ( C4::Context->preference('IndependentBranches') ) {
1421
        return $userenv->{branch} eq $branchcode;
1422
    }
1423
1424
    return $self->can_edit_items_from($branchcode);
1425
}
1426
1427
=head3 can_edit_items_from
1428
1429
my $can_edit = $patron->can_edit_items_from( $branchcode );
1430
1431
Return true if this user can edit items from the give home branchcode
1432
1433
=cut
1434
1435
sub can_edit_items_from {
1436
    my ( $self, $branchcode ) = @_;
1437
1438
    return $self->can_see_things_from(
1439
        {
1440
            branchcode    => $branchcode,
1441
            permission    => 'editcatalogue',
1442
            subpermission => 'edit_any_item',
1443
        }
1444
    );
1445
}
1446
1447
=head3 libraries_where_can_edit_items
1448
1449
my $libraries = $patron->libraries_where_can_edit_items;
1450
1451
Return the list of branchcodes(!) of libraries the patron is allowed to items for.
1452
The branchcodes are arbitrarily returned sorted.
1453
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1454
1455
An empty array means no restriction, the user can edit any item.
1456
1457
=cut
1458
1459
sub libraries_where_can_edit_items {
1460
    my ($self) = @_;
1461
1462
    return $self->libraries_where_can_see_things(
1463
        {
1464
            permission    => 'editcatalogue',
1465
            subpermission => 'edit_any_item',
1466
            group_feature => 'ft_limit_item_editing',
1467
        }
1468
    );
1469
}
1470
1369
=head3 can_see_things_from
1471
=head3 can_see_things_from
1370
1472
1371
my $can_see = $thing->can_see_things_from( $branchcode );
1473
my $can_see = $thing->can_see_things_from( $branchcode );
1372
- 

Return to bug 20256