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

(-)a/Koha/Item.pm (-1 / +1 lines)
Lines 296-302 sub safe_to_delete { Link Here
296
    $error //= "not_same_branch"
296
    $error //= "not_same_branch"
297
      if defined C4::Context->userenv
297
      if defined C4::Context->userenv
298
      and defined C4::Context->userenv->{number}
298
      and defined C4::Context->userenv->{number}
299
      and !Koha::Patrons->find( C4::Context->userenv->{number} )->can_edit_item( $self );
299
      and !Koha::Patrons->find( C4::Context->userenv->{number} )->can_edit_items_from( $self->homebranch );
300
300
301
    # check it doesn't have a waiting reserve
301
    # check it doesn't have a waiting reserve
302
    $error //= "book_reserved"
302
    $error //= "book_reserved"
(-)a/Koha/Patron.pm (-33 / +9 lines)
Lines 1510-1560 sub can_see_patrons_from { Link Here
1510
    );
1510
    );
1511
}
1511
}
1512
1512
1513
=head3 can_edit_item
1513
=head3 can_edit_items_from
1514
1515
my $can_edit = $patron->can_edit_item( $item );
1516
1514
1517
Return true if the patron (usually the logged in user) can edit the given item
1515
    my $can_edit = $patron->can_edit_items_from( $branchcode );
1518
1516
1519
The parameter can be a Koha::Item, an item hashref, or a branchcode.
1517
Return true if the I<Koha::Patron> can edit items from the given branchcode
1520
1518
1521
=cut
1519
=cut
1522
1520
1523
sub can_edit_item {
1521
sub can_edit_items_from {
1524
    my ( $self, $item ) = @_;
1522
    my ( $self, $branchcode ) = @_;
1525
1526
    my $userenv = C4::Context->userenv();
1527
1528
    my $ref = ref($item);
1529
1530
    my $branchcode =
1531
        $ref eq 'Koha::Item' ? $item->homebranch
1532
      : $ref eq 'HASH'       ? $item->{homebranch}
1533
      : $ref eq q{}          ? $item
1534
      :                        undef;
1535
1536
    return unless $branchcode;
1537
1523
1538
    return 1 if C4::Context->IsSuperLibrarian();
1524
    return 1 if C4::Context->IsSuperLibrarian();
1539
1525
1526
    my $userenv = C4::Context->userenv();
1540
    if ( $userenv && C4::Context->preference('IndependentBranches') ) {
1527
    if ( $userenv && C4::Context->preference('IndependentBranches') ) {
1541
        return $userenv->{branch} eq $branchcode;
1528
        return $userenv->{branch} eq $branchcode;
1542
    }
1529
    }
1543
1530
1544
    return $self->can_edit_items_from($branchcode);
1545
}
1546
1547
=head3 can_edit_items_from
1548
1549
    my $can_edit = $patron->can_edit_items_from( $branchcode );
1550
1551
Return true if the I<Koha::Patron> can edit items from the given branchcode
1552
1553
=cut
1554
1555
sub can_edit_items_from {
1556
    my ( $self, $branchcode ) = @_;
1557
1558
    return $self->can_see_things_from(
1531
    return $self->can_see_things_from(
1559
        {
1532
        {
1560
            branchcode    => $branchcode,
1533
            branchcode    => $branchcode,
Lines 1622-1631 Return true if the I<Koha::Patron> can perform some action on the given thing Link Here
1622
1595
1623
sub can_see_things_from {
1596
sub can_see_things_from {
1624
    my ( $self, $params ) = @_;
1597
    my ( $self, $params ) = @_;
1598
1625
    my $branchcode    = $params->{branchcode};
1599
    my $branchcode    = $params->{branchcode};
1626
    my $permission    = $params->{permission};
1600
    my $permission    = $params->{permission};
1627
    my $subpermission = $params->{subpermission};
1601
    my $subpermission = $params->{subpermission};
1628
1602
1603
    return 1 if C4::Context->IsSuperLibrarian();
1604
1629
    my $can = 0;
1605
    my $can = 0;
1630
    if ( $self->branchcode eq $branchcode ) {
1606
    if ( $self->branchcode eq $branchcode ) {
1631
        $can = 1;
1607
        $can = 1;
(-)a/Koha/UI/Table/Builder/Items.pm (-1 / +1 lines)
Lines 89-95 sub build_table { Link Here
89
            holds          => $item->biblio->holds->count,
89
            holds          => $item->biblio->holds->count,
90
            item_holds     => $item->holds->count,
90
            item_holds     => $item->holds->count,
91
            is_checked_out => $item->checkout ? 1 : 0,
91
            is_checked_out => $item->checkout ? 1 : 0,
92
            nomod          => $patron ? !$patron->can_edit_item($item) : 0,
92
            nomod          => $patron ? !$patron->can_edit_items_from($item->homebranch) : 0,
93
        };
93
        };
94
        push @items, $item_info;
94
        push @items, $item_info;
95
    }
95
    }
(-)a/catalogue/detail.pl (-1 / +1 lines)
Lines 442-448 foreach my $item (@items) { Link Here
442
        $item_info->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $item->itemnumber );
442
        $item_info->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $item->itemnumber );
443
    }
443
    }
444
444
445
    $item_info->{can_be_edited} = $patron->can_edit_item( $item );
445
    $item_info->{can_be_edited} = $patron->can_edit_items_from( $item->homebranch );
446
446
447
    if ( C4::Context->preference("LocalCoverImages") == 1 ) {
447
    if ( C4::Context->preference("LocalCoverImages") == 1 ) {
448
        $item_info->{cover_images} = $item->cover_images;
448
        $item_info->{cover_images} = $item->cover_images;
(-)a/catalogue/moredetail.pl (-1 / +1 lines)
Lines 247-253 foreach my $item (@items){ Link Here
247
        }
247
        }
248
    );
248
    );
249
249
250
    $item_info->{nomod} = !$patron->can_edit_item( $item );
250
    $item_info->{nomod} = !$patron->can_edit_items_from( $item->homebranch );
251
251
252
    push @item_data, $item_info;
252
    push @item_data, $item_info;
253
}
253
}
(-)a/cataloguing/additem.pl (-2 / +2 lines)
Lines 161-167 my ($template, $loggedinuser, $cookie) Link Here
161
my $patron = Koha::Patrons->find( $loggedinuser );
161
my $patron = Koha::Patrons->find( $loggedinuser );
162
162
163
my $item = $itemnumber ? Koha::Items->find( $itemnumber ) : undef;
163
my $item = $itemnumber ? Koha::Items->find( $itemnumber ) : undef;
164
if ( $item && !$patron->can_edit_item( $item ) ) {
164
if ( $item && !$patron->can_edit_items_from( $item->homebranch ) ) {
165
    print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber");
165
    print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber");
166
    exit;
166
    exit;
167
}
167
}
Lines 635-641 if ($op) { Link Here
635
my @items;
635
my @items;
636
for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) {
636
for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) {
637
    my $i = $item->columns_to_str;
637
    my $i = $item->columns_to_str;
638
    $i->{nomod} = 1 unless $patron->can_edit_item($item);
638
    $i->{nomod} = 1 unless $patron->can_edit_items_from($item->homebranch);
639
    push @items, $i;
639
    push @items, $i;
640
}
640
}
641
641
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc (-1 / +1 lines)
Lines 32-37 Link Here
32
  "[% (item.issues || 0) | html %]",
