Bug 33070: Remove use of can_edit_items
Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Acquisition/Order.t
3) git grep "can_edit_item("
should return no results
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
5c3693bbd2
commit
6a2564a369
|
|
@ -296,7 +296,7 @@ sub safe_to_delete {
|
|||
$error //= "not_same_branch"
|
||||
if defined C4::Context->userenv
|
||||
and defined C4::Context->userenv->{number}
|
||||
and !Koha::Patrons->find( C4::Context->userenv->{number} )->can_edit_item( $self );
|
||||
and !Koha::Patrons->find( C4::Context->userenv->{number} )->can_edit_items_from( $self->homebranch );
|
||||
|
||||
# check it doesn't have a waiting reserve
|
||||
$error //= "book_reserved"
|
||||
|
|
|
|||
|
|
@ -1510,40 +1510,6 @@ sub can_see_patrons_from {
|
|||
);
|
||||
}
|
||||
|
||||
=head3 can_edit_item
|
||||
|
||||
my $can_edit = $patron->can_edit_item( $item );
|
||||
|
||||
Return true if the patron (usually the logged in user) can edit the given item
|
||||
|
||||
The parameter can be a Koha::Item, an item hashref, or a branchcode.
|
||||
|
||||
=cut
|
||||
|
||||
sub can_edit_item {
|
||||
my ( $self, $item ) = @_;
|
||||
|
||||
my $userenv = C4::Context->userenv();
|
||||
|
||||
my $ref = ref($item);
|
||||
|
||||
my $branchcode =
|
||||
$ref eq 'Koha::Item' ? $item->homebranch
|
||||
: $ref eq 'HASH' ? $item->{homebranch}
|
||||
: $ref eq q{} ? $item
|
||||
: undef;
|
||||
|
||||
return unless $branchcode;
|
||||
|
||||
return 1 if C4::Context->IsSuperLibrarian();
|
||||
|
||||
if ( $userenv && C4::Context->preference('IndependentBranches') ) {
|
||||
return $userenv->{branch} eq $branchcode;
|
||||
}
|
||||
|
||||
return $self->can_edit_items_from($branchcode);
|
||||
}
|
||||
|
||||
=head3 can_edit_items_from
|
||||
|
||||
my $can_edit = $patron->can_edit_items_from( $branchcode );
|
||||
|
|
@ -1555,6 +1521,13 @@ Return true if the I<Koha::Patron> can edit items from the given branchcode
|
|||
sub can_edit_items_from {
|
||||
my ( $self, $branchcode ) = @_;
|
||||
|
||||
return 1 if C4::Context->IsSuperLibrarian();
|
||||
|
||||
my $userenv = C4::Context->userenv();
|
||||
if ( $userenv && C4::Context->preference('IndependentBranches') ) {
|
||||
return $userenv->{branch} eq $branchcode;
|
||||
}
|
||||
|
||||
return $self->can_see_things_from(
|
||||
{
|
||||
branchcode => $branchcode,
|
||||
|
|
@ -1622,10 +1595,13 @@ Return true if the I<Koha::Patron> can perform some action on the given thing
|
|||
|
||||
sub can_see_things_from {
|
||||
my ( $self, $params ) = @_;
|
||||
|
||||
my $branchcode = $params->{branchcode};
|
||||
my $permission = $params->{permission};
|
||||
my $subpermission = $params->{subpermission};
|
||||
|
||||
return 1 if C4::Context->IsSuperLibrarian();
|
||||
|
||||
my $can = 0;
|
||||
if ( $self->branchcode eq $branchcode ) {
|
||||
$can = 1;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ sub build_table {
|
|||
holds => $item->biblio->holds->count,
|
||||
item_holds => $item->holds->count,
|
||||
is_checked_out => $item->checkout ? 1 : 0,
|
||||
nomod => $patron ? !$patron->can_edit_item($item) : 0,
|
||||
nomod => $patron ? !$patron->can_edit_items_from($item->homebranch) : 0,
|
||||
};
|
||||
push @items, $item_info;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ foreach my $item (@items) {
|
|||
$item_info->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $item->itemnumber );
|
||||
}
|
||||
|
||||
$item_info->{can_be_edited} = $patron->can_edit_item( $item );
|
||||
$item_info->{can_be_edited} = $patron->can_edit_items_from( $item->homebranch );
|
||||
|
||||
if ( C4::Context->preference("LocalCoverImages") == 1 ) {
|
||||
$item_info->{cover_images} = $item->cover_images;
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ foreach my $item (@items){
|
|||
}
|
||||
);
|
||||
|
||||
$item_info->{nomod} = !$patron->can_edit_item( $item );
|
||||
$item_info->{nomod} = !$patron->can_edit_items_from( $item->homebranch );
|
||||
|
||||
push @item_data, $item_info;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ my ($template, $loggedinuser, $cookie)
|
|||
my $patron = Koha::Patrons->find( $loggedinuser );
|
||||
|
||||
my $item = $itemnumber ? Koha::Items->find( $itemnumber ) : undef;
|
||||
if ( $item && !$patron->can_edit_item( $item ) ) {
|
||||
if ( $item && !$patron->can_edit_items_from( $item->homebranch ) ) {
|
||||
print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber");
|
||||
exit;
|
||||
}
|
||||
|
|
@ -635,7 +635,7 @@ if ($op) {
|
|||
my @items;
|
||||
for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) {
|
||||
my $i = $item->columns_to_str;
|
||||
$i->{nomod} = 1 unless $patron->can_edit_item($item);
|
||||
$i->{nomod} = 1 unless $patron->can_edit_items_from($item->homebranch);
|
||||
push @items, $i;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,6 @@
|
|||
"[% (item.issues || 0) | html %]",
|
||||
"[% IF item.checkout %][% item.checkout.date_due | $KohaDates %][% END %]",
|
||||
"[% FILTER escape_quotes ~%]
|
||||
<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>
|
||||
<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>
|
||||
[%~ END %]"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@
|
|||
|
||||
[% IF CAN_user_coursereserves_add_reserves || CAN_user_coursereserves_delete_reserves %]
|
||||
<td class="actions">
|
||||
[% IF CAN_user_coursereserves_add_reserves && user.can_edit_item( cr.item ) %]
|
||||
[% IF CAN_user_coursereserves_add_reserves && user.can_edit_items_from( cr.item.homebranch ) %]
|
||||
<a class="btn btn-default btn-xs" href="add_items.pl?course_id=[% course.course_id | html %]&itemnumber=[% cr.item.itemnumber | html %]&biblionumber=[% cr.biblio.biblionumber | html %]&action=lookup&return=[% course.course_id | html %]&is_edit=1"><i class="fa fa-pencil"></i> Edit</a>
|
||||
[% END %]
|
||||
|
||||
|
|
|
|||
|
|
@ -2460,7 +2460,7 @@ subtest 'filter_by_amount_owed' => sub {
|
|||
);
|
||||
};
|
||||
|
||||
subtest 'libraries_where_can_edit_items + can_edit_item' => sub {
|
||||
subtest 'libraries_where_can_edit_items() and can_edit_items_from() tests' => sub {
|
||||
plan tests => 2;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
|
@ -2520,18 +2520,18 @@ subtest 'libraries_where_can_edit_items + can_edit_item' => sub {
|
|||
is_deeply( \@branchcodes, [$library_2A->branchcode], "patron_2A doesn't have edit_any_item => Can only see patron's from its group" );
|
||||
};
|
||||
|
||||
subtest 'can_edit_item' => sub {
|
||||
subtest 'can_edit_items_from' => sub {
|
||||
plan tests => 6;
|
||||
|
||||
t::lib::Mocks::mock_userenv({ patron => $patron_1A_1 });
|
||||
is( $patron_1A_1->can_edit_item( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" );
|
||||
is( $patron_1A_1->can_edit_item( $library_1B->id ), 1, "patron_1A_1 can see patron_1B, from its group" );
|
||||
is( $patron_1A_1->can_edit_item( $library_2A->id ), 1, "patron_1A_1 can see patron_1A_2, from another group" );
|
||||
is( $patron_1A_1->can_edit_items_from( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" );
|
||||
is( $patron_1A_1->can_edit_items_from( $library_1B->id ), 1, "patron_1A_1 can see patron_1B, from its group" );
|
||||
is( $patron_1A_1->can_edit_items_from( $library_2A->id ), 1, "patron_1A_1 can see patron_1A_2, from another group" );
|
||||
|
||||
t::lib::Mocks::mock_userenv({ patron => $patron_1A_2 });
|
||||
is( $patron_1A_2->can_edit_item( $library_1A->id ), 1, "patron_1A_2 can see patron_1A_1, from its library" );
|
||||
is( $patron_1A_2->can_edit_item( $library_1B->id ), 1, "patron_1A_2 can see patron_1B, from its group" );
|
||||
is( $patron_1A_2->can_edit_item( $library_2A->id ), 0, "patron_1A_2 can NOT see patron_2A, from another group" );
|
||||
is( $patron_1A_2->can_edit_items_from( $library_1A->id ), 1, "patron_1A_2 can see patron_1A_1, from its library" );
|
||||
is( $patron_1A_2->can_edit_items_from( $library_1B->id ), 1, "patron_1A_2 can see patron_1B, from its group" );
|
||||
is( $patron_1A_2->can_edit_items_from( $library_2A->id ), 0, "patron_1A_2 can NOT see patron_2A, from another group" );
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue