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

(-)a/Koha/Patron.pm (-25 / +102 lines)
Lines 1272-1277 sub can_see_patrons_from { Link Here
1272
    );
1272
    );
1273
}
1273
}
1274
1274
1275
=head3 libraries_where_can_see_patrons
1276
1277
my $libraries = $patron-libraries_where_can_see_patrons;
1278
1279
Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos.
1280
The branchcodes are arbitrarily returned sorted.
1281
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1282
1283
An empty array means no restriction, the patron can see patron's infos from any libraries.
1284
1285
=cut
1286
1287
sub libraries_where_can_see_patrons {
1288
    my ($self) = @_;
1289
1290
    return $self->libraries_where_can_see_things(
1291
        {
1292
            permission    => 'borrowers',
1293
            subpermission => 'view_borrower_infos_from_any_libraries',
1294
            group_feature => 'ft_hide_patron_info',
1295
        }
1296
    );
1297
}
1298
1299
=head3 can_edit_item
1300
1301
my $can_edit = $patron->can_edit_item( $item );
1302
1303
Return true if the patron (usually the logged in user) can edit the given item
1304
1305
The parameter can be a Koha::Item, an item hashref, or a branchcode.
1306
1307
=cut
1308
1309
sub can_edit_item {
1310
    my ( $self, $item ) = @_;
1311
1312
    my $userenv = C4::Context->userenv();
1313
1314
    my $ref = ref($item);
1315
1316
    my $branchcode =
1317
        $ref eq 'Koha::Item' ? $item->homebranch
1318
      : $ref eq 'HASH'       ? $item->{homebranch}
1319
      : $ref eq q{}          ? $item
1320
      :                        undef;
1321
1322
    return unless $branchcode;
1323
1324
    return 1 if C4::Context->IsSuperLibrarian();
1325
1326
    if ( C4::Context->preference('IndependentBranches') ) {
1327
        return $userenv->{branch} eq $branchcode;
1328
    }
1329
1330
    return $self->can_edit_items_from($branchcode);
1331
}
1332
1333
=head3 can_edit_items_from
1334
1335
my $can_edit = $patron->can_edit_items_from( $branchcode );
1336
1337
Return true if this user can edit items from the give home branchcode
1338
1339
=cut
1340
1341
sub can_edit_items_from {
1342
    my ( $self, $branchcode ) = @_;
1343
1344
    return $self->can_see_things_from(
1345
        {
1346
            branchcode    => $branchcode,
1347
            permission    => 'editcatalogue',
1348
            subpermission => 'edit_any_item',
1349
        }
1350
    );
1351
}
1352
1353
=head3 libraries_where_can_edit_items
1354
1355
my $libraries = $patron->libraries_where_can_edit_items;
1356
1357
Return the list of branchcodes(!) of libraries the patron is allowed to items for.
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 user can edit any item.
1362
1363
=cut
1364
1365
sub libraries_where_can_edit_items {
1366
    my ($self) = @_;
1367
1368
    return $self->libraries_where_can_see_things(
1369
        {
1370
            permission    => 'editcatalogue',
1371
            subpermission => 'edit_any_item',
1372
            group_feature => 'ft_limit_item_editing',
1373
        }
1374
    );
1375
}
1376
1275
=head3 can_see_things_from
1377
=head3 can_see_things_from
1276
1378
1277
my $can_see = $thing->can_see_things_from( $branchcode );
1379
my $can_see = $thing->can_see_things_from( $branchcode );
Lines 1302-1331 sub can_see_things_from { Link Here
1302
    return $can;
1404
    return $can;
1303
}
1405
}
1304
1406
1305
=head3 libraries_where_can_see_patrons
1306
1307
my $libraries = $patron-libraries_where_can_see_patrons;
1308
1309
Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos.
1310
The branchcodes are arbitrarily returned sorted.
1311
We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library)
1312
1313
An empty array means no restriction, the patron can see patron's infos from any libraries.
1314
1315
=cut
1316
1317
sub libraries_where_can_see_patrons {
1318
    my ($self) = @_;
1319
1320
    return $self->libraries_where_can_see_things(
1321
        {
1322
            permission    => 'borrowers',
1323
            subpermission => 'view_borrower_infos_from_any_libraries',
1324
            group_feature => 'ft_hide_patron_info',
1325
        }
1326
    );
1327
}
1328
1329
=head3 libraries_where_can_see_things
1407
=head3 libraries_where_can_see_things
1330
1408
1331
my $libraries = $thing-libraries_where_can_see_things;
1409
my $libraries = $thing-libraries_where_can_see_things;
1332
- 

Return to bug 20256