From 5800f628ae3e68119290212eab727e4a973e6d3c Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 28 Mar 2019 11:07:02 -0400 Subject: [PATCH] Bug 20256: Use new methods Signed-off-by: Bob Bennhoff - CLiC Signed-off-by: Martin Renvoize --- Koha/Item.pm | 4 +--- Koha/UI/Table/Builder/Items.pm | 5 +++++ catalogue/detail.pl | 2 ++ catalogue/moredetail.pl | 9 ++------- cataloguing/additem.pl | 5 ++++- .../intranet-tmpl/prog/en/includes/html_helpers.inc | 2 +- .../intranet-tmpl/prog/en/modules/catalogue/detail.tt | 4 +++- tools/batchMod.pl | 5 +++-- 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 3ef1e04194..c976de46c8 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -294,9 +294,7 @@ sub safe_to_delete { $error = "not_same_branch" if defined C4::Context->userenv - and !C4::Context->IsSuperLibrarian() - and C4::Context->preference("IndependentBranches") - and ( C4::Context->userenv->{branch} ne $self->homebranch ); + and !Koha::Patrons->find( C4::Context->userenv->{number} )->can_edit_item( $self ) ) # check it doesn't have a waiting reserve $error = "book_reserved" diff --git a/Koha/UI/Table/Builder/Items.pm b/Koha/UI/Table/Builder/Items.pm index 615d210871..5706321990 100644 --- a/Koha/UI/Table/Builder/Items.pm +++ b/Koha/UI/Table/Builder/Items.pm @@ -71,7 +71,11 @@ Use it with: sub build_table { my ( $self, $params ) = @_; + + my $patron = $self->params; + my %itemnumbers_to_idx = map { $self->{itemnumbers}->[$_] => $_ } 0..$#{$self->{itemnumbers}}; + my $items = Koha::Items->search( { itemnumber => $self->{itemnumbers} } ); my @items; @@ -85,6 +89,7 @@ sub build_table { holds => $item->biblio->holds->count, item_holds => $item->holds->count, is_checked_out => $item->checkout || 0, + nomod => $patron ? 0 : $patron->can_edit_item($item), }; push @items, $item_info; } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 5cb556ae05..c1cefeeab6 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -442,6 +442,8 @@ foreach my $item (@items) { $item_info->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $item->itemnumber ); } + $item->{cannot_be_edited} = !$patron->can_edit_item( $item_object ); + if ( C4::Context->preference("LocalCoverImages") == 1 ) { $item_info->{cover_images} = $item->cover_images; } diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 90f2de0b07..ca5d3729fd 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -228,13 +228,8 @@ foreach my $item (@items){ } } - if (C4::Context->preference("IndependentBranches")) { - #verifying rights - my $userenv = C4::Context->userenv(); - unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->homebranch)) { - $item_info->{'nomod'}=1; - } - } + $item_data->{nomod} = !$patron->can_edit_item( $item ); + push @item_data, $item_info; } diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index c722f60201..1d19b69fed 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -155,7 +155,8 @@ my ($template, $loggedinuser, $cookie) # Does the user have a restricted item editing permission? -my $uid = Koha::Patrons->find( $loggedinuser )->userid; +my $patron = Koha::Patrons->find( $loggedinuser ); +my $uid = $patron->userid; my $restrictededition = $uid ? haspermission($uid, {'editcatalogue' => 'edit_items_restricted'}) : undef; # In case user is a superlibrarian, editing is not restricted $restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibrarian()); @@ -554,6 +555,8 @@ if ($op) { my @items; for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) { + my $i = $item->columns_to_str; + $item->{nomod} = 1 unless $patron->can_edit_item($item); push @items, $item->columns_to_str; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc index 237500bf7a..4fa697f1ad 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -262,7 +262,7 @@ [% FOREACH item IN items %] - [% SET can_be_edited = ! ( Koha.Preference('IndependentBranches') && ! logged_in_user.is_superlibrarian && item.homebranch != Branches.GetLoggedInBranchname() ) %] + [% SET can_be_edited = !item.nomod && !( Koha.Preference('IndependentBranches') && ! logged_in_user && item.homebranch != Branches.GetLoggedInBranchname() ) %] [% item.index + 1 | html %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index be4b5dcfa5..7140d2a09a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -381,7 +381,9 @@ [% IF (StaffDetailItemSelection) %] - + [% UNLESS item.cannot_be_edited %] + + [% END %] [% END %] [% IF Koha.Preference('LocalCoverImages') && ( tab == 'holdings' && itemloop_has_images || tab == 'otherholdings' && otheritemloop_has_images ) %] diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 31a61b7046..27830f505c 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -74,7 +74,8 @@ my ($template, $loggedinuser, $cookie) $template->param( searchid => scalar $input->param('searchid'), ); # Does the user have a restricted item edition permission? -my $uid = $loggedinuser ? Koha::Patrons->find( $loggedinuser )->userid : undef; +my $patron = Koha::Patrons->find( $loggedinuser ); +my $uid = $loggedinuser ? $patron->userid : undef; my $restrictededition = $uid ? haspermission($uid, {'tools' => 'items_batchmod_restricted'}) : undef; # In case user is a superlibrarian, edition is not restricted $restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibrarian()); @@ -292,7 +293,7 @@ if ($op eq "show"){ if ( $display_items ) { my $items_table = Koha::UI::Table::Builder::Items->new( { itemnumbers => \@itemnumbers } ) - ->build_table; + ->build_table( { patron => $patron } );; $template->param( items => $items_table->{items}, item_header_loop => $items_table->{headers}, -- 2.30.2