32
  "[% (item.issues || 0) | html %]",
33
  "[% IF item.checkout %][% item.checkout.date_due | $KohaDates %][% END %]",
33
  "[% IF item.checkout %][% item.checkout.date_due | $KohaDates %][% END %]",
34
  "[% FILTER escape_quotes ~%]
34
  "[% FILTER escape_quotes ~%]
35
    <div class="btn-group dropup"><button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fa fa-pencil"></i> Edit <span class="caret"></span> </button> <ul class="dropdown-menu pull-right"> [% IF user.can_edit_item( item ) %]<li><a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=[% item.biblionumber | uri %]&itemnumber=[% item.itemnumber | uri %]">Edit item</a></li>[% END %] <li><a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% item.biblionumber | html %]">Edit record</a></li> </ul> </div>
35
    <div class="btn-group dropup"><button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fa fa-pencil"></i> Edit <span class="caret"></span> </button> <ul class="dropdown-menu pull-right"> [% IF user.can_edit_items_from( item.homebranch ) %]<li><a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=[% item.biblionumber | uri %]&itemnumber=[% item.itemnumber | uri %]">Edit item</a></li>[% END %] <li><a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% item.biblionumber | html %]">Edit record</a></li> </ul> </div>
36
  [%~ END %]"
36
  [%~ END %]"
37
]
37
]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt (-1 / +1 lines)
Lines 294-300 Link Here
294
294
295
                                    [% IF CAN_user_coursereserves_add_reserves || CAN_user_coursereserves_delete_reserves %]
