From 8a5b7833f9233ccd10f776cc8ccf4455c1456a79 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 --- C4/Items.pm | 4 +--- catalogue/detail.pl | 8 +------- catalogue/moredetail.pl | 9 ++------- cataloguing/additem.pl | 13 +++++++++---- .../prog/en/modules/catalogue/detail.tt | 4 +++- tools/batchMod.pl | 19 ++++++++----------- 6 files changed, 24 insertions(+), 33 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 547d8358c9..75401c535a 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1743,9 +1743,7 @@ sub ItemSafeToDelete { $status = "book_on_loan"; } elsif ( defined C4::Context->userenv - and !C4::Context->IsSuperLibrarian() - and C4::Context->preference("IndependentBranches") - and ( C4::Context->userenv->{branch} ne $item->homebranch ) ) + and !Koha::Patrons->find( C4::Context->userenv->{number} )->can_edit_item( $item ) ) { $status = "not_same_branch"; } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 27eb2787ce..56610d7ff2 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -340,13 +340,7 @@ foreach my $item (@items) { $item->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $item->{'itemnumber'} ); } - if ( C4::Context->preference('IndependentBranches') ) { - my $userenv = C4::Context->userenv(); - if ( not C4::Context->IsSuperLibrarian() - and $userenv->{branch} ne $item->{homebranch} ) { - $item->{cannot_be_edited} = 1; - } - } + $item->{cannot_be_edited} = !$patron->can_edit_item( $item_object ); if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET" and C4::Context->preference('SeparateHoldings')) { diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index e8736ff398..5984f50a1d 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -174,13 +174,8 @@ foreach my $item (@items){ $item->{status_advisory} = 1; } - if (C4::Context->preference("IndependentBranches")) { - #verifying rights - my $userenv = C4::Context->userenv(); - unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) { - $item->{'nomod'}=1; - } - } + $item->{nomod} = !$patron->can_edit_item( $item ); + if ($item->{'datedue'}) { $item->{'issue'}= 1; } else { diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 7b6d5e4033..ec5fa70a46 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -412,7 +412,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()); @@ -794,13 +795,17 @@ foreach my $field (@fields) { || $subfieldvalue; } - if (($field->tag eq $branchtagfield) && ($subfieldcode eq $branchtagsubfield) && C4::Context->preference("IndependentBranches")) { + if ( $subfieldvalue + && ( $field->tag eq $branchtagfield ) + && ( $subfieldcode eq $branchtagsubfield ) ) + { #verifying rights - my $userenv = C4::Context->userenv(); - unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $subfieldvalue))){ + unless ( $patron->can_edit_item($subfieldvalue) ) { + warn "NOMOD"; $this_row{'nomod'} = 1; } } + $this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield); if ( C4::Context->preference('EasyAnalyticalRecords') ) { 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 fe0188b43d..e99d232c36 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -380,7 +380,9 @@ [% IF (StaffDetailItemSelection) %] - + [% UNLESS item.cannot_be_edited %] + + [% END %] [% END %] [% IF ( item_level_itypes ) %] diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 8f028c2225..d5c6e2655f 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -75,7 +75,8 @@ my ($template, $loggedinuser, $cookie) }); # 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()); @@ -532,21 +533,17 @@ sub BuildItemsData{ my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", ""); my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", ""); foreach my $itemnumber (@itemnumbers){ - my $itemdata = Koha::Items->find($itemnumber); - next unless $itemdata; # Should have been tested earlier, but just in case... - $itemdata = $itemdata->unblessed; + my $item = Koha::Items->find($itemnumber); + next unless $item; # Should have been tested earlier, but just in case... + my $itemdata = $item->unblessed; my $itemmarc=Item2Marc($itemdata); my %this_row; foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) { # loop through each subfield my $itembranchcode=$field->subfield($branchtagsubfield); - if ($itembranchcode && C4::Context->preference("IndependentBranches")) { - #verifying rights - my $userenv = C4::Context->userenv(); - unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $itembranchcode))){ - $this_row{'nomod'}=1; - } - } + if ($itembranchcode) { + $this_row{'nomod'} = !$patron->can_edit_item($item); + } my $tag=$field->tag(); foreach my $subfield ($field->subfields) { my ($subfcode,$subfvalue)=@$subfield; -- 2.20.1 (Apple Git-117)