From 32489127ad0361768729aa41900da9bbc476ef43 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 | 5 ++-- Koha/Patron.pm | 30 ++----------------- Koha/UI/Table/Builder/Items.pm | 5 ++++ catalogue/detail.pl | 2 ++ catalogue/itemsearch.pl | 7 +++-- catalogue/moredetail.pl | 9 ++---- cataloguing/additem.pl | 14 +++++++-- course_reserves/course-details.pl | 1 + .../catalogue/itemsearch_item.json.inc | 2 +- .../prog/en/includes/html_helpers.inc | 2 +- .../prog/en/includes/permissions.inc | 4 +-- .../prog/en/modules/admin/library_groups.tt | 2 +- .../prog/en/modules/catalogue/detail.tt | 6 ++-- .../en/modules/catalogue/itemsearch_json.tt | 2 +- .../prog/en/modules/cataloguing/additem.tt | 4 +++ .../modules/course_reserves/course-details.tt | 3 +- tools/batchMod.pl | 5 ++-- 17 files changed, 49 insertions(+), 54 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index dae9df8f29..7d3d27a994 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -295,9 +295,8 @@ sub safe_to_delete { $error //= "not_same_branch" if defined C4::Context->userenv - && !C4::Context->IsSuperLibrarian() - && C4::Context->preference("IndependentBranches") - && ( C4::Context->userenv->{branch} ne $self->homebranch ); + and defined C4::Context->userenv->{number} + 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/Patron.pm b/Koha/Patron.pm index 354040586a..e3a302d553 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1496,7 +1496,7 @@ sub can_see_patrons_from { =head3 libraries_where_can_see_patrons -my $libraries = $patron-libraries_where_can_see_patrons; +my $libraries = $patron->libraries_where_can_see_patrons; Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos. The branchcodes are arbitrarily returned sorted. @@ -1545,7 +1545,7 @@ sub can_edit_item { return 1 if C4::Context->IsSuperLibrarian(); - if ( C4::Context->preference('IndependentBranches') ) { + if ( $userenv && C4::Context->preference('IndependentBranches') ) { return $userenv->{branch} eq $branchcode; } @@ -1653,35 +1653,11 @@ sub can_log_into { return $can; } -=head3 libraries_where_can_see_patrons - -my $libraries = $patron-libraries_where_can_see_patrons; - -Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos. -The branchcodes are arbitrarily returned sorted. -We are supposing here that the object is related to the logged in patron (use of C4::Context::only_my_library) - -An empty array means no restriction, the patron can see patron's infos from any libraries. - -=cut - -sub libraries_where_can_see_patrons { - my ($self) = @_; - - return $self->libraries_where_can_see_things( - { - permission => 'borrowers', - subpermission => 'view_borrower_infos_from_any_libraries', - group_feature => 'ft_hide_patron_info', - } - ); -} - =head3 libraries_where_can_see_things my $libraries = $thing-libraries_where_can_see_things; -Returns a list of libraries where an aribitarary action is allowd to be taken by the logged in librarian +Returns a list of libraries where an aribitarary action is allowed to be taken by the logged in librarian against an object based on some branchcode related to the object ( patron branchcode, item homebranch, etc ). We are supposing here that the object is related to the logged in librarian (use of C4::Context::only_my_library) diff --git a/Koha/UI/Table/Builder/Items.pm b/Koha/UI/Table/Builder/Items.pm index 615d210871..5914339c12 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 = $params->{patron}; + 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 ? !$patron->can_edit_item($item) : 0, }; push @items, $item_info; } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index c7908bc969..1018f21a5d 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->{can_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/itemsearch.pl b/catalogue/itemsearch.pl index e18524307c..72074a8fdf 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -251,10 +251,11 @@ if ( defined $format ) { } $template->param( - filter => $filter, + filter => $filter, search_params => $search_params, - results => $results, - total_rows => $total_rows, + results => $results, + total_rows => $total_rows, + user => Koha::Patrons->find( $borrowernumber ), ); if ($format eq 'csv') { 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 ed31390663..586f89cd62 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -158,7 +158,15 @@ 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 $item = $itemnumber ? Koha::Items->find( $itemnumber ) : undef; +if ( $item && !$patron->can_edit_item( $item ) ) { + print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber"); + exit; +} + +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()); @@ -626,7 +634,9 @@ if ($op) { my @items; for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) { - push @items, $item->columns_to_str; + my $i = $item->columns_to_str; + $i->{nomod} = 1 unless $patron->can_edit_item($item); + push @items, $i; } my @witness_attributes = uniq map { diff --git a/course_reserves/course-details.pl b/course_reserves/course-details.pl index e5c7efe5b2..c5d74f950e 100755 --- a/course_reserves/course-details.pl +++ b/course_reserves/course-details.pl @@ -66,6 +66,7 @@ my $course_reserves = GetCourseReserves( $template->param( course => $course, course_reserves => $course_reserves, + user => Koha::Patrons->find( $loggedinuser ), ); output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc index 5d30c08a9b..39e95ac8fe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc @@ -32,6 +32,6 @@ "[% (item.issues || 0) | html %]", "[% IF item.checkout %][% item.checkout.date_due | $KohaDates %][% END %]", "[% FILTER escape_quotes ~%] - +
[%~ END %]" ] 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 52d645f255..dd8682a2b7 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/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc index a406d68d4a..a8bfd89e02 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -343,12 +343,12 @@ ([% name | html %]) [%- CASE 'edit_items' -%] - Edit items + Edit items (not including items restricted by library group) ([% name | html %]) [%- CASE 'edit_any_item' -%] - Edit any item. If not set the logged in user can only edit items whose home library matches the logged in library. + Edit any item including items that would otherwise be restricted ([% name | html %]) [%- CASE 'edit_items_restricted' -%] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt index 7b631bd593..49dba189b9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt @@ -420,7 +420,7 @@
  • Hide patron's info for librarians outside of this group.
  • [% END %] [% IF group.ft_limit_item_editing %] -
  • Limit item editing for librarians outside of this group.
  • +
  • Limit item editing to librarians inside of this group.
  • [% END %] [% IF group.ft_search_groups_opac %]
  • Use for OPAC search groups
  • 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 ace46656c9..59a704cc9f 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) %] - + [% IF item.can_be_edited %] + + [% END %] [% END %] [% IF Koha.Preference('LocalCoverImages') && ( tab == 'holdings' && itemloop_has_images || tab == 'otherholdings' && otheritemloop_has_images ) %] @@ -638,7 +640,7 @@ Note that permanent location is a code, and location may be an authval. [% IF CAN_user_editcatalogue_edit_items %] - [% UNLESS item.cannot_be_edited %] + [% IF item.can_be_edited %] [% IF Koha.Preference('LocalCoverImages') OR Koha.Preference('OPACLocalCoverImages') %]
    Edit diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch_json.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch_json.tt index 3c7b17d61b..3d46ae4708 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch_json.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch_json.tt @@ -4,7 +4,7 @@ "iTotalDisplayRecords": [% total_rows | html %], "aaData": [ [%- FOREACH item IN results -%] - [%- INCLUDE 'catalogue/itemsearch_item.json.inc' item = item -%] + [%- INCLUDE 'catalogue/itemsearch_item.json.inc' item = item, user = user -%] [%- UNLESS loop.last %],[% END -%] [%- END -%] ] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index e9a512c60e..aef2909b86 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -115,10 +115,14 @@ [% IF item.biblionumber != biblio.biblionumber %] [%# Host item %]
  • Edit in host   Delink
  • [% ELSE %] + [% UNLESS item.nomod %]
  • Edit
  • + [% END %]
  • Duplicate
  • + [% UNLESS item.nomod %]
  • Delete
  • + [% END %] [% END %] [% IF ( OPACBaseURL ) %]
  • OPAC view
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt index 36abc1d196..623974a4f3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt @@ -294,7 +294,7 @@ [% IF CAN_user_coursereserves_add_reserves || CAN_user_coursereserves_delete_reserves %] - [% IF CAN_user_coursereserves_add_reserves %] + [% IF CAN_user_coursereserves_add_reserves && user.can_edit_item( cr.item ) %] Edit [% END %] @@ -304,7 +304,6 @@ [% END %] [% END %] - [% END %] 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