295
                                    [% IF CAN_user_coursereserves_add_reserves || CAN_user_coursereserves_delete_reserves %]
296
                                        <td class="actions">
296
                                        <td class="actions">
297
                                            [% IF CAN_user_coursereserves_add_reserves && user.can_edit_item( cr.item ) %]
297
                                            [% IF CAN_user_coursereserves_add_reserves && user.can_edit_items_from( cr.item.homebranch ) %]
298
                                                <a class="btn btn-default btn-xs" href="add_items.pl?course_id=[% course.course_id | html %]&amp;itemnumber=[% cr.item.itemnumber | html %]&amp;biblionumber=[% cr.biblio.biblionumber | html %]&amp;action=lookup&amp;return=[% course.course_id | html %]&amp;is_edit=1"><i class="fa fa-pencil"></i> Edit</a>
298
                                                <a class="btn btn-default btn-xs" href="add_items.pl?course_id=[% course.course_id | html %]&amp;itemnumber=[% cr.item.itemnumber | html %]&amp;biblionumber=[% cr.biblio.biblionumber | html %]&amp;action=lookup&amp;return=[% course.course_id | html %]&amp;is_edit=1"><i class="fa fa-pencil"></i> Edit</a>
299
                                            [% END %]
299
                                            [% END %]
300
300
(-)a/t/db_dependent/Koha/Patrons.t (-9 / +8 lines)
Lines 2460-2466 subtest 'filter_by_amount_owed' => sub { Link Here
2460
    );
2460
    );
2461
};
2461
};
2462
2462
2463
subtest 'libraries_where_can_edit_items + can_edit_item' => sub {
2463
subtest 'libraries_where_can_edit_items() and can_edit_items_from() tests' => sub {
2464
    plan tests => 2;
2464
    plan tests => 2;
2465
2465
2466
    $schema->storage->txn_begin;
2466
    $schema->storage->txn_begin;
Lines 2520-2537 subtest 'libraries_where_can_edit_items + can_edit_item' => sub { Link Here
2520
        is_deeply( \@branchcodes, [$library_2A->branchcode], "patron_2A doesn't have edit_any_item => Can only see patron's from its group" );
2520
        is_deeply( \@branchcodes, [$library_2A->branchcode], "patron_2A doesn't have edit_any_item => Can only see patron's from its group" );
2521
    };
2521
    };
2522
2522
2523
    subtest 'can_edit_item' => sub {
2523
    subtest 'can_edit_items_from' => sub {
2524
        plan tests => 6;
2524
        plan tests => 6;
2525
2525
2526
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_1 });
2526
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_1 });
2527
        is( $patron_1A_1->can_edit_item( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" );
2527
        is( $patron_1A_1->can_edit_items_from( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" );
2528
        is( $patron_1A_1->can_edit_item( $library_1B->id ),   1, "patron_1A_1 can see patron_1B, from its group" );
2528
        is( $patron_1A_1->can_edit_items_from( $library_1B->id ),   1, "patron_1A_1 can see patron_1B, from its group" );
2529
        is( $patron_1A_1->can_edit_item( $library_2A->id ),   1, "patron_1A_1 can see patron_1A_2, from another group" );
2529
        is( $patron_1A_1->can_edit_items_from( $library_2A->id ),   1, "patron_1A_1 can see patron_1A_2, from another group" );
2530
2530
2531
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_2 });
2531
        t::lib::Mocks::mock_userenv({ patron => $patron_1A_2 });
2532
        is( $patron_1A_2->can_edit_item( $library_1A->id ),   1, "patron_1A_2 can see patron_1A_1, from its library" );
2532
        is( $patron_1A_2->can_edit_items_from( $library_1A->id ),   1, "patron_1A_2 can see patron_1A_1, from its library" );
2533
        is( $patron_1A_2->can_edit_item( $library_1B->id ),   1, "patron_1A_2 can see patron_1B, from its group" );
2533
        is( $patron_1A_2->can_edit_items_from( $library_1B->id ),   1, "patron_1A_2 can see patron_1B, from its group" );
2534
        is( $patron_1A_2->can_edit_item( $library_2A->id ),   0, "patron_1A_2 can NOT see patron_2A, from another group" );
2534
        is( $patron_1A_2->can_edit_items_from( $library_2A->id ),   0, "patron_1A_2 can NOT see patron_2A, from another group" );
2535
    };
2535
    };
2536
};
2536
};
2537
2537
2538
- 

Return to bug 33070