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

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

Return to bug 20256