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

(-)a/Koha/REST/V1/Illbatches.pm (+18 lines)
Lines 23-28 use Koha::Illbatches; Link Here
23
use Koha::IllbatchStatuses;
23
use Koha::IllbatchStatuses;
24
use Koha::Illrequests;
24
use Koha::Illrequests;
25
25
26
use Try::Tiny qw( catch try );
27
26
=head1 NAME
28
=head1 NAME
27
29
28
Koha::REST::V1::Illbatches
30
Koha::REST::V1::Illbatches
Lines 140-145 sub add { Link Here
140
    # We receive cardnumber, so we need to look up the corresponding
142
    # We receive cardnumber, so we need to look up the corresponding
141
    # borrowernumber
143
    # borrowernumber
142
    my $patron = Koha::Patrons->find({ cardnumber => $body->{cardnumber} });
144
    my $patron = Koha::Patrons->find({ cardnumber => $body->{cardnumber} });
145
146
    if ( not defined $patron ) {
147
        return $c->render(
148
            status  => 404,
149
            openapi => { error => "Patron with cardnumber " . $body->{cardnumber} . " not found" }
150
        );
151
    }
152
143
    delete $body->{cardnumber};
153
    delete $body->{cardnumber};
144
    $body->{borrowernumber} = $patron->borrowernumber;
154
    $body->{borrowernumber} = $patron->borrowernumber;
145
155
Lines 162-167 sub add { Link Here
162
        );
172
        );
163
    }
173
    }
164
    catch {
174
    catch {
175
        if ( blessed $_ ) {
176
            if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
177
                return $c->render(
178
                    status  => 409,
179
                    openapi => { error => "A batch named " . $body->{name} . " already exists" }
180
                );
181
            }
182
        }
165
        $c->unhandled_exception($_);
183
        $c->unhandled_exception($_);
166
    };
184
    };
167
}
185
}
(-)a/api/v1/swagger/definitions/illrequest.yaml (-1 / +1 lines)
Lines 128-134 properties: Link Here
128
    description: The request's current status
128
    description: The request's current status
129
  status_alias:
129
  status_alias:
130
    type:
130
    type:
131
      - string
131
      - object
132
      - "null"
132
      - "null"
133
    description: The ID of a user defined status for this request
133
    description: The ID of a user defined status for this request
134
  updated:
134
  updated:
(-)a/api/v1/swagger/paths/illbatches.yaml (+4 lines)
Lines 72-77 Link Here
72
        description: Access forbidden
72
        description: Access forbidden
73
        schema:
73
        schema:
74
          $ref: "../swagger.yaml#/definitions/error"
74
          $ref: "../swagger.yaml#/definitions/error"
75
      "404":
76
        description: Patron with given cardnumber not found
77
        schema:
78
          $ref: "../swagger.yaml#/definitions/error"
75
      "409":
79
      "409":
76
        description: Conflict in creating resource
80
        description: Conflict in creating resource
77
        schema:
81
        schema:
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal-strings.inc (+1 lines)
Lines 17-22 Link Here
17
    var ill_batch_create_api_fail = _("Unable to create batch request");
17
    var ill_batch_create_api_fail = _("Unable to create batch request");
18
    var ill_batch_update_api_fail = _("Unable to updatecreate batch request");
18
    var ill_batch_update_api_fail = _("Unable to updatecreate batch request");
19
    var ill_batch_item_remove = _("Are you sure you want to remove this item from the batch");
19
    var ill_batch_item_remove = _("Are you sure you want to remove this item from the batch");
20
    var ill_batch_create_cancel_button = _("Close");
20
    var ill_batch_metadata_more = _("More");
21
    var ill_batch_metadata_more = _("More");
21
    var ill_batch_metadata_less = _("Less");
22
    var ill_batch_metadata_less = _("Less");
22
    var ill_batch_available_via = _("Available via");
23
    var ill_batch_available_via = _("Available via");
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal.inc (-8 / +9 lines)
Lines 18-25 Link Here
18
                                    value="" />
18
                                    value="" />
19
                                </li>
19
                                </li>
20
                                <li id="batch_patron">
20
                                <li id="batch_patron">
21
                                    <label class="required" for="cardnumber">Card number, username or surname:</label>
21
                                    <label class="required" for="batchcardnumber">Card number, username or surname:</label>
