From 625ceab5a6a2938d283aea21f6efe6490d46c531 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 5 Dec 2019 06:32:25 -0500 Subject: [PATCH] Bug 20256: (QA follow-up) Filter out branchcodes the user has no permissions for Signed-off-by: Bob Bennhoff - CLiC --- cataloguing/additem.pl | 10 ++++++---- tools/batchMod.pl | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index e8cf90dfde..d5685062a1 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -107,8 +107,8 @@ sub _increment_barcode { sub generate_subfield_form { - my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $loop_data, $i, $restrictededition, $item) = @_; - + my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $loop_data, $i, $restrictededition, $item, $patron) = @_; + my $frameworkcode = &GetFrameworkCode($biblionumber); my %subfield_data; @@ -187,7 +187,9 @@ sub generate_subfield_form { } } elsif ( $subfieldlib->{authorised_value} eq "branches" ) { + my @allowed = $patron->libraries_where_can_edit_items; foreach my $thisbranch (@$branches) { + next unless any { /^$thisbranch->{branchcode}$/ } @allowed; push @authorised_values, $thisbranch->{branchcode}; $authorised_lib{$thisbranch->{branchcode}} = $thisbranch->{branchname}; $value = $thisbranch->{branchcode} if $thisbranch->{selected} && !$value; @@ -951,7 +953,7 @@ if($itemrecord){ next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10"); - my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item); + my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item, $patron); push @fields, "$tag$subfieldtag"; push (@loop_data, $subfield_data); $i++; @@ -975,7 +977,7 @@ foreach my $tag ( keys %{$tagslib}){ my @values = (undef); @values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)) && defined($itemrecord->field($tag)->subfield($subtag))); for my $value (@values){ - my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item); + my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item, $patron); push (@loop_data, $subfield_data); $i++; } diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 8e90e6bfc5..271faf954a 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -34,7 +34,7 @@ use C4::ClassSource; use C4::Debug; use C4::Members; use MARC::File::XML; -use List::MoreUtils qw/uniq/; +use List::MoreUtils qw( uniq any ); use Koha::Database; use Koha::Exceptions::Exception; @@ -412,6 +412,8 @@ my $allowAllSubfields = ( ) ? 1 : 0; my @subfieldsToAllow = split(/ /, $subfieldsToAllowForBatchmod); +my @allowed_to_edit_branches = $patron->libraries_where_can_edit_items; + foreach my $tag (sort keys %{$tagslib}) { # loop through each subfield foreach my $subfield (sort keys %{$tagslib->{$tag}}) { @@ -456,6 +458,7 @@ foreach my $tag (sort keys %{$tagslib}) { if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) { foreach my $library (@$libraries) { + next unless any { /^$library->{branchcode}$/ } @allowed_to_edit_branches; push @authorised_values, $library->{branchcode}; $authorised_lib{$library->{branchcode}} = $library->{branchname}; } -- 2.24.1 (Apple Git-126)