From 65c2f9b417f11694e02233fc776330df640a74e0 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 --- cataloguing/additem.pl | 8 +++++--- tools/batchMod.pl | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index c0c741774e..0870ae4857 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -107,7 +107,7 @@ sub _increment_barcode { sub generate_subfield_form { - my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $loop_data, $i, $restrictededition) = @_; + my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $loop_data, $i, $restrictededition, $patron) = @_; my $frameworkcode = &GetFrameworkCode($biblionumber); @@ -171,7 +171,9 @@ sub generate_subfield_form { my %authorised_lib; # builds list, depending on authorised value... if ( $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; @@ -927,7 +929,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); + my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $patron); push @fields, "$tag$subfieldtag"; push (@loop_data, $subfield_data); $i++; @@ -951,7 +953,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); + my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $patron); push (@loop_data, $subfield_data); $i++; } diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 9635774d89..b129e6fd5f 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -32,7 +32,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::AuthorisedValues; use Koha::Biblios; @@ -376,6 +376,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}}) { @@ -420,6 +422,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)