Bug 33428: Parse search fields in buildPatronSearchQuery

This patch moves the parsing of standard search_field into the buildPatronQuery subroutine
and adds a check for 'standard' field before adding attributes to the search

To test:
1 - Add a new attribute type and make it searchable
2 - Add a value to a patron
3 - Search for this value using 'Standard' fields, confirm you get the patron
4 - Search for the value using 'Cardnumber' field, confirm you get the patron - BAD!
5 - Apply patch
6 - Repeat cardnumebr search, confirm patron not found - Yay!
7 - Search standard, confirm patron is found
8 - Add a new field to 'DefaultPatronSearchFields
9 - Confirm it appears in patron search dropdown
10 - Confirm a search of this field with the attribute value does not return the patron

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-08-10 18:58:55 +00:00 committed by Tomas Cohen Arazi
parent a06396c282
commit b1b92cb9a4
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 27 additions and 10 deletions

View file

@ -1,9 +1,9 @@
[%- BLOCK patron_fields -%]
[%- SWITCH name -%]
[%- CASE standard -%]<span>Standard</span>
[%- CASE full_address -%]<span>Full address</span>
[%- CASE all_emails -%]<span>All emails</span>
[%- CASE all_phones -%]<span>All phones</span>
[%- CASE 'standard' -%]<span>Standard</span>
[%- CASE 'full_address' -%]<span>Full address</span>
[%- CASE 'all_emails' -%]<span>All emails</span>
[%- CASE 'all_phones' -%]<span>All phones</span>
[%- CASE 'borrowernumber' -%]<span>Borrowernumber</span>
[%- CASE 'cardnumber' -%]<span>Card number</span>
[%- CASE 'surname' -%]<span>Surname</span>
@ -87,10 +87,8 @@
<select name="searchfieldstype" id="searchfieldstype_filter">
[% END %]
[% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname|middle_name|surname|othernames|cardnumber|userid' %]
[% SET full_address = 'streetnumber|streettype|address|address2|city|state|zipcode|country' %]
[% SET all_emails = 'email|emailpro|B_email' %]
[% SET all_phones = 'phone|phonepro|B_phone|altcontactphone|mobile' %]
[% default_fields = [ standard, 'surname', 'cardnumber', all_emails, 'borrowernumber', 'userid', all_phones, full_address, 'dateofbirth', 'sort1', 'sort2' ] %]
[%# Above is needed for adding fields from the DefaultPatronSearchFields preference to the dropdowns %]
[% default_fields = [ 'standard', 'surname', 'cardnumber', 'all_emails', 'borrowernumber', 'userid', 'all_phones', 'full_address', 'dateofbirth', 'sort1', 'sort2' ] %]
[% search_options = default_fields.merge(standard.split('\|')).unique %]
[% FOREACH s_o IN search_options %]
[% display_name = PROCESS patron_fields name=s_o %]

View file

@ -520,6 +520,25 @@ function patron_autocomplete(node, options) {
};
}
function expandPatronSearchFields(search_fields) {
switch(search_fields) {
case 'standard':
return defaultPatronSearchFields;
break;
case 'full_address':
return 'streetnumber,streettype,address,address2,city,state,zipcode,country';
break;
case 'all_emails':
return 'email,emailpro,B_email';
break;
case 'all_phones':
return 'phone,phonepro,B_phone,altcontactphone,mobile';
break;
default:
return search_fields;
}
}
/**
* Build patron search query
* - term: The full search term input by the user
@ -550,7 +569,7 @@ function buildPatronSearchQuery(term, options) {
// Search fields: If search_fields option exists, we use that
if (typeof options !== 'undefined' && options.search_fields) {
search_fields = options.search_fields;
search_fields = expandPatronSearchFields(options.search_fields);
// If not, we use DefaultPatronSearchFields system preference instead
} else {
search_fields = defaultPatronSearchFields;
@ -587,7 +606,7 @@ function buildPatronSearchQuery(term, options) {
q.push({ "-or": term_subquery_or });
// Add each pattern for each extended patron attributes
if (typeof options !== 'undefined' && options.extended_attribute_types && extendedPatronAttributes) {
if (typeof options !== 'undefined' && options.search_fields == 'standard' && options.extended_attribute_types && extendedPatronAttributes) {
extended_attribute_subquery_and = [];
patterns.forEach(function (pattern, i) {
let extended_attribute_sub_or = [];