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

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

Return to bug 20256