From 3d006feb85980d4b1b31c4ac253e7e43567e90b9 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Fri, 30 Mar 2012 13:52:38 +0200 Subject: [PATCH 1/1] Bug 7673 : New patron permissions --- C4/Items.pm | 2 +- C4/VirtualShelves.pm | 2 +- cataloguing/additem.pl | 29 +++++++++++++++++--- .../data/mysql/en/mandatory/userpermissions.sql | 3 ++ installer/data/mysql/updatedatabase.pl | 20 +++++++++++++ .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 1 + .../prog/en/modules/cataloguing/additem.tt | 9 +++++- tools/batchMod.pl | 7 +++++ 8 files changed, 66 insertions(+), 7 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 0b2f99b..d33f4ea 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1589,7 +1589,7 @@ sub GetItemnumberFromBarcode { my $dbh = C4::Context->dbh; my $rq = - $dbh->prepare("SELECT itemnumber FROM items WHERE items.barcode=?"); + $dbh->prepare("SELECT itemnumber FROM items WHERE TRIM(items.barcode)=?"); $rq->execute($barcode); my ($result) = $rq->fetchrow; return ($result); diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 85dbc9f..3aa5e8e 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -458,7 +458,7 @@ sub ShelfPossibleAction { return 0 unless defined($shelfnumber); - my $query = qq/ + my $query = qq / SELECT IFNULL(owner,0) AS owner, category, allow_add, allow_delete_own, allow_delete_other, IFNULL(sh.borrowernumber,0) AS borrowernumber FROM virtualshelves vs LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 9c8120e..3ce517e 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -33,6 +33,7 @@ use C4::ClassSource; use C4::Dates; use List::MoreUtils qw/any/; use C4::Search; +use C4::Members; use MARC::File::XML; use URI::Escape; @@ -100,7 +101,7 @@ 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 %subfield_data; @@ -152,6 +153,14 @@ sub generate_subfield_form { $value = $input->param('barcode'); } my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="$subfield_data{maxlength}" ); + $attributes_no_value .= 'readonly="readonly" ' + if ( + $limitededition + and C4::Context->preference("marcflavour") eq "UNIMARC" + and $subfieldtag ne 'f' + and $subfieldtag ne 'u' + ); + my $attributes = qq($attributes_no_value value="$value" ); if ( $subfieldlib->{authorised_value} ) { @@ -212,7 +221,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, @@ -224,6 +233,13 @@ sub generate_subfield_form { -id => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield, -class => "input_marceditor", ); + push @scrparam, (-readonly => "readonly") + if ( + $limitededition + and C4::Context->preference("marcflavour") eq "UNIMARC" + and $subfieldtag ne 'o' + ); + $subfield_data{marc_value} =CGI::scrolling_list(@scrparam); } } @@ -308,6 +324,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); @@ -682,8 +704,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++; diff --git a/installer/data/mysql/en/mandatory/userpermissions.sql b/installer/data/mysql/en/mandatory/userpermissions.sql index 873089a..bfe1580 100644 --- a/installer/data/mysql/en/mandatory/userpermissions.sql +++ b/installer/data/mysql/en/mandatory/userpermissions.sql @@ -6,6 +6,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'), @@ -32,6 +34,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES (13, 'batch_upload_patron_images', 'Upload patron images in 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/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index ddc288c..1fff211 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5109,6 +5109,26 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } + +$DBversion = "3.07.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(qq{ + 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(qq{ + INSERT INTO permissions (module_bit, code, description) VALUES ('9', 'delete_all_items', 'Delete all items'); + }); + + $dbh->do(qq{ + 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)'); + }); + + print "Upgrade to $DBversion done (Adds new permissions for cataloguing and batch item modification)\n"; + + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($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 be2f74f..debd199 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -117,6 +117,7 @@ function confirm_items_deletion() { [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{ text: _("Replace Record via Z39.50"), onclick: {fn: PopupZ3950 } },[% END %] [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{ text: _("Delete Record"), onclick: {fn: confirm_deletion }[% IF ( count ) %],id:'disabled'[% END %] },[% END %] [% IF ( CAN_user_editcatalogue_edit_items ) %]{ text: _("Delete all Items"), onclick: {fn: confirm_items_deletion }[% UNLESS ( count ) %],id:'disabled'[% END %] }[% END %] + [% IF ( CAN_user_editcatalogue_delete_all_items ) %]{ text: _("Delete all Items"), onclick: {fn: confirm_items_deletion } }[% END %] ]; if(editmenu.length){ new YAHOO.widget.Button({ 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 26313f9..29e13da 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -47,6 +47,13 @@ function Check(f) { var alertString2; if (total_errors==0) { + // Explanation about this line: + // In case of limited edition permission, we have to prevent user from modifying some fields. + // But there is no such thing as readonly attribute for select elements. + // So we use disabled instead. But disabled prevent values from being passed through the form at submit. + // So we "un-disable" the elements just before submitting. + // That's a bit clumsy, and if someone comes up with a better solution, feel free to improve that. + $("select[name=field_value]").removeAttr("disabled"); return true; } else { alertString2 = _("Form not submitted because of the following problem(s)"); @@ -217,7 +224,7 @@ $(document).ready(function() {
-
+ [% IF ( opisadd ) %] diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 9d59e3a..1ff89ce 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; my $input = new CGI; @@ -65,6 +66,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); @@ -274,6 +280,7 @@ 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 && C4::Context->preference("marcflavour") eq "UNIMARC" && $subfield ne 'o'); 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.7.3