22
                                    <input type="text" autocomplete="off" name="cardnumber" id="cardnumber" type="text" value="" />
22
                                    <input type="text" autocomplete="off" name="batchcardnumber" id="batchcardnumber" type="text" value="" />
23
                                    <span id="patron_link"></span>
23
                                    <span id="patron_link"></span>
24
                                </li>
24
                                </li>
25
                                <li id="batch_branch">
25
                                <li id="batch_branch">
Lines 49-55 Link Here
49
                                    <textarea id="identifiers_input" placeholder="Enter identifiers, one per line"></textarea>
49
                                    <textarea id="identifiers_input" placeholder="Enter identifiers, one per line"></textarea>
50
                                </li>
50
                                </li>
51
                                <li id="process-button">
51
                                <li id="process-button">
52
                                    <button id="process_button" disabled type="button">Process identifiers</button>
52
                                    <button id="process_button" disabled aria-disabled="true" type="button">Process identifiers</button>
53
                                </li>
53
                                </li>
54
                            </ol>
54
                            </ol>
55
                        </fieldset>
55
                        </fieldset>
Lines 64-72 Link Here
64
                            </div>
64
                            </div>
65
                        </div>
65
                        </div>
66
                    </div>
66
                    </div>
67
                    <div id="create-requests" style="display:none">
68
                        <button id="create-requests-button" type="button" class="btn btn-xs btn-success">Add items to batch</button>
69
                    </div>
70
                    <table id="identifier-table" style="display:none">
67
                    <table id="identifier-table" style="display:none">
71
                        <thead>
68
                        <thead>
72
                            <tr id="identifier-table-header">
69
                            <tr id="identifier-table-header">
Lines 74-79 Link Here
74
                                <th scope="col">Identifier value</th>
71
                                <th scope="col">Identifier value</th>
75
                                <th scope="col">Metadata</th>
72
                                <th scope="col">Metadata</th>
76
                                <th scope="col">Request ID</th>
73
                                <th scope="col">Request ID</th>
74
                                <th scope="col">Request Status</th>
77
                                <th scope="col"></th>
75
                                <th scope="col"></th>
78
                            </tr>
76
                            </tr>
79
                        </thead>
77
                        </thead>
Lines 81-94 Link Here
81
                        </tbody>
79
                        </tbody>
82
                    </table>
80
                    </table>
83
                </div>
81
                </div>
82
                <div id="create-requests" style="display:none">
83
                    <button id="create-requests-button" type="button" class="btn btn-primary" aria-label="Add items to batch">Add items to batch</button>
84
                </div>
84
            </div>
85
            </div>
85
            <div class="modal-footer">
86
            <div class="modal-footer">
86
                <div id="lhs">
87
                <div id="lhs">
87
                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="false">Close</button>
88
                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="false">Cancel</button>
88
                </div>
89
                </div>
89
                <div id="rhs">
90
                <div id="rhs">
90
                    <button id="button_create_batch" class="btn btn-default" aria-hidden="true" disabled>Continue</button>
91
                    <button id="button_create_batch" class="btn btn-default" aria-hidden="true" disabled>Continue</button>
91
                    <a id="button_finish" disabled type="button" class="btn btn-default" aria-hidden="true">Finish and view batch</a>
92
                    <button id="button_finish" disabled type="button" class="btn btn-default" aria-hidden="true">Finish and view batch</button>
92
                </div>
93
                </div>
93
            </div>
94
            </div>
94
        </div>
95
        </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-toolbar.inc (-1 / +1 lines)
Lines 32-38 Link Here
32
                <i class="fa fa-list"></i> List requests
32
                <i class="fa fa-list"></i> List requests
33
            </a>
33
            </a>
34
        [% END %]
34
        [% END %]
35
        [% IF have_batch.size > 0 %]
35
        [% IF have_batch.size > 0 && metadata_enrichment_services %]
36
        <div id="ill-batch">
36
        <div id="ill-batch">
37
            <div class="dropdown btn-group">
37
            <div class="dropdown btn-group">
38
                <button class="btn btn-default dropdown-toggle" type="button" id="ill-batch-backend-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
38
                <button class="btn btn-default dropdown-toggle" type="button" id="ill-batch-backend-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/ill_batch_statuses.tt (-2 / +2 lines)
