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

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

Return to bug 20256