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.inc (-3 / +4 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 65-71 Link Here
65
                        </div>
65
                        </div>
66
                    </div>
66
                    </div>
67
                    <div id="create-requests" style="display:none">
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>
68
                        <button id="create-requests-button" type="button" class="btn btn-xs btn-primary">Add items to batch</button>
69
                    </div>
69
                    </div>
70
                    <table id="identifier-table" style="display:none">
70
                    <table id="identifier-table" style="display:none">
71
                        <thead>
71
                        <thead>
Lines 74-79 Link Here
74
                                <th scope="col">Identifier value</th>
74
                                <th scope="col">Identifier value</th>
75
                                <th scope="col">Metadata</th>
75
                                <th scope="col">Metadata</th>
76
                                <th scope="col">Request ID</th>
76
                                <th scope="col">Request ID</th>
77
                                <th scope="col">Request Status</th>
77
                                <th scope="col"></th>
78
                                <th scope="col"></th>
78
                            </tr>
79
                            </tr>
79
                        </thead>
80
                        </thead>
(-)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 (-21 / +37 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 21-27 Link Here
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
24
25
    // We need a data structure keyed on identifier type, which tells us how to parse that
30
    // 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
31
    // identifier type and what services can get its metadata. We receive an array of
27
    // available services
32
    // available services
Lines 299-304 Link Here
299
                tableContent.data = tableContent.data.map(function (row) {
304
                tableContent.data = tableContent.data.map(function (row) {
300
                    if (row.value === identifier) {
305
                    if (row.value === identifier) {
301
                        row.requestId = data.illrequest_id;
306
                        row.requestId = data.illrequest_id;
307
                        row.requestStatus = data.status;
302
                    }
308
                    }
303
                    return row;
309
                    return row;
304
                });
310
                });
Lines 512-518 Link Here
512
            })
518
            })
513
        })
519
        })
514
            .then(function (response) {
520
            .then(function (response) {
515
                return response.json();
521
                if ( response.ok ) {
522
                    return response.json();
523
                }
524
                return Promise.reject(response);
516
            })
525
            })
517
            .then(function (body) {
526
            .then(function (body) {
518
                batchId = body.id;
527
                batchId = body.id;
Lines 528-535 Link Here
528
                };
537
                };
529
                initPostCreate();
538
                initPostCreate();
530
            })
539
            })
531
            .catch(function () {
540
            .catch(function (response) {
532
                handleApiError(ill_batch_create_api_fail);
541
                response.json().then((json) => {
542
                    if( json.error ) {
543
                        handleApiError(json.error);
544
                    } else {
545
                        handleApiError(ill_batch_create_api_fail);
546
                    }
547
                })
533
            });
548
            });
534
    };
549
    };
535
550
Lines 893-898 Link Here
893
        return data.requestId || '-';
908
        return data.requestId || '-';
894
    }
909
    }
895
910
911
    function createRequestStatus(x, y, data) {
912
        return data.requestStatus || '-';
913
    }
914
896
    function buildTable(identifiers) {
915
    function buildTable(identifiers) {
897
        table = KohaTable('identifier-table', {
916
        table = KohaTable('identifier-table', {
898
            processing: true,
917
            processing: true,
Lines 918-926 Link Here
918
                },
937
                },
919
                {
938
                {
920
                    data: 'requestId',
939
                    data: 'requestId',
921
                    width: '13%',
940
                    width: '6.5%',
922
                    render: createRequestId
941
                    render: createRequestId
923
                },
942
                },
943
                {
944
                    data: 'requestStatus',
945
                    width: '6.5%',
946
                    render: createRequestStatus
947
                },
924
                {
948
                {
925
                    width: '18%',
949
                    width: '18%',
926
                    render: createActions,
950
                    render: createActions,
Lines 1021-1043 Link Here
1021
    }
1045
    }
1022
1046
1023
    function patronAutocomplete() {
1047
    function patronAutocomplete() {
1024
        // Add autocomplete for patron selection
1048
        patron_autocomplete(
1025
        $('#batch-form #cardnumber').autocomplete({
1049
            $('#batch-form #batchcardnumber'),
1026
            appendTo: '#batch-form',
1050
            {
1027
            source: "/cgi-bin/koha/circ/ysearch.pl",
1051
              'on-select-callback': function( event, ui ) {
1028
            minLength: 3,
1052
                $("#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;
1053
                return false;
1054
              }
1033
            }
1055
            }
1034
        })
1056
          );
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
    };
1057
    };
1042
1058
1043
    function createPatronLink() {
1059
    function createPatronLink() {
(-)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