Lines 132-138 Link Here
132
                                [% FOREACH status IN statuses %]
132
                                [% FOREACH status IN statuses %]
133
                                <tr>
133
                                <tr>
134
                                    <td>[% status.name | html %]</td>
134
                                    <td>[% status.name | html %]</td>
135
                                    <td>[% name.code | html %]</td>
135
                                    <td>[% status.code | html %]</td>
136
                                    <td>[% status.is_system ? "Yes" : "No" | html %]</td>
136
                                    <td>[% status.is_system ? "Yes" : "No" | html %]</td>
137
                                    <td class="actions">
137
                                    <td class="actions">
138
                                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=add_form&amp;code=[% status.code | uri %]"><i class="fa fa-pencil"></i> Edit</a>
138
                                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=add_form&amp;code=[% status.code | uri %]"><i class="fa fa-pencil"></i> Edit</a>
Lines 146-152 Link Here
146
                        </table>
146
                        </table>
147
                    [% ELSE %]
147
                    [% ELSE %]
148
                        <div class="dialog message">
148
                        <div class="dialog message">
149
                            There are no batch statuses defined. <a href="/cgi-bin/koha/admin/debit_types.pl?op=add_form">Create new batch status</a>
149
                            There are no batch statuses defined. <a href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=add_form">Create new batch status</a>
150
                        </div>
150
                        </div>
151
                    [% END %]
151
                    [% END %]
152
                [% END %]
152
                [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js (-31 / +52 lines)
Lines 1-4 Link Here
1
(function () {
1
(function () {
2
    // Bail if there aren't any metadata enrichment plugins installed
3
    if (typeof metadata_enrichment_services === 'undefined') {
4
        console.log('No metadata enrichment plugins found.')
5
        return;
6
    }
7
2
    window.addEventListener('load', onload);
8
    window.addEventListener('load', onload);
3
9
4
    // Delay between API requests
10
    // Delay between API requests
Lines 7-13 Link Here
7
    // Elements we work frequently with
13
    // Elements we work frequently with
8
    var textarea = document.getElementById("identifiers_input");
14
    var textarea = document.getElementById("identifiers_input");
9
    var nameInput = document.getElementById("name");
15
    var nameInput = document.getElementById("name");
10
    var cardnumberInput = document.getElementById("cardnumber");
16
    var cardnumberInput = document.getElementById("batchcardnumber");
11
    var branchcodeSelect = document.getElementById("branchcode");
17
    var branchcodeSelect = document.getElementById("branchcode");
12
    var processButton = document.getElementById("process_button");
18
    var processButton = document.getElementById("process_button");
13
    var createButton = document.getElementById("button_create_batch");
19
    var createButton = document.getElementById("button_create_batch");
Lines 20-26 Link Here
20
    var identifierTable = document.getElementById('identifier-table');
26
    var identifierTable = document.getElementById('identifier-table');
21
    var createRequestsButton = document.getElementById('create-requests-button');
27
    var createRequestsButton = document.getElementById('create-requests-button');
22
    var statusesSelect = document.getElementById('statuscode');
28
    var statusesSelect = document.getElementById('statuscode');
23
29
    var cancelButton = document.getElementById('lhs').querySelector('button');
30
    var cancelButtonOriginalText = cancelButton.innerHTML;
24
31
25
    // We need a data structure keyed on identifier type, which tells us how to parse that
32
    // We need a data structure keyed on identifier type, which tells us how to parse that
26
    // identifier type and what services can get its metadata. We receive an array of
33
    // identifier type and what services can get its metadata. We receive an array of
Lines 58-64 Link Here
58
                obj[prop] = value;
65
                obj[prop] = value;
59
                manageBatchItemsDisplay();
66
                manageBatchItemsDisplay();
60
                updateBatchInputs();
67
                updateBatchInputs();
61
                setFinishButton();
62
                disableCardnumberInput();
68
                disableCardnumberInput();
63
                displayPatronName();
69
                displayPatronName();
64
                updateStatusesSelect();
70
                updateStatusesSelect();
Lines 149-154 Link Here
149
        });
155
        });
150
        $('#ill-batch-modal').on('hidden.bs.modal', function () {
156
        $('#ill-batch-modal').on('hidden.bs.modal', function () {
151
            // Reset our state when we close the modal
157
            // Reset our state when we close the modal
158
            // TODO: need to also reset progress bar and already processed identifiers
152
            delete idEl.dataset.batchId;
159
            delete idEl.dataset.batchId;
153
            delete idEl.dataset.backend;
160
            delete idEl.dataset.backend;
154
            batchId = null;
161
            batchId = null;
Lines 161-166 Link Here
161
            };
168
            };
162
            textarea.value = '';
169
            textarea.value = '';
163
            batch.data = {};
170
            batch.data = {};
171
            cancelButton.innerHTML = cancelButtonOriginalText;
164
            // Remove event listeners we created
172
            // Remove event listeners we created
165
            removeEventListeners();
173
            removeEventListeners();
166
        });
174
        });
