From f1447353ba70baa5558273abf6cf8c6a07600765 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Tue, 1 Oct 2019 12:12:53 -0400 Subject: [PATCH] Bug 12446: (follow-up) Remove mandatory transfered values With the new system preference AdditionalGuarantorField, one can add data to be transfered to the guarantee, but cannot remove default ones. This patch renames the syspref to GuarantorFields and set hardcoded default values as the preference's default. To test: 1. After database update, check that the default value for the syspref GuarantorFields contains these columns: streetnumber|address|address2|city|state|zipcode|country| branchcode|phonepro|mobile|email|emailpro|fax 2. Set the value as empty 3. Try adding a guarantor to a patron (from the guarantor's page or the guarantee's): no values should be imported. 4. Check that it still works with different values for the preference. --- C4/Utils/DataTables/Members.pm | 7 ++----- installer/data/mysql/atomicupdate/bug_12446.perl | 2 +- installer/data/mysql/sysprefs.sql | 2 +- .../prog/en/modules/admin/preferences/patrons.pref | 4 ++-- .../prog/en/modules/common/patron_search.tt | 2 ++ koha-tmpl/intranet-tmpl/prog/js/members.js | 10 ++++++---- members/memberentry.pl | 7 +++---- svc/members/search | 7 +++---- 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index 5fb9b5150f..f5a0b10458 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/C4/Utils/DataTables/Members.pm @@ -80,13 +80,10 @@ sub search { $dbh = C4::Context->dbh; my @columns = qw( borrowernumber surname firstname othernames flags streetnumber streettype address address2 city state zipcode country cardnumber dateexpiry borrowernotes branchcode email userid dateofbirth categorycode phone phonepro mobile fax email emailpro); - my @guarantor_attributes = qw( streetnumber address address2 city state zipcode country branchcode phone phonepro mobile email emailpro fax ); - if( my @additional_guarantor_attributes = split(/\|/, C4::Context->preference("AdditionalGuarantorField")) ){ - $_ =~ s/(?:^\s+)|(?:\s+$)//g for (@additional_guarantor_attributes); # Trim whitespaces - @guarantor_attributes = ( @guarantor_attributes, @additional_guarantor_attributes); - } + my @guarantor_attributes = split(/\|/, C4::Context->preference("GuarantorFields")); if( @guarantor_attributes ){ foreach my $item (@guarantor_attributes) { + $item =~ s/(?:^\s+)|(?:\s+$)//g; # Trim whitespaces if (! grep {$_ eq $item} @columns) { push @columns, $item; } diff --git a/installer/data/mysql/atomicupdate/bug_12446.perl b/installer/data/mysql/atomicupdate/bug_12446.perl index 9575afe186..9b13510f8a 100644 --- a/installer/data/mysql/atomicupdate/bug_12446.perl +++ b/installer/data/mysql/atomicupdate/bug_12446.perl @@ -5,7 +5,7 @@ if( CheckVersion( $DBversion ) ) { ## ******** ## $dbh->do(q{ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) - VALUES ('AdditionalGuarantorField','',NULL,'Additional fields name to be transfer from guarantor to guarantee.','free'); + VALUES ('GuarantorFields', 'streetnumber|address|address2|city|state|zipcode|country|branchcode|phonepro|mobile|email|emailpro|fax', NULL, 'Fields to be transfered from guarantor to guarantee.', 'free') }); ## ********* ## diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index edc3bbf0d8..df24bf59f5 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -9,7 +9,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AcqViewBaskets','user','user|branch|all','Define which baskets a user is allowed to view: his own only, any within his branch or all','Choice'), ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'), ('AdditionalFieldsInZ3950ResultSearch', '', NULL, 'Determines which MARC field/subfields are displayed in -Additional field- column in the result of a search Z3950', 'Free'), -('AdditionalGuarantorField','',NULL,'Additional fields name to be transfer from guarantor to guarantee.','free'), ('AddressFormat','us','us|de|fr','Choose format to display postal addresses', 'Choice'), ('AdlibrisCoversEnabled','0',NULL,'Display cover images in OPAC results and detail listing from Swedish retailer Adlibris.','YesNo'), ('AdlibrisCoversURL','http://www.adlibris.com/se/organisationer/showimagesafe.aspx',NULL,'Base URL for Adlibris cover image web service.','Free'), @@ -216,6 +215,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('GoogleOpenIDConnectDefaultBranch', '','','This branch code will be used to create Google OpenID Connect patrons.','Textarea'), ('GoogleOpenIDConnectDefaultCategory','','','This category code will be used to create Google OpenID Connect patrons.','Textarea'), ('GoogleOpenIDConnectDomain', '', NULL, 'Restrict Google OpenID Connect to this domain (or subdomains of this domain). Leave blank for all Google domains', 'Free'), +('GuarantorFields', 'streetnumber|address|address2|city|state|zipcode|country|branchcode|phonepro|mobile|email|emailpro|fax', NULL, 'Fields to be transfered from guarantor to guarantee.', 'free'), ('hidelostitems','0','','If ON, disables display of\"lost\" items in OPAC.','YesNo'), ('HidePatronName','0','','If this is switched on, patron\'s cardnumber will be shown instead of their name on the holds and catalog screens','YesNo'), ('hide_marc','0',NULL,'If ON, disables display of MARC fields, subfield codes & indicators (still shows data)','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 5498913c72..c8b59f70c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -281,8 +281,8 @@ Patrons: no: "Don't allow" - staff to set the ability for a patron's fines to be viewed by linked patrons in the OPAC. - - - "These additional following database columns will be transferred from guarantor to guarantee:" - - pref: AdditionalGuarantorField + - "These following database columns will be transferred from guarantor to guarantee:" + - pref: GuarantorFields class: multi - (separate columns with |) Privacy: diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt index 9b628126b6..d647e90e20 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt @@ -226,6 +226,8 @@ var borrowernumber = $(this).data("borrowernumber"); var borrower_data = $("#borrower_data"+borrowernumber).val(); var guarantor_attributes = $("#guarantor_attributes").val(); + if ( !guarantor_attributes ) + guarantor_attributes = "{}"; select_user( borrowernumber, JSON.parse(borrower_data), JSON.parse(guarantor_attributes) ); }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index 6d18d6286b..3eb177eb9e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -210,10 +210,12 @@ function select_user(borrowernumber, borrower, relationship, attributes) { fieldset.find('.new_guarantor_relationship').val(relationship); } - for (var i = 0; i < parseInt(attributes.length, 10); i++) { - var attribute = attributes[i]; - if (borrower[attribute] != null){ - document.forms.entryform[attribute].value = borrower[attribute]; + if ( attributes ) { + for (var i = 0; i < parseInt(attributes.length, 10); i++) { + var attribute = attributes[i]; + if (borrower[attribute] != null){ + document.forms.entryform[attribute].value = borrower[attribute]; + } } } } diff --git a/members/memberentry.pl b/members/memberentry.pl index a67276e016..bcc43025d2 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -808,10 +808,9 @@ if (C4::Context->preference('EnhancedMessagingPreferences')) { $template->param( "show_guarantor" => $categorycode ? Koha::Patron::Categories->find($categorycode)->canbeguarantee : 1); # associate with step to know where you are -my @guarantor_attributes = qw( streetnumber address address2 city state zipcode country branchcode phone phonepro mobile email emailpro fax ); -if( my @additional_guarantor_attributes = split(/\|/, C4::Context->preference("AdditionalGuarantorField")) ){ - $_ =~ s/(?:^\s+)|(?:\s+$)//g for (@additional_guarantor_attributes); # Trim whitespaces - @guarantor_attributes = ( @guarantor_attributes, @additional_guarantor_attributes); +my @guarantor_attributes = split(/\|/, C4::Context->preference("GuarantorFields")); +if (@guarantor_attributes) { + $_ =~ s/(?:^\s+)|(?:\s+$)//g for (@guarantor_attributes); # Trim whitespaces } $template->param( "guarantor_attributes" => \@guarantor_attributes ); $debug and warn "memberentry step: $step"; diff --git a/svc/members/search b/svc/members/search index 38a0a3ffef..1a236bb83b 100755 --- a/svc/members/search +++ b/svc/members/search @@ -91,10 +91,9 @@ $results = C4::Utils::DataTables::Members::search( } ) unless $results; -my @attributes = qw( streetnumber address address2 city state zipcode country branchcode phone phonepro mobile email emailpro fax ); -if( my @additional = split(/\|/, C4::Context->preference("AdditionalGuarantorField")) ){ - $_ =~ s/(?:^\s+)|(?:\s+$)//g for (@additional); # Trim whitespaces - @attributes = ( @attributes, @additional); +my @attributes = split(/\|/, C4::Context->preference("GuarantorFields")); +if (@attributes) { + $_ =~ s/(?:^\s+)|(?:\s+$)//g for (@attributes); # Trim whitespaces } $template->param( sEcho => $sEcho, -- 2.17.1