View | Details | Raw Unified | Return to bug 41048
Collapse All | Expand All

(-)a/Koha/REST/V1/Patrons.pm (+28 lines)
Lines 47-52 sub list { Link Here
47
47
48
    return try {
48
    return try {
49
49
50
        # Check if empty searches are disallowed
51
        if ( C4::Context->preference('DisallowEmptyPatronSearches') ) {
52
            my $has_search_criteria = 0;
53
            my $params              = $c->req->query_params->to_hash;
54
55
            # Remove special parameters that aren't search criteria
56
            delete $params->{_per_page};
57
            delete $params->{_page};
58
            delete $params->{_order_by};
59
            delete $params->{_match};
60
61
            # Check if any search parameters are provided
62
            $has_search_criteria = 1 if scalar( keys %$params ) > 0;
63
64
            # Check if we're not in restricted mode (which would add a criterion)
65
            $has_search_criteria = 1 if $c->param('restricted');
66
67
            if ( !$has_search_criteria ) {
68
                return $c->render(
69
                    status  => 422,
70
                    openapi => {
71
                        error => 'Search criteria are required',
72
                        code  => 'empty_search_not_allowed'
73
                    }
74
                );
75
            }
76
        }
77
50
        my $query      = {};
78
        my $query      = {};
51
        my $restricted = $c->param('restricted');
79
        my $restricted = $c->param('restricted');
52
        $c->req->params->remove('restricted');
80
        $c->req->params->remove('restricted');
(-)a/api/v1/swagger/paths/patrons.yaml (+4 lines)
Lines 392-397 Link Here
392
        description: Access forbidden
392
        description: Access forbidden
393
        schema:
393
        schema:
394
          $ref: "../swagger.yaml#/definitions/error"
394
          $ref: "../swagger.yaml#/definitions/error"
395
      "422":
396
        description: Unprocessable Content
397
        schema:
398
          $ref: "../swagger.yaml#/definitions/error"
395
      "500":
399
      "500":
396
        description: |
400
        description: |
397
          Internal server error. Possible `error_code` attribute values:
401
          Internal server error. Possible `error_code` attribute values:
(-)a/installer/data/mysql/atomicupdate/bug_41048.pl (+20 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "41048",
6
    description => ":dd ability to disallow empty patron searches",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        $dbh->do(
12
            q{
13
INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
14
('DisallowEmptyPatronSearches','0',NULL,'If enabled, the Patron REST API will return a 422 status code when a search is performed without any criteria.','YesNo')
15
        }
16
        );
17
18
        say $out "Added new system preference 'DisallowEmptyPatronSearches'";
19
    },
20
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 214-219 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
214
('DefaultLongOverdueSkipPatronCategories', '', NULL, "Set the patron categories that will not be listed when longoverdue cronjob is executed", 'choice'),
214
('DefaultLongOverdueSkipPatronCategories', '', NULL, "Set the patron categories that will not be listed when longoverdue cronjob is executed", 'choice'),
215
('DefaultPatronSearchFields',    'firstname|preferred_name|middle_name|surname|othernames|cardnumber|userid',NULL,'Pipe separated list defining the default fields to be used during a patron search using the "standard" option. If empty Koha will default to "firstname|surname|othernames|cardnumber|userid". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page.','free'),
215
('DefaultPatronSearchFields',    'firstname|preferred_name|middle_name|surname|othernames|cardnumber|userid',NULL,'Pipe separated list defining the default fields to be used during a patron search using the "standard" option. If empty Koha will default to "firstname|surname|othernames|cardnumber|userid". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page.','free'),
216
('DefaultPatronSearchMethod','starts_with','Choose which search method to use by default when searching with PatronAutoComplete','starts_with|contains','Choice'),
216
('DefaultPatronSearchMethod','starts_with','Choose which search method to use by default when searching with PatronAutoComplete','starts_with|contains','Choice'),
217
('DisallowEmptyPatronSearches','0',NULL,'If enabled, the Patron REST API will return a 422 status code when a search is performed without any criteria.','YesNo'),
217
('DefaultSaveRecordFileID','biblionumber','biblionumber|controlnumber','Defines whether the advanced cataloging editor will use the bibliographic record number or control number field to populate the name of the save file','Choice'),
218
('DefaultSaveRecordFileID','biblionumber','biblionumber|controlnumber','Defines whether the advanced cataloging editor will use the bibliographic record number or control number field to populate the name of the save file','Choice'),
218
('defaultSortField','relevance','relevance|popularity|call_number|pubdate|acqdate|title|author','Specify the default field used for sorting','Choice'),
219
('defaultSortField','relevance','relevance|popularity|call_number|pubdate|acqdate|title|author','Specify the default field used for sorting','Choice'),
219
('defaultSortOrder','dsc','asc|dsc|az|za','Specify the default sort order','Choice'),
220
('defaultSortOrder','dsc','asc|dsc|az|za','Specify the default sort order','Choice'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-1 / +40 lines)
Lines 343-352 Link Here
343
            [% END %]
343
            [% END %]
344
344
345
            $(document).ready(function(){
345
            $(document).ready(function(){
346
347
                let parent_block = $("#[% search_results_block_id | html %]");
346
                let parent_block = $("#[% search_results_block_id | html %]");
348
                let patron_search_form = get_patron_search_form();
347
                let patron_search_form = get_patron_search_form();
349
348
349
                let patron_search_filter = patron_search_form.find(".search_patron_filter"); // jQuery object
350
                let search_patron_filter_btn = patron_search_form.find(".search_patron_filter_btn"); // assuming you already have this
351
352
                [% IF Koha.Preference('DisallowEmptyPatronSearches') %]
353
                    // Check for passed search value on load
354
                    if (!patron_search_filter.val()) {
355
                        search_patron_filter_btn.prop('disabled', true);
356
                    }
357
358
                    // Check for empty search value on input
359
                    patron_search_filter.on("input", function() {
360
                        if (!patron_search_filter.val()) {
361
                            search_patron_filter_btn.prop('disabled', true);
362
                        } else {
363
                            search_patron_filter_btn.prop('disabled', false);
364
                        }
365
                    });
366
                [% END %]
367
350
                parent_block.find(".info").hide();
368
                parent_block.find(".info").hide();
351
                parent_block.find(".error").hide();
369
                parent_block.find(".error").hide();
352
370
Lines 493-498 Link Here
493
                                first_draw = 0;
511
                                first_draw = 0;
494
                            [% END %]
512
                            [% END %]
495
                            return json.data;
513
                            return json.data;
514
                        },
515
                        error: function(xhr, error, thrown) {
516
                            if (xhr.status === 422) {
517
                                // Directly manipulate tbody instead of clear().draw(), that causes an infinite loop
518
                                var tbody = table_node.find('tbody');
519
                                tbody.empty();
520
521
                                // Hide the "Processing..." model
522
                                $(".dt-processing").hide();
523
524
                                // Display a message to the librarian
525
                                var colCount = table_node.find('thead th').length;
526
                                tbody.append(
527
                                    '<tr class="error-row"><td colspan="' + colCount + '" style="text-align:center;">' +
528
                                    _("Empty patron search, please add a search term") +
529
                                    '</td></tr>'
530
                                );
531
532
                                // Re-enable the patron search button
533
                                patron_search_form.find(".search_patron_filter_btn").prop({disabled: false});
534
                            }
496
                        }
535
                        }
497
                    },
536
                    },
498
                    [% IF open_on_row_click OR preview_on_name_click OR remember_selections %]
537
                    [% IF open_on_row_click OR preview_on_name_click OR remember_selections %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (-1 / +6 lines)
Lines 468-473 Patrons: Link Here
468
         - pref: minPasswordLength
468
         - pref: minPasswordLength
469
           class: integer
469
           class: integer
470
         - characters long.
470
         - characters long.
471
     -
472
         - pref: DisallowEmptyPatronSearches
473
           choices:
474
               1: "Require"
475
               0: "Don't require"
476
         - "at least one search criterion when searching for patrons."
471
     -
477
     -
472
         - pref: RequireStrongPassword
478
         - pref: RequireStrongPassword
473
           choices:
479
           choices:
474
- 

Return to bug 41048