Lines 194-199 Link Here
194
202
195
    function initPostCreate() {
203
    function initPostCreate() {
196
        disableCreateButton();
204
        disableCreateButton();
205
        cancelButton.innerHTML = ill_batch_create_cancel_button;
197
    };
206
    };
198
207
199
    function setFinishButton() {
208
    function setFinishButton() {
Lines 211-216 Link Here
211
    // created, and do so
220
    // created, and do so
212
    function requestRequestable() {
221
    function requestRequestable() {
213
        createRequestsButton.setAttribute('disabled', true);
222
        createRequestsButton.setAttribute('disabled', true);
223
        createRequestsButton.setAttribute('aria-disabled', true);
224
        setFinishButton();
214
        var toCheck = tableContent.data;
225
        var toCheck = tableContent.data;
215
        toCheck.forEach(function (row) {
226
        toCheck.forEach(function (row) {
216
            if (
227
            if (
Lines 299-304 Link Here
299
                tableContent.data = tableContent.data.map(function (row) {
310
                tableContent.data = tableContent.data.map(function (row) {
300
                    if (row.value === identifier) {
311
                    if (row.value === identifier) {
301
                        row.requestId = data.illrequest_id;
312
                        row.requestId = data.illrequest_id;
313
                        row.requestStatus = data.status;
302
                    }
314
                    }
303
                    return row;
315
                    return row;
304
                });
316
                });
Lines 421-436 Link Here
421
    function processButtonState() {
433
    function processButtonState() {
422
        if (textarea.value.length > 0) {
434
        if (textarea.value.length > 0) {
423
            processButton.removeAttribute('disabled');
435
            processButton.removeAttribute('disabled');
436
            processButton.removeAttribute('aria-disabled');
424
        } else {
437
        } else {
425
            processButton.setAttribute('disabled', 1);
438
            processButton.setAttribute('disabled', true);
439
            processButton.setAttribute('aria-disabled', true);
426
        }
440
        }
427
    };
441
    };
428
442
429
    function disableCardnumberInput() {
443
    function disableCardnumberInput() {
430
        if (batch.data.patron) {
444
        if (batch.data.patron) {
431
            cardnumberInput.setAttribute('disabled', true);
445
            cardnumberInput.setAttribute('disabled', true);
446
            cardnumberInput.setAttribute('aria-disabled', true);
432
        } else {
447
        } else {
433
            cardnumberInput.removeAttribute('disabled');
448
            cardnumberInput.removeAttribute('disabled');
449
            cardnumberInput.removeAttribute('aria-disabled');
434
        }
450
        }
435
    };
451
    };
436
452
Lines 512-518 Link Here
512
            })
528
            })
513
        })
529
        })
514
            .then(function (response) {
530
            .then(function (response) {
515
                return response.json();
531
                if ( response.ok ) {
532
                    return response.json();
533
                }
534
                return Promise.reject(response);
516
            })
535
            })
517
            .then(function (body) {
536
            .then(function (body) {
518
                batchId = body.id;
537
                batchId = body.id;
Lines 528-535 Link Here
528
                };
547
                };
529
                initPostCreate();
548
                initPostCreate();
530
            })
549
            })
531
            .catch(function () {
550
            .catch(function (response) {
532
                handleApiError(ill_batch_create_api_fail);
551
                response.json().then((json) => {
552
                    if( json.error ) {
553
                        handleApiError(json.error);
554
                    } else {
555
                        handleApiError(ill_batch_create_api_fail);
556
                    }
557
                })
533
            });
558
            });
534
    };
559
    };
