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

(-)a/Koha/Patron.pm (-25 / +102 lines)
Lines 1290-1295 sub can_see_patrons_from { Link Here
1290
    );
1290
    );
1291
}
1291
}
1292
1292
1293
=head3 libraries_where_can_see_patrons
1294
1295
my $libraries = $patron-libraries_where_can_see_patrons;
1296
1297
Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos.
1298
The branchcodes are arbitrarily returned sorted.
1299
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1300
1301
An empty array means no restriction, the patron can see patron's infos from any libraries.
1302
1303
=cut
1304
1305
sub libraries_where_can_see_patrons {
1306
    my ($self) = @_;
1307
1308
    return $self->libraries_where_can_see_things(
1309
        {
1310
            permission    => 'borrowers',
1311
            subpermission => 'view_borrower_infos_from_any_libraries',
1312
            group_feature => 'ft_hide_patron_info',
1313
        }
1314
    );
1315
}
1316
1317
=head3 can_edit_item
1318
1319
my $can_edit = $patron->can_edit_item( $item );
1320
1321
Return true if the patron (usually the logged in user) can edit the given item
1322
1323
The parameter can be a Koha::Item, an item hashref, or a branchcode.
1324
1325
=cut
1326
1327
sub can_edit_item {
1328
    my ( $self, $item ) = @_;
1329
1330
    my $userenv = C4::Context->userenv();
1331
1332
    my $ref = ref($item);
1333
1334
    my $branchcode =
1335
        $ref eq 'Koha::Item' ? $item->homebranch
1336
      : $ref eq 'HASH'       ? $item->{homebranch}
1337
      : $ref eq q{}          ? $item
1338
      :                        undef;
1339
1340
    return unless $branchcode;
1341
1342
    return 1 if C4::Context->IsSuperLibrarian();
1343
1344
    if ( C4::Context->preference('IndependentBranches') ) {
1345
        return $userenv->{branch} eq $branchcode;
1346
    }
1347
1348
    return $self->can_edit_items_from($branchcode);
1349
}
1350
1351
=head3 can_edit_items_from
1352
1353
my $can_edit = $patron->can_edit_items_from( $branchcode );
1354
1355
Return true if this user can edit items from the give home branchcode
1356
1357
=cut
1358
1359
sub can_edit_items_from {
1360
    my ( $self, $branchcode ) = @_;
1361
1362
    return $self->can_see_things_from(
1363
        {
1364
            branchcode    => $branchcode,
1365
            permission    => 'editcatalogue',
1366
            subpermission => 'edit_any_item',
1367
        }
1368
    );
1369
}
1370
1371
=head3 libraries_where_can_edit_items
1372
1373
my $libraries = $patron->libraries_where_can_edit_items;
1374
1375
Return the list of branchcodes(!) of libraries the patron is allowed to items for.
1376
The branchcodes are arbitrarily returned sorted.
1377
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1378
1379
An empty array means no restriction, the user can edit any item.
1380
1381
=cut
1382
1383
sub libraries_where_can_edit_items {
1384
    my ($self) = @_;
1385
1386
    return $self->libraries_where_can_see_things(
1387
        {
1388
            permission    => 'editcatalogue',
1389
            subpermission => 'edit_any_item',
1390
            group_feature => 'ft_limit_item_editing',
1391
        }
1392
    );
1393
}
1394
1293
=head3 can_see_things_from
1395
=head3 can_see_things_from
1294
1396
1295
my $can_see = $thing->can_see_things_from( $branchcode );
1397
my $can_see = $thing->can_see_things_from( $branchcode );
Lines 1320-1349 sub can_see_things_from { Link Here
1320
    return $can;
1422
    return $can;
1321
}
1423
}
1322
1424
1323
=head3 libraries_where_can_see_patrons
1324
1325
my $libraries = $patron-libraries_where_can_see_patrons;
1326
1327
Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos.
1328
The branchcodes are arbitrarily returned sorted.
1329
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1330
1331
An empty array means no restriction, the patron can see patron's infos from any libraries.
1332
1333
=cut
1334
1335
sub libraries_where_can_see_patrons {
1336
    my ($self) = @_;
1337
1338
    return $self->libraries_where_can_see_things(
1339
        {
1340
            permission    => 'borrowers',
1341
            subpermission => 'view_borrower_infos_from_any_libraries',
1342
            group_feature => 'ft_hide_patron_info',
1343
        }
1344
    );
1345
}
1346
1347
=head3 libraries_where_can_see_things
1425
=head3 libraries_where_can_see_things
1348
1426
1349
my $libraries = $thing-libraries_where_can_see_things;
1427
my $libraries = $thing-libraries_where_can_see_things;
1350
- 

Return to bug 20256