From aee1a3daf2ce8de239225eb21f1dc5bc492e5dcf Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Fri, 30 Mar 2012 13:52:38 +0200 Subject: [PATCH] Bug 7673 : New patron permissions This patch adds the following permissions: - editcatalogue.limited_item_edition: Limit item modification to barcode, status and note - editcatalogue.delete_all_items: Delete all items at once - tools.items_limited_batchmod: Limit batch item modification to item status The SubfieldsToAllowForLimitedEdition syspref is used to define which subfields can be edited when the editcatalogue.limited_item_edition permission is enabled. In the same way, the SubfieldsToAllowForLimitedBatchmod is used to define which subfields can be edited when the tools.items_limited_batchmod permission is enabled. --- cataloguing/additem.pl | 42 ++++++++++++++++---- .../data/mysql/en/mandatory/userpermissions.sql | 3 ++ installer/data/mysql/sysprefs.sql | 2 + installer/data/mysql/updatedatabase.pl | 28 +++++++++++++ .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 1 - .../en/modules/admin/preferences/cataloguing.pref | 6 +++ .../prog/en/modules/cataloguing/additem.tt | 13 +++++- tools/batchMod.pl | 10 +++++ 8 files changed, 95 insertions(+), 10 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index a819019..88928c1 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -36,7 +36,7 @@ use List::MoreUtils qw/any/; use C4::Search; use Storable qw(thaw freeze); use URI::Escape; - +use C4::Members; use MARC::File::XML; use URI::Escape; @@ -104,9 +104,10 @@ sub _increment_barcode { sub generate_subfield_form { - my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $today_iso, $biblionumber, $temp, $loop_data, $i) = @_; + my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $today_iso, $biblionumber, $temp, $loop_data, $i, $limitededition) = @_; - my $frameworkcode = &GetFrameworkCode($biblionumber); + my $frameworkcode = &GetFrameworkCode($biblionumber); + my %subfield_data; my $dbh = C4::Context->dbh; @@ -156,6 +157,19 @@ sub generate_subfield_form { } my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="$subfield_data{maxlength}" ); my $attributes_no_value_textarea = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" rows="5" cols="64" ); + + # Getting list of subfields to keep when limited edition is enabled + my $subfieldsToAllowForLimitedEdition = C4::Context->preference('SubfieldsToAllowForLimitedEdition'); + my @subfieldsToAllow = split(/ /, $subfieldsToAllowForLimitedEdition); + + # If we're on limited edition, and our field is not in the list of subfields to allow, + # then it is read-only + $attributes_no_value .= 'readonly="readonly" ' + if ( + $limitededition + and !grep { $tag . '$' . $subfieldtag eq $_ } @subfieldsToAllow + ); + my $attributes = qq($attributes_no_value value="$value" ); if ( $subfieldlib->{authorised_value} ) { @@ -216,7 +230,7 @@ sub generate_subfield_form { $subfield_data{marc_value} = qq( $authorised_lib{$value}); } else { - $subfield_data{marc_value} =CGI::scrolling_list( # FIXME: factor out scrolling_list + my @scrparam = ( -name => "field_value", -values => \@authorised_values, -default => $value, @@ -228,6 +242,15 @@ sub generate_subfield_form { -id => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield, -class => "input_marceditor", ); + + # If we're on limited edition, and our field is not in the list of subfields to allow, + # then it is read-only + push @scrparam, (-readonly => "readonly"), (-disabled => "disabled") + if ( + $limitededition + and !grep { $tag . '$' . $subfieldtag eq $_ } @subfieldsToAllow + ); + $subfield_data{marc_value} =CGI::scrolling_list(@scrparam); } } @@ -346,6 +369,12 @@ my ($template, $loggedinuser, $cookie) }); +# Does the user have a limited item edition permission? +my $uid = GetMember( borrowernumber => $loggedinuser )->{userid} if ($loggedinuser) ; +my $limitededition = haspermission($uid, {'editcatalogue' => 'limited_item_edition'}) if ($uid); +# In case user is a superlibrarian, edition is not limited +$limitededition = 0 if ($limitededition != 0 && $limitededition->{'superlibrarian'} eq 1); + my $today_iso = C4::Dates->today('iso'); my $tagslib = &GetMarcStructure(1,$frameworkcode); my $record = GetMarcBiblio($biblionumber); @@ -777,8 +806,7 @@ if($itemrecord){ next if subfield_is_koha_internal_p($subfieldtag); next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10"); - my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i); - + my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i, $limitededition); push @fields, "$tag$subfieldtag"; push (@loop_data, $subfield_data); $i++; @@ -802,7 +830,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}, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i); + my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i, $limitededition); push (@loop_data, $subfield_data); $i++; } diff --git a/installer/data/mysql/en/mandatory/userpermissions.sql b/installer/data/mysql/en/mandatory/userpermissions.sql index 7874c9e..9db38bc 100644 --- a/installer/data/mysql/en/mandatory/userpermissions.sql +++ b/installer/data/mysql/en/mandatory/userpermissions.sql @@ -9,6 +9,8 @@ INSERT INTO permissions (module_bit, code, description) VALUES ( 9, 'edit_catalogue', 'Edit catalog (Modify bibliographic/holdings data)'), ( 9, 'fast_cataloging', 'Fast cataloging'), ( 9, 'edit_items', 'Edit Items'), + ( 9, 'limited_item_edition', 'Limit item modification to barcode, status and note (please note that edit_item is still required)'), + ( 9, 'delete_all_items', 'Delete all items'), (11, 'vendors_manage', 'Manage vendors'), (11, 'contracts_manage', 'Manage contracts'), (11, 'period_manage', 'Manage periods'), @@ -39,6 +41,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES (13, 'batch_upload_patron_images', 'Upload patron images in a batch or one at a time'), (13, 'schedule_tasks', 'Schedule tasks to run'), (13, 'items_batchmod', 'Perform batch modification of items'), + (13, 'items_limited_batchmod', 'Limit batch item modification to item status (please note that items_batchmod is still required)'), (13, 'items_batchdel', 'Perform batch deletion of items'), (13, 'manage_csv_profiles', 'Manage CSV export profiles'), (13, 'moderate_tags', 'Moderate patron tags'), diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 6438483..7b72252 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -355,6 +355,8 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('StaffDetailItemSelection', '1', NULL, 'Enable item selection in record detail page', 'YesNo'), ('StaffSerialIssueDisplayCount','3','','Number of serial issues to display per subscription in the Staff client','Integer'), ('StaticHoldsQueueWeight','0',NULL,'Specify a list of library location codes separated by commas -- the list of codes will be traversed and weighted with first values given higher weight for holds fulfillment -- alternatively, if RandomizeHoldsQueueWeight is set, the list will be randomly selective','Integer'), +('SubfieldsToAllowForLimitedEdition','','','Define a list of subfields for which edition is authorized when limited_item_edtion permission is enabled, separated by spaces. Example: 995$f 995$h 995$j','Free'), +('SubfieldsToAllowForLimitedBatchmod','','','Define a list of subfields for which edition is authorized when items_limited_batchmod permission is enabled, separated by spaces. Example: 995$f 995$h 995$j','Free'), ('SubfieldsToUseWhenPrefill','','','Define a list of subfields to use when prefilling items (separated by space)','Free'), ('SubscriptionDuplicateDroppedInput','','','List of fields which must not be rewritten when a subscription is duplicated (Separated by pipe |)','Free'), ('SubscriptionHistory','simplified','simplified|full','Define the display preference for serials issue history in OPAC','Choice'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index a9bfbbf..2668126 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7778,6 +7778,34 @@ if(CheckVersion($DBversion)) { SetVersion($DBversion); } +$DBversion = "3.11.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(q{ + INSERT INTO permissions (module_bit, code, description) VALUES ('9', 'limited_item_edition', 'Limit item modification to barcode, status and note (please note that edit_item is still required)'); + }); + + $dbh->do(q{ + INSERT INTO permissions (module_bit, code, description) VALUES ('9', 'delete_all_items', 'Delete all items at once'); + }); + + $dbh->do(q{ + INSERT INTO permissions (module_bit, code, description) VALUES ('13', 'items_limited_batchmod', 'Limit batch item modification to item status (please note that items_batchmod is still required)'); + }); + + $dbh->do(q{ + INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToAllowForLimitedEdition','','Define a list of subfields for which edition is authorized when limited_item_edtion permission is enabled, separated by spaces. Example: 995\$f 995\$h 995\$j','','Free'); + }); + + $dbh->do(q{ + INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToAllowForLimitedBatchmod','','Define a list of subfields for which edition is authorized when items_limited_batchmod permission is enabled, separated by spaces. Example: 995\$f 995\$h 995\$j','','Free'); + }); + + print "Upgrade to $DBversion done (Bug 7673: Adds new permissions for cataloguing and batch item modification)\n"; + + SetVersion($DBversion); +} + + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc index 63b22a4..b18aef1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -148,7 +148,6 @@ CAN_user_serials_create_subscription ) %] [% END %] -
-
+ [% IF (popup) %] diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 69762b1..8c83490 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -33,6 +33,7 @@ use C4::BackgroundJob; use C4::ClassSource; use C4::Dates; use C4::Debug; +use C4::Members; use MARC::File::XML; use List::MoreUtils qw/uniq/; @@ -69,6 +70,11 @@ my ($template, $loggedinuser, $cookie) flagsrequired => $template_flag, }); +# Does the user have a limited item edition permission? +my $uid = GetMember( borrowernumber => $loggedinuser )->{userid} if ($loggedinuser) ; +my $limitededition = haspermission($uid, {'tools' => 'items_limited_batchmod'}) if ($uid); +# In case user is a superlibrarian, edition is not limited +$limitededition = 0 if ($limitededition != 0 && $limitededition->{'superlibrarian'} eq 1); my $today_iso = C4::Dates->today('iso'); $template->param(today_iso => $today_iso); @@ -294,11 +300,15 @@ unshift (@$branches, $nochange_branch); my $pref_itemcallnumber = C4::Context->preference('itemcallnumber'); +# Getting list of subfields to keep when limited batchmod edit is enabled +my $subfieldsToAllowForBatchmod = C4::Context->preference('SubfieldsToAllowForLimitedBatchmod'); +my @subfieldsToAllow = split(/ /, $subfieldsToAllowForBatchmod); foreach my $tag (sort keys %{$tagslib}) { # loop through each subfield foreach my $subfield (sort keys %{$tagslib->{$tag}}) { next if subfield_is_koha_internal_p($subfield); + next if ($limitededition && !grep { $tag . '$' . $subfield eq $_ } @subfieldsToAllow ); next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); # barcode and stocknumber are not meant to be batch-modified next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode'; -- 1.7.10.4