535
560
Lines 706-722 Link Here
706
731
707
    function disableProcessButton() {
732
    function disableProcessButton() {
708
        processButton.setAttribute('disabled', true);
733
        processButton.setAttribute('disabled', true);
734
        processButton.setAttribute('aria-disabled', true);
709
    }
735
    }
710
736
711
    function disableCreateButton() {
737
    function disableCreateButton() {
712
        createButton.setAttribute('disabled', true);
738
        createButton.setAttribute('disabled', true);
713
    }
739
        createButton.setAttribute('aria-disabled', true);
714
715
    function disableRemoveRowButtons() {
716
        var buttons = document.getElementsByClassName('remove-row');
717
        for (var button of buttons) {
718
            button.setAttribute('disabled', true);
719
        }
720
    }
740
    }
721
741
722
    async function populateMetadata(identifier) {
742
    async function populateMetadata(identifier) {
Lines 893-898 Link Here
893
        return data.requestId || '-';
913
        return data.requestId || '-';
894
    }
914
    }
895
915
916
    function createRequestStatus(x, y, data) {
917
        return data.requestStatus || '-';
918
    }
919
896
    function buildTable(identifiers) {
920
    function buildTable(identifiers) {
897
        table = KohaTable('identifier-table', {
921
        table = KohaTable('identifier-table', {
898
            processing: true,
922
            processing: true,
Lines 918-926 Link Here
918
                },
942
                },
919
                {
943
                {
920
                    data: 'requestId',
944
                    data: 'requestId',
921
                    width: '13%',
945
                    width: '6.5%',
922
                    render: createRequestId
946
                    render: createRequestId
923
                },
947
                },
948
                {
949
                    data: 'requestStatus',
950
                    width: '6.5%',
951
                    render: createRequestStatus
952
                },
924
                {
953
                {
925
                    width: '18%',
954
                    width: '18%',
926
                    render: createActions,
955
                    render: createActions,
Lines 936-942 Link Here
936
    }
965
    }
937
966
938
    function createActions(x, y, data) {
967
    function createActions(x, y, data) {
939
        return '<button type="button"' + (data.requestId ? ' disabled' : '') + ' class="btn btn-xs btn-danger remove-row">' + ill_button_remove + '</button>';
968
        return '<button type="button" aria-label='+ ill_button_remove + (data.requestId ? ' disabled aria-disabled="true"' : '') + ' class="btn btn-xs btn-danger remove-row">' + ill_button_remove + '</button>';
940
    }
969
    }
941
970
942
    // Redraw the table
971
    // Redraw the table
Lines 1021-1043 Link Here
1021
    }
1050
    }
1022
1051
1023
    function patronAutocomplete() {
1052
    function patronAutocomplete() {
1024
        // Add autocomplete for patron selection
1053
        patron_autocomplete(
1025
        $('#batch-form #cardnumber').autocomplete({
1054
            $('#batch-form #batchcardnumber'),
1026
            appendTo: '#batch-form',
1055
            {
1027
            source: "/cgi-bin/koha/circ/ysearch.pl",
1056
              'on-select-callback': function( event, ui ) {
1028
            minLength: 3,
1057
                $("#batch-form #batchcardnumber").val( ui.item.cardnumber );
1029
            select: function (event, ui) {
1030
                var field = ui.item.cardnumber;
1031
                $('#batch-form #cardnumber').val(field)
1032
                return false;
1058
                return false;
1059
              }
1033
            }
1060
            }
1034
        })
1061
          );
1035
            .data("ui-autocomplete")._renderItem = function (ul, item) {
1036
                return $("<li></li>")
1037
                    .data("ui-autocomplete-item", item)
1038
                    .append("<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>")
1039
                    .appendTo(ul);
1040
            };
1041
    };
1062
    };
1042
1063
1043
    function createPatronLink() {
1064
    function createPatronLink() {
(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js (-3 / +3 lines)
Lines 51-57 $(document).ready(function() { Link Here
51
                    var sel = $('#illfilter_status option:selected').val();
51
                    var sel = $('#illfilter_status option:selected').val();
52
                    if (sel && sel.length > 0) {
52
                    if (sel && sel.length > 0) {
53
                        activeFilters[me] = function() {
53
                        activeFilters[me] = function() {
54
                            table.api().column(13).search(sel);
54
                            table.api().column(14).search(sel);
55
                        }
55
                        }
56
                    } else {
56
                    } else {
57
                        if (activeFilters.hasOwnProperty(me)) {
57
                        if (activeFilters.hasOwnProperty(me)) {
Lines 83-89 $(document).ready(function() { Link Here
83
                    var sel = $('#illfilter_branchname option:selected').val();
83
                    var sel = $('#illfilter_branchname option:selected').val();
84
                    if (sel && sel.length > 0) {
84
                    if (sel && sel.length > 0) {
85
                        activeFilters[me] = function() {
85
                        activeFilters[me] = function() {
86
                            table.api().column(12).search(sel);
86
                            table.api().column(13).search(sel);
87
                        }
87
                        }
88
                    } else {
88
                    } else {
89
                        if (activeFilters.hasOwnProperty(me)) {
89
                        if (activeFilters.hasOwnProperty(me)) {
Lines 103-109 $(document).ready(function() { Link Here
103
                    var val = $('#illfilter_patron').val();
103
                    var val = $('#illfilter_patron').val();
104
                    if (val && val.length > 0) {
104
                    if (val && val.length > 0) {
105
                        activeFilters[me] = function() {
105
                        activeFilters[me] = function() {
106
                            table.api().column(10).search(val);
106
                            table.api().column(11).search(val);
107
                        }
107
                        }
108
                    } else {
108
                    } else {
109
                        if (activeFilters.hasOwnProperty(me)) {
109
                        if (activeFilters.hasOwnProperty(me)) {
(-)a/t/db_dependent/IllbatchStatuses.t (-5 / +12 lines)
Lines 28-34 use t::lib::TestBuilder; Link Here
28
use Test::MockObject;
28
use Test::MockObject;
29
use Test::MockModule;
29
use Test::MockModule;
30
30
31
use Test::More tests => 12;
31
use Test::More tests => 13;
32
32
33
my $schema = Koha::Database->new->schema;
33
my $schema = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
Lines 98-103 is( Link Here
98
    "Creation of status calls log_something"
98
    "Creation of status calls log_something"
99
);
99
);
100
100
101
# Try creating a system status and ensure it's not created
102
my $cannot_create_system = Koha::IllbatchStatus->new({
103
    name => "Jar Jar Binks",
104
    code => "GUNGAN",
105
    is_system => 1
106
});
107
$cannot_create_system->create_and_log;
108
my $created_but_not_system = Koha::IllbatchStatuses->find({ code => "GUNGAN" });
109
is($created_but_not_system->{is_system}, undef, "is_system statuses cannot be created");
110
101
## Status update
111
## Status update
102
112
103
# Ensure only name can be updated
113
# Ensure only name can be updated
Lines 118-136 is( Link Here
118
);
128
);
119
129
120
## Status delete
130
## Status delete
121
122
# Prevent deletion of system statuses
123
my $cannot_delete = Koha::IllbatchStatus->new({
131
my $cannot_delete = Koha::IllbatchStatus->new({
124
    name => "Palapatine",
132
    name => "Palapatine",
125
    code => "SITH",
133
    code => "SITH",
126
    is_system => 1
134
    is_system => 1
127
});
135
})->store;
128
my $can_delete = Koha::IllbatchStatus->new({
136
my $can_delete = Koha::IllbatchStatus->new({
129
    name => "Windu",
137
    name => "Windu",
130
    code => "JEDI",
138
    code => "JEDI",
131
    is_system => 0
139
    is_system => 0
132
});
140
});
133
$cannot_delete->create_and_log;
134
$cannot_delete->delete_and_log;
141
$cannot_delete->delete_and_log;
135
my $not_deleted = Koha::IllbatchStatuses->find({ code => "SITH" });
142
my $not_deleted = Koha::IllbatchStatuses->find({ code => "SITH" });
136
isa_ok( $not_deleted, 'Koha::IllbatchStatus', "is_system statuses cannot be deleted" );
143
isa_ok( $not_deleted, 'Koha::IllbatchStatus', "is_system statuses cannot be deleted" );
(-)a/t/db_dependent/api/v1/illbatches.t (-7 / +25 lines)
Lines 26-31 use t::lib::Mocks; Link Here
26
use Koha::Illbatch;
26
use Koha::Illbatch;
27
use Koha::Illbatches;
27
use Koha::Illbatches;
28
use Koha::Illrequests;
28
use Koha::Illrequests;
29
use Koha::IllbatchStatuses;
29
use Koha::Database;
30
use Koha::Database;
30
31
31
my $schema  = Koha::Database->new->schema;
32
my $schema  = Koha::Database->new->schema;
Lines 200-206 subtest 'get() tests' => sub { Link Here
200
201
201
subtest 'add() tests' => sub {
202
subtest 'add() tests' => sub {
202
203
203
    plan tests =>16;
204
    plan tests =>19;
204
205
205
    $schema->storage->txn_begin;
206
    $schema->storage->txn_begin;
206
207
Lines 230-240 subtest 'add() tests' => sub { Link Here
230
        }
231
        }
231
    );
232
    );
232
233
234
    my $batch_status = $builder->build_object(
235
        {
236
            class => 'Koha::IllbatchStatuses'
237
        }
238
    );
239
233
    my $batch_metadata = {
240
    my $batch_metadata = {
234
        name           => "Anakin's requests",
241
        name           => "Anakin's requests",
235
        backend        => "Mock",
242
        backend        => "Mock",
236
        borrowernumber => $librarian->borrowernumber,
243
        cardnumber     => $librarian->cardnumber,
237
        branchcode     => $branch->branchcode
244
        branchcode     => $branch->branchcode,
245
        statuscode     => $batch_status->code
238
    };
246
    };
239
247
240
    # Unauthorized attempt to write
248
    # Unauthorized attempt to write
Lines 264-272 subtest 'add() tests' => sub { Link Here
264
        ->status_is( 201 )
272
        ->status_is( 201 )
265
        ->json_is( '/name'           => $batch_metadata->{name} )
273
        ->json_is( '/name'           => $batch_metadata->{name} )
266
        ->json_is( '/backend'        => $batch_metadata->{backend} )
274
        ->json_is( '/backend'        => $batch_metadata->{backend} )
267
        ->json_is( '/borrowernumber' => $batch_metadata->{borrowernumber} )
275
        ->json_is( '/borrowernumber' => $librarian->borrowernumber )
268
        ->json_is( '/branchcode'     => $batch_metadata->{branchcode} )
276
        ->json_is( '/branchcode'     => $batch_metadata->{branchcode} )
277
        ->json_is( '/statuscode'     => $batch_status->code )
269
        ->json_has( '/patron' )
278
        ->json_has( '/patron' )
279
        ->json_has( '/status' )
280
        ->json_has( '/requests_count' )
270
        ->json_has( '/branch' );
281
        ->json_has( '/branch' );
271
282
272
    # Authorized attempt to create with null id
283
    # Authorized attempt to create with null id
Lines 316-326 subtest 'update() tests' => sub { Link Here
316
    $t->put_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" => json => { name => 'These are not the droids you are looking for' } )
327
    $t->put_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" => json => { name => 'These are not the droids you are looking for' } )
317
      ->status_is(403);
328
      ->status_is(403);
318
329
330
    my $batch_status = $builder->build_object(
331
        {
332
            class => 'Koha::IllbatchStatuses'
333
        }
334
    );
335
319
    # Attempt partial update on a PUT
336
    # Attempt partial update on a PUT
320
    my $batch_with_missing_field = {
337
    my $batch_with_missing_field = {
321
        backend => "Mock",
338
        backend => "Mock",
322
        borrowernumber => $librarian->borrowernumber,
339
        borrowernumber => $librarian->borrowernumber,
323
        branchcode => $branch->branchcode
340
        branchcode => $branch->branchcode,
341
        statuscode => $batch_status->code
324
    };
342
    };
325
343
326
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_missing_field )
344
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_missing_field )
Lines 334-340 subtest 'update() tests' => sub { Link Here
334
        name           => "Master Ploo Koon",
352
        name           => "Master Ploo Koon",
335
        backend        => "Mock",
353
        backend        => "Mock",
336
        borrowernumber => $librarian->borrowernumber,
354
        borrowernumber => $librarian->borrowernumber,
337
        branchcode => $branch->branchcode
355
        branchcode => $branch->branchcode,
356
        statuscode => $batch_status->code
338
    };
357
    };
339
358
340
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
359
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
341
- 

Return to bug 30719