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

(-)a/Koha/Illbatch.pm (+16 lines)
Lines 20-25 package Koha::Illbatch; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
use Koha::Database;
21
use Koha::Database;
22
use Koha::Illrequest::Logger;
22
use Koha::Illrequest::Logger;
23
use Koha::IllbatchStatus;
23
use JSON qw( to_json );
24
use JSON qw( to_json );
24
use base qw(Koha::Object);
25
use base qw(Koha::Object);
25
26
Lines 29-34 Koha::Illbatch - Koha Illbatch Object class Link Here
29
30
30
=head2 Class methods
31
=head2 Class methods
31
32
33
=head3 status
34
35
    my $status = Koha::Illbatch->status;
36
37
Return the status object associated with this batch
38
39
=cut
40
41
sub status {
42
    my ( $self ) = @_;
43
    return Koha::IllbatchStatus->_new_from_dbic(
44
        scalar $self->_result->statuscode
45
    );
46
}
47
32
=head3 patron
48
=head3 patron
33
49
34
    my $patron = Koha::Illbatch->patron;
50
    my $patron = Koha::Illbatch->patron;
(-)a/Koha/IllbatchStatus.pm (+162 lines)
Line 0 Link Here
1
package Koha::IllbatchStatus;
2
3
# Copyright PTFS Europe 2022
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use Koha::Database;
22
use Koha::Illrequest::Logger;
23
use Koha::Illbatch;
24
use JSON qw( to_json );
25
use base qw(Koha::Object);
26
27
=head1 NAME
28
29
Koha::IllbatchStatus - Koha IllbatchStatus Object class
30
31
=head2 Class methods
32
33
=head3 create_and_log
34
35
    $status->create_and_log;
36
37
Log batch status creation following storage
38
39
=cut
40
41
sub create_and_log {
42
    my ( $self ) = @_;
43
44
    # Ensure code is uppercase and contains only word characters
45
    my $fixed_code = uc $self->code;
46
    $fixed_code =~ s/\W/_/;
47
48
    # Ensure this status doesn't already exist
49
    my $status = Koha::IllbatchStatuses->find({ code => $fixed_code });
50
    if ($status) {
51
        return {
52
            error => "Duplicate status found"
53
        };
54
    }
55
56
    # Ensure system statuses can't be created
57
    $self->set({
58
        code      => $fixed_code,
59
        is_system => 0
60
    })->store;
61
62
    my $logger = Koha::Illrequest::Logger->new;
63
64
    $logger->log_something({
65
        modulename   => 'ILL',
66
        actionname   => 'batch_status_create',
67
        objectnumber => $self->id,
68
        infos        => to_json({})
69
    });
70
}
71
72
=head3 update_and_log
73
74
    $status->update_and_log;
75
76
Log batch status update following storage
77
78
=cut
79
80
sub update_and_log {
81
    my ( $self, $params ) = @_;
82
83
    my $before = {
84
        name => $self->name
85
    };
86
87
    # Ensure only the name can be changed
88
    $self->set({
89
        name => $params->{name}
90
    });
91
    my $update = $self->store;
92
93
    my $after = {
94
        name => $self->name
95
    };
96
97
    my $logger = Koha::Illrequest::Logger->new;
98
99
    $logger->log_something({
100
        modulename   => 'ILL',
101
        actionname  => 'batch_status_update',
102
        objectnumber => $self->id,
103
        infos        => to_json({
104
            before => $before,
105
            after  => $after
106
        })
107
    });
108
}
109
110
=head3 delete_and_log
111
112
    $batch->delete_and_log;
113
114
Log batch status delete
115
116
=cut
117
118
sub delete_and_log {
119
    my ( $self ) = @_;
120
121
    # Don't permit deletion of system statuses
122
    if ($self->is_system) {
123
        return;
124
    }
125
126
    # Update all batches that use this status to have status UNKNOWN
127
    my $affected = Koha::Illbatches->search({ statuscode => $self->code });
128
    $affected->update({ statuscode => 'UNKNOWN'});
129
130
    my $logger = Koha::Illrequest::Logger->new;
131
132
    $logger->log_something({
133
        modulename   => 'ILL',
134
        actionname   => 'batch_status_delete',
135
        objectnumber => $self->id,
136
        infos        => to_json({})
137
    });
138
139
    $self->delete;
140
}
141
142
=head2 Internal methods
143
144
=head3 _type
145
146
    my $type = Koha::IllbatchStatus->_type;
147
148
Return this object's type
149
150
=cut
151
152
sub _type {
153
    return 'IllbatchStatus';
154
}
155
156
=head1 AUTHOR
157
158
Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
159
160
=cut
161
162
1;
(-)a/Koha/IllbatchStatuses.pm (+61 lines)
Line 0 Link Here
1
package Koha::IllbatchStatuses;
2
3
# Copyright PTFS Europe 2022
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use Koha::Database;
22
use Koha::IllbatchStatus;
23
use base qw(Koha::Objects);
24
25
=head1 NAME
26
27
Koha::IllbatchStatuses - Koha IllbatchStatuses Object class
28
29
=head2 Internal methods
30
31
=head3 _type
32
33
    my $type = Koha::IllbatchStatuses->_type;
34
35
Return this object's type
36
37
=cut
38
39
sub _type {
40
    return 'IllbatchStatus';
41
}
42
43
=head3 object_class
44
45
    my $class = Koha::IllbatchStatuses->object_class;
46
47
Return this object's class name
48
49
=cut
50
51
sub object_class {
52
    return 'Koha::IllbatchStatus';
53
}
54
55
=head1 AUTHOR
56
57
Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
58
59
=cut
60
61
1;
(-)a/Koha/REST/V1/IllbatchStatuses.pm (+167 lines)
Line 0 Link Here
1
package Koha::REST::V1::IllbatchStatuses;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::IllbatchStatuses;
23
24
=head1 NAME
25
26
Koha::REST::V1::IllbatchStatuses
27
28
=head2 Operations
29
30
=head3 list
31
32
Return a list of available ILL batch statuses
33
34
=cut
35
36
sub list {
37
    my $c = shift->openapi->valid_input;
38
39
    my @statuses = Koha::IllbatchStatuses->search()->as_list;
40
41
    return $c->render( status => 200, openapi => \@statuses );
42
}
43
44
=head3 get
45
46
Get one batch statuses
47
48
=cut
49
50
sub get {
51
    my $c = shift->openapi->valid_input;
52
53
    my $status_code = $c->validation->param('illbatchstatus_code');
54
55
    my $status = Koha::IllbatchStatuses->find({ code => $status_code });
56
57
    if (not defined $status) {
58
        return $c->render(
59
            status => 404,
60
            openapi => { error => "ILL batch status not found" }
61
        );
62
    }
63
64
    return $c->render(
65
        status => 200,
66
        openapi => {
67
            %{$status->unblessed}
68
        }
69
    );
70
}
71
72
=head3 add
73
74
Add a new batch status
75
76
=cut
77
78
sub add {
79
    my $c = shift->openapi->valid_input or return;
80
81
    my $body = $c->validation->param('body');
82
83
    my $status = Koha::IllbatchStatus->new( $body );
84
85
    return try {
86
        my $return = $status->create_and_log;
87
        if ($return && $return->{error}) {
88
            return $c->render(
89
                status  => 500,
90
                openapi => $return
91
            );
92
        } else {
93
            return $c->render(
94
                status  => 201,
95
                openapi => $status
96
            );
97
        }
98
    }
99
    catch {
100
        $c->unhandled_exception($_);
101
    };
102
}
103
104
=head3 update
105
106
Update a batch status
107
108
=cut
109
110
sub update {
111
    my $c = shift->openapi->valid_input or return;
112
113
    my $status = Koha::IllbatchStatuses->find({ code => $c->validation->param('illbatchstatus_code') });
114
115
    if ( not defined $status ) {
116
        return $c->render(
117
            status  => 404,
118
            openapi => { error => "ILL batch status not found" }
119
        );
120
    }
121
122
    my $params = $c->req->json;
123
124
    return try {
125
        # Only permit updating of name
126
        $status->update_and_log({ name => $params->{name} });
127
128
        return $c->render(
129
            status  => 200,
130
            openapi => $status
131
        );
132
    }
133
    catch {
134
        $c->unhandled_exception($_);
135
    };
136
}
137
138
=head3 delete
139
140
Delete a batch status
141
142
=cut
143
144
sub delete {
145
146
    my $c = shift->openapi->valid_input or return;
147
148
    my $status = Koha::IllbatchStatuses->find({ code => $c->validation->param( 'illbatchstatus_code' ) });
149
150
    if ( not defined $status ) {
151
        return $c->render( status => 404, openapi => { errors => [ { message => "ILL batch status not found" } ] } );
152
    }
153
154
    if ( $status->is_system) {
155
        return $c->render( status => 400, openapi => { errors => [ { message => "ILL batch status cannot be deleted" } ] } );
156
    }
157
158
    return try {
159
        $status->delete_and_log;
160
        return $c->render( status => 204, openapi => '');
161
    }
162
    catch {
163
        $c->unhandled_exception($_);
164
    };
165
}
166
167
1;
(-)a/Koha/REST/V1/Illbatches.pm (-8 / +26 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::Illbatches;
22
use Koha::Illbatches;
23
use Koha::IllbatchStatuses;
23
use Koha::Illrequests;
24
use Koha::Illrequests;
24
25
25
=head1 NAME
26
=head1 NAME
Lines 63-77 sub list { Link Here
63
        branchcode => { -in => \@branchcodes }
64
        branchcode => { -in => \@branchcodes }
64
    });
65
    });
65
66
67
    # Get all batch statuses associated with all our batches
68
    # in one go
69
    my $statuses = {};
70
    foreach my $batch(@batches) {
71
        my $code = $batch->statuscode;
72
        $statuses->{$code} = 1
73
    };
74
    my @statuscodes = keys %{$statuses};
75
    my $status_results = Koha::IllbatchStatuses->search({
76
        code => { -in => \@statuscodes }
77
    });
78
66
    # Populate the response
79
    # Populate the response
67
    my @to_return = ();
80
    my @to_return = ();
68
    foreach my $it_batch(@batches) {
81
    foreach my $it_batch(@batches) {
69
        my $patron = $patron_results->find({ borrowernumber => $it_batch->borrowernumber});
82
        my $patron = $patron_results->find({ borrowernumber => $it_batch->borrowernumber});
70
        my $branch = $branch_results->find({ branchcode => $it_batch->branchcode });
83
        my $branch = $branch_results->find({ branchcode => $it_batch->branchcode });
84
        my $status = $status_results->find({ code => $it_batch->statuscode });
71
        push @to_return, {
85
        push @to_return, {
72
            %{$it_batch->unblessed},
86
            %{$it_batch->unblessed},
73
            patron   => $patron,
87
            patron         => $patron,
74
            branch   => $branch,
88
            branch         => $branch,
89
            status         => $status,
75
            requests_count => $it_batch->requests_count
90
            requests_count => $it_batch->requests_count
76
        };
91
        };
77
    }
92
    }
Lines 103-110 sub get { Link Here
103
        status => 200,
118
        status => 200,
104
        openapi => {
119
        openapi => {
105
            %{$batch->unblessed},
120
            %{$batch->unblessed},
106
            patron => $batch->patron->unblessed,
121
            patron         => $batch->patron->unblessed,
107
            branch => $batch->branch->unblessed,
122
            branch         => $batch->branch->unblessed,
123
            status         => $batch->status->unblessed,
108
            requests_count => $batch->requests_count
124
            requests_count => $batch->requests_count
109
        }
125
        }
110
    );
126
    );
Lines 134-141 sub add { Link Here
134
150
135
        my $ret = {
151
        my $ret = {
136
            %{$batch->unblessed},
152
            %{$batch->unblessed},
137
            patron => $batch->patron->unblessed,
153
            patron           => $batch->patron->unblessed,
138
            branch => $batch->branch->unblessed,
154
            branch           => $batch->branch->unblessed,
155
            status           => $batch->status->unblessed,
139
            requests_count   => 0
156
            requests_count   => 0
140
        };
157
        };
141
158
Lines 175-182 sub update { Link Here
175
192
176
        my $ret = {
193
        my $ret = {
177
            %{$batch->unblessed},
194
            %{$batch->unblessed},
178
            patron => $batch->patron->unblessed,
195
            patron         => $batch->patron->unblessed,
179
            branch => $batch->branch->unblessed,
196
            branch         => $batch->branch->unblessed,
197
            status         => $batch->status->unblessed,
180
            requests_count => $batch->requests_count
198
            requests_count => $batch->requests_count
181
        };
199
        };
182
200
(-)a/admin/ill_batch_statuses.pl (+102 lines)
Line 0 Link Here
1
#! /usr/bin/perl
2
3
# Copyright 2019 Koha Development Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
22
use Try::Tiny qw( catch try );
23
24
use C4::Context;
25
use C4::Auth qw( get_template_and_user );
26
use C4::Output qw( output_html_with_http_headers );
27
28
use Koha::IllbatchStatus;
29
use Koha::IllbatchStatuses;
30
31
my $input = CGI->new;
32
my $code  = $input->param('code');
33
my $op    = $input->param('op') || 'list';
34
my @messages;
35
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
    {
38
        template_name   => "admin/ill_batch_statuses.tt",
39
        query           => $input,
40
        type            => "intranet",
41
        flagsrequired   => { parameters => 'ill' },
42
    }
43
);
44
45
my $status;
46
if ($code) {
47
    $status = Koha::IllbatchStatuses->find({ code => $code });
48
}
49
50
if ( $op eq 'add_form' ) {
51
    if ($status) {
52
        $template->param(
53
            status => $status
54
        );
55
    }
56
}
57
elsif ( $op eq 'add_validate' ) {
58
    my $name = $input->param('name');
59
    my $code = $input->param('code');
60
61
    if ( not defined $status ) {
62
        $status = Koha::IllbatchStatus->new( {
63
            name => $name,
64
            code => $code
65
        } );
66
    }
67
68
    try {
69
        if ($status->id) {
70
            $status->update_and_log({ name => $name });
71
        } else {
72
            $status->create_and_log;
73
        }
74
        push @messages, { type => 'message', code => 'success_on_saving' };
75
    }
76
    catch {
77
        push @messages, { type => 'error', code => 'error_on_saving' };
78
    };
79
    $op = 'list';
80
}
81
elsif ( $op eq 'delete' ) {
82
    try {
83
        $status->delete_and_log;
84
        push @messages, { code => 'success_on_delete', type => 'message' };
85
    }
86
    catch {
87
        push @messages, { code => 'error_on_delete', type => 'alert' };
88
89
    };
90
    $op = 'list';
91
}
92
if ( $op eq 'list' ) {
93
    my $statuses = Koha::IllbatchStatuses->search();
94
    $template->param( statuses => $statuses );
95
}
96
97
$template->param(
98
    messages => \@messages,
99
    op       => $op,
100
);
101
102
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/api/v1/swagger/definitions/illbatch.yaml (-1 / +10 lines)
Lines 29-34 properties: Link Here
29
      - object
29
      - object
30
      - "null"
30
      - "null"
31
    description: The branch associated with the batch
31
    description: The branch associated with the batch
32
  statuscode:
33
    type: string
34
    description: Code of the status of the ILL batch
35
  status:
36
    type:
37
      - object
38
      - "null"
39
    description: The status associated with the batch
32
  requests_count:
40
  requests_count:
33
    type: string
41
    type: string
34
    description: The number of requests in this batch
42
    description: The number of requests in this batch
Lines 36-39 additionalProperties: false Link Here
36
required:
44
required:
37
  - name
45
  - name
38
  - backend
46
  - backend
39
  - branchcode
47
  - branchcode
48
  - statuscode
(-)a/api/v1/swagger/definitions/illbatchstatus.yaml (+20 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  id:
5
    type: string
6
    description: Internal ILL batch status identifier
7
  name:
8
    type: string
9
    description: Status name
10
  code:
11
    type: string
12
    description: Unique, immutable status code
13
  is_system:
14
    type: string
15
    description: Is this status required for system operation
16
additionalProperties: false
17
required:
18
  - name
19
  - code
20
  - is_system
(-)a/api/v1/swagger/definitions/illbatchstatuses.yaml (+5 lines)
Line 0 Link Here
1
---
2
type: array
3
items:
4
  $ref: "illbatchstatus.yaml"
5
additionalProperties: false
(-)a/api/v1/swagger/definitions/illrequest.yaml (+5 lines)
Lines 141-144 properties: Link Here
141
      - string
141
      - string
142
      - "null"
142
      - "null"
143
    description: The timestamp the request was last updated (formatted for display)
143
    description: The timestamp the request was last updated (formatted for display)
144
  due_date:
145
    type:
146
      - string
147
      - "null"
148
    description: The hard due date of an ILL request
144
additionalProperties: false
149
additionalProperties: false
(-)a/api/v1/swagger/paths/illbatchstatuses.yaml (+232 lines)
Line 0 Link Here
1
---
2
/illbatchstatuses:
3
  get:
4
    x-mojo-to: IllbatchStatuses#list
5
    operationId: listIllbatchstatuses
6
    tags:
7
      - illbatchstatuses
8
    summary: List ILL batch statuses
9
    parameters: []
10
    produces:
11
      - application/json
12
    responses:
13
      "200":
14
        description: A list of ILL batch statuses
15
        schema:
16
          $ref: "../swagger.yaml#/definitions/illbatchstatuses"
17
      "401":
18
        description: Authentication required
19
        schema:
20
          $ref: "../swagger.yaml#/definitions/error"
21
      "403":
22
        description: Access forbidden
23
        schema:
24
          $ref: "../swagger.yaml#/definitions/error"
25
      "404":
26
        description: ILL batch statuses not found
27
        schema:
28
          $ref: "../swagger.yaml#/definitions/error"
29
      "500":
30
        description: |
31
          Internal server error. Possible `error_code` attribute values:
32
33
          * `internal_server_error`
34
        schema:
35
          $ref: "../swagger.yaml#/definitions/error"
36
      "503":
37
        description: Under maintenance
38
        schema:
39
          $ref: "../swagger.yaml#/definitions/error"
40
    x-koha-authorization:
41
      permissions:
42
        ill: "1"
43
  post:
44
    x-mojo-to: IllbatchStatuses#add
45
    operationId: addIllbatchstatus
46
    tags:
47
      - illbatchstatuses
48
    summary: Add ILL batch status
49
    parameters:
50
      - name: body
51
        in: body
52
        description: A JSON object containing informations about the new batch status
53
        required: true
54
        schema:
55
          $ref: "../swagger.yaml#/definitions/illbatchstatus"
56
    produces:
57
      - application/json
58
    responses:
59
      "201":
60
        description: Batch status added
61
        schema:
62
          $ref: "../swagger.yaml#/definitions/illbatchstatus"
63
      "400":
64
        description: Bad request
65
        schema:
66
          $ref: "../swagger.yaml#/definitions/error"
67
      "401":
68
        description: Authentication required
69
        schema:
70
          $ref: "../swagger.yaml#/definitions/error"
71
      "403":
72
        description: Access forbidden
73
        schema:
74
          $ref: "../swagger.yaml#/definitions/error"
75
      "409":
76
        description: Conflict in creating resource
77
        schema:
78
          $ref: "../swagger.yaml#/definitions/error"
79
      "500":
80
        description: |
81
          Internal server error. Possible `error_code` attribute values:
82
83
          * `internal_server_error`
84
        schema:
85
          $ref: "../swagger.yaml#/definitions/error"
86
      "503":
87
        description: Under maintenance
88
        schema:
89
          $ref: "../swagger.yaml#/definitions/error"
90
    x-koha-authorization:
91
      permissions:
92
        ill: "1"
93
"/illbatchstatuses/{illbatchstatus_code}":
94
  get:
95
    x-mojo-to: IllbatchStatuses#get
96
    operationId: getIllbatchstatuses
97
    tags:
98
      - illbatchstatuses
99
    summary: Get ILL batch status
100
    parameters:
101
      - name: illbatchstatus_code
102
        in: path
103
        description: ILL batch status
104
        required: true
105
        type: string
106
    produces:
107
      - application/json
108
    responses:
109
      "200":
110
        description: An ILL batch status
111
        schema:
112
          $ref: "../swagger.yaml#/definitions/illbatchstatus"
113
      "401":
114
        description: Authentication required
115
        schema:
116
          $ref: "../swagger.yaml#/definitions/error"
117
      "403":
118
        description: Access forbidden
119
        schema:
120
          $ref: "../swagger.yaml#/definitions/error"
121
      "404":
122
        description: ILL batch status not found
123
        schema:
124
          $ref: "../swagger.yaml#/definitions/error"
125
      "500":
126
        description: |
127
          Internal server error. Possible `error_code` attribute values:
128
129
          * `internal_server_error`
130
        schema:
131
          $ref: "../swagger.yaml#/definitions/error"
132
      "503":
133
        description: Under maintenance
134
        schema:
135
          $ref: "../swagger.yaml#/definitions/error"
136
    x-koha-authorization:
137
      permissions:
138
        ill: "1"
139
  put:
140
    x-mojo-to: IllbatchStatuses#update
141
    operationId: updateIllBatchstatus
142
    tags:
143
      - illbatchstatuses
144
    summary: Update batch status
145
    parameters:
146
      - $ref: "../swagger.yaml#/parameters/illbatchstatus_code_pp"
147
      - name: body
148
        in: body
149
        description: A JSON object containing information on the batch status
150
        required: true
151
        schema:
152
          $ref: "../swagger.yaml#/definitions/illbatchstatus"
153
    consumes:
154
      - application/json
155
    produces:
156
      - application/json
157
    responses:
158
      "200":
159
        description: An ILL batch status
160
        schema:
161
          $ref: "../swagger.yaml#/definitions/illbatchstatus"
162
      "400":
163
        description: Bad request
164
        schema:
165
          $ref: "../swagger.yaml#/definitions/error"
166
      "401":
167
        description: Authentication required
168
        schema:
169
          $ref: "../swagger.yaml#/definitions/error"
170
      "403":
171
        description: Access forbidden
172
        schema:
173
          $ref: "../swagger.yaml#/definitions/error"
174
      "404":
175
        description: ILL batch status not found
176
        schema:
177
          $ref: "../swagger.yaml#/definitions/error"
178
      "500":
179
        description: |
180
          Internal server error. Possible `error_code` attribute values:
181
182
          * `internal_server_error`
183
        schema:
184
          $ref: "../swagger.yaml#/definitions/error"
185
      "503":
186
        description: Under maintenance
187
        schema:
188
          $ref: "../swagger.yaml#/definitions/error"
189
    x-koha-authorization:
190
      permissions:
191
        ill: "1"
192
  delete:
193
    x-mojo-to: IllbatchStatuses#delete
194
    operationId: deleteBatchstatus
195
    tags:
196
      - illbatchstatuses
197
    summary: Delete ILL batch status
198
    parameters:
199
      - $ref: "../swagger.yaml#/parameters/illbatchstatus_code_pp"
200
    produces:
201
      - application/json
202
    responses:
203
      "204":
204
        description: ILL batch status deleted
205
        schema:
206
          type: string
207
      "401":
208
        description: Authentication required
209
        schema:
210
          $ref: "../swagger.yaml#/definitions/error"
211
      "403":
212
        description: Access forbidden
213
        schema:
214
          $ref: "../swagger.yaml#/definitions/error"
215
      "404":
216
        description: ILL batch status not found
217
        schema:
218
          $ref: "../swagger.yaml#/definitions/error"
219
      "500":
220
        description: |
221
          Internal server error. Possible `error_code` attribute values:
222
223
          * `internal_server_error`
224
        schema:
225
          $ref: "../swagger.yaml#/definitions/error"
226
      "503":
227
        description: Under maintenance
228
        schema:
229
          $ref: "../swagger.yaml#/definitions/error"
230
    x-koha-authorization:
231
      permissions:
232
        ill: "1"
(-)a/api/v1/swagger/swagger.yaml (+17 lines)
Lines 52-57 definitions: Link Here
52
    $ref: ./definitions/illbatch.yaml
52
    $ref: ./definitions/illbatch.yaml
53
  illbatches:
53
  illbatches:
54
    $ref: ./definitions/illbatches.yaml
54
    $ref: ./definitions/illbatches.yaml
55
  illbatchstatus:
56
    $ref: ./definitions/illbatchstatus.yaml
57
  illbatchstatuses:
58
    $ref: ./definitions/illbatchstatuses.yaml
55
  illrequest:
59
  illrequest:
56
    $ref: ./definitions/illrequest.yaml
60
    $ref: ./definitions/illrequest.yaml
57
  illrequests:
61
  illrequests:
Lines 237-242 paths: Link Here
237
    $ref: ./paths/illbatches.yaml#/~1illbatches
241
    $ref: ./paths/illbatches.yaml#/~1illbatches
238
  "/illbatches/{illbatch_id}":
242
  "/illbatches/{illbatch_id}":
239
    $ref: "./paths/illbatches.yaml#/~1illbatches~1{illbatch_id}"
243
    $ref: "./paths/illbatches.yaml#/~1illbatches~1{illbatch_id}"
244
  /illbatchstatuses:
245
    $ref: ./paths/illbatchstatuses.yaml#/~1illbatchstatuses
246
  "/illbatchstatuses/{illbatchstatus_code}":
247
    $ref: "./paths/illbatchstatuses.yaml#/~1illbatchstatuses~1{illbatchstatus_code}"
240
  /illrequests:
248
  /illrequests:
241
    $ref: ./paths/illrequests.yaml#/~1illrequests
249
    $ref: ./paths/illrequests.yaml#/~1illrequests
242
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
250
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
Lines 438-443 parameters: Link Here
438
    name: illbatch_id
446
    name: illbatch_id
439
    required: true
447
    required: true
440
    type: integer
448
    type: integer
449
  illbatchstatus_code_pp:
450
    description: Internal ILL batch status identifier
451
    in: path
452
    name: illbatchstatus_code
453
    required: true
454
    type: string
441
  import_batch_profile_id_pp:
455
  import_batch_profile_id_pp:
442
    description: Internal profile identifier
456
    description: Internal profile identifier
443
    in: path
457
    in: path
Lines 734-739 tags: Link Here
734
  - description: "Manage ILL module batches\n"
748
  - description: "Manage ILL module batches\n"
735
    name: illbatches
749
    name: illbatches
736
    x-displayName: ILL batches
750
    x-displayName: ILL batches
751
  - description: "Manage ILL module batch statuses\n"
752
    name: illbatchstatuses
753
    x-displayName: ILL batch statuses
737
  - description: "Manage ILL requests\n"
754
  - description: "Manage ILL requests\n"
738
    name: illrequests
755
    name: illrequests
739
    x-displayName: ILL requests
756
    x-displayName: ILL requests
(-)a/ill/ill-requests.pl (-2 / +4 lines)
Lines 28-33 use Koha::AuthorisedValues; Link Here
28
use Koha::Illcomment;
28
use Koha::Illcomment;
29
use Koha::Illrequests;
29
use Koha::Illrequests;
30
use Koha::Illbatches;
30
use Koha::Illbatches;
31
use Koha::IllbatchStatuses;
31
use Koha::Illrequest::Availability;
32
use Koha::Illrequest::Availability;
32
use Koha::Libraries;
33
use Koha::Libraries;
33
use Koha::Token;
34
use Koha::Token;
Lines 454-461 if ( $backends_available ) { Link Here
454
        );
455
        );
455
        exit;
456
        exit;
456
    } elsif ( $op eq "batch_list" ) {
457
    } elsif ( $op eq "batch_list" ) {
458
        # Do not remove, it prevents us falling through to the 'else'
457
    } elsif ( $op eq "batch_create" ) {
459
    } elsif ( $op eq "batch_create" ) {
458
        # Batch create
460
        # Do not remove, it prevents us falling through to the 'else'
459
    } else {
461
    } else {
460
        my $request = Koha::Illrequests->find($params->{illrequest_id});
462
        my $request = Koha::Illrequests->find($params->{illrequest_id});
461
        my $backend_result = $request->custom_capability($op, $params);
463
        my $backend_result = $request->custom_capability($op, $params);
Lines 567-570 sub get_ill_availability { Link Here
567
    return $availability->get_services({
569
    return $availability->get_services({
568
        ui_context => 'staff'
570
        ui_context => 'staff'
569
    });
571
    });
570
}
572
}
(-)a/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl (-1 / +17 lines)
Lines 7-22 return { Link Here
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        $dbh->do(q{
9
        $dbh->do(q{
10
            CREATE TABLE `illbatches` (
10
            CREATE TABLE IF NOT EXISTS `illbatches` (
11
                `id` int(11) NOT NULL auto_increment, -- Batch ID
11
                `id` int(11) NOT NULL auto_increment, -- Batch ID
12
                `name` varchar(100) NOT NULL,         -- Unique name of batch
12
                `name` varchar(100) NOT NULL,         -- Unique name of batch
13
                `backend` varchar(20) NOT NULL,       -- Name of batch backend
13
                `backend` varchar(20) NOT NULL,       -- Name of batch backend
14
                `borrowernumber` int(11),             -- Patron associated with batch
14
                `borrowernumber` int(11),             -- Patron associated with batch
15
                `branchcode` varchar(50),             -- Branch associated with batch
15
                `branchcode` varchar(50),             -- Branch associated with batch
16
                `statuscode` varchar(20),             -- Status of batch
16
                PRIMARY KEY (`id`),
17
                PRIMARY KEY (`id`),
17
                UNIQUE KEY `u_illbatches__name` (`name`)
18
                UNIQUE KEY `u_illbatches__name` (`name`)
18
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
19
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
19
        });
20
        });
21
        $dbh->do(q{
22
            CREATE TABLE IF NOT EXISTS `illbatch_statuses` (
23
                `id` int(11) NOT NULL auto_increment, -- Status ID
24
                `name` varchar(100) NOT NULL,         -- Name of status
25
                `code` varchar(20) NOT NULL,          -- Unique, immutable code for status
26
                `is_system` int(1),                   -- Is this status required for system operation
27
                PRIMARY KEY (`id`),
28
                UNIQUE KEY `u_illbatchstatuses__code` (`code`)
29
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
30
        });
20
        $dbh->do(q{
31
        $dbh->do(q{
21
            ALTER TABLE `illrequests`
32
            ALTER TABLE `illrequests`
22
                ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to
33
                ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to
Lines 33-38 return { Link Here
33
            ALTER TABLE `illbatches`
44
            ALTER TABLE `illbatches`
34
                ADD CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
45
                ADD CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
35
        });
46
        });
47
        $dbh->do(q{
48
            ALTER TABLE `illbatches`
49
                ADD CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
50
        });
51
36
        say $out "Bug 30719: Add ILL batches completed"
52
        say $out "Bug 30719: Add ILL batches completed"
37
    },
53
    },
38
};
54
};
(-)a/installer/data/mysql/kohastructure.sql (-1 / +15 lines)
Lines 3226-3231 CREATE TABLE `illrequestattributes` ( Link Here
3226
  CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE
3226
  CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE
3227
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3227
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3228
/*!40101 SET character_set_client = @saved_cs_client */;
3228
/*!40101 SET character_set_client = @saved_cs_client */;
3229
--
3230
-- Table structure for table `illbatch_statuses`
3231
--
3232
DROP TABLE IF EXISTS `illbatch_statuses`;
3233
CREATE TABLE `illbatch_statuses` (
3234
    `id` int(11) NOT NULL auto_increment, -- Status ID
3235
    `name` varchar(100) NOT NULL,         -- Name of status
3236
    `code` varchar(20) NOT NULL,          -- Unique, immutable code for status
3237
    `is_system` int(1),                   -- Is this status required for system operation
3238
    PRIMARY KEY (`id`),
3239
    UNIQUE KEY `u_illbatchstatuses__code` (`code`)
3240
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3229
3241
3230
--
3242
--
3231
-- Table structure for table `illbatches`
3243
-- Table structure for table `illbatches`
Lines 3237-3246 CREATE TABLE `illbatches` ( Link Here
3237
    `backend` varchar(20) NOT NULL,       -- Name of batch backend
3249
    `backend` varchar(20) NOT NULL,       -- Name of batch backend
3238
    `borrowernumber` int(11),             -- Patron associated with batch
3250
    `borrowernumber` int(11),             -- Patron associated with batch
3239
    `branchcode` varchar(50),             -- Branch associated with batch
3251
    `branchcode` varchar(50),             -- Branch associated with batch
3252
    `statuscode` varchar(20),             -- Status of batch
3240
    PRIMARY KEY (`id`),
3253
    PRIMARY KEY (`id`),
3241
    UNIQUE KEY `u_illbatches__name` (`name`),
3254
    UNIQUE KEY `u_illbatches__name` (`name`),
3242
    CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3255
    CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3243
    CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
3256
    CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
3257
    CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
3244
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3258
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3245
3259
3246
--
3260
--
(-)a/installer/data/mysql/mandatory/illbatch_statuses.sql (+5 lines)
Line 0 Link Here
1
INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES
2
('New', 'NEW', 1),
3
('In progress', 'IN_PROGRESS', 1),
4
('Completed', 'COMPLETED', 1),
5
('Unknown', 'UNKNOWN', 1);
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (+3 lines)
Lines 177-182 Link Here
177
            [% IF ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts ) %]
177
            [% IF ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts ) %]
178
                <li><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></li>
178
                <li><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></li>
179
            [% END %]
179
            [% END %]
180
            [% IF Koha.Preference('ILLModule ') && CAN_user_ill %]
181
                <li><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a></li>
182
            [% END %]
180
        </ul>
183
        </ul>
181
    [% END %]
184
    [% END %]
182
</div>
185
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal-strings.inc (+1 lines)
Lines 5-10 Link Here
5
    var ill_batch_none = _("None");
5
    var ill_batch_none = _("None");
6
    var ill_batch_retrieving_metadata = _("Retrieving metadata");
6
    var ill_batch_retrieving_metadata = _("Retrieving metadata");
7
    var ill_batch_api_fail = _("Unable to retrieve batch details");
7
    var ill_batch_api_fail = _("Unable to retrieve batch details");
8
    var ill_batch_statuses_api_fail = _("Unable to retrieve batch statuses");
8
    var ill_batch_api_request_fail = _("Unable to create local request");
9
    var ill_batch_api_request_fail = _("Unable to create local request");
9
    var ill_batch_requests_api_fail = _("Unable to retrieve batch requests");
10
    var ill_batch_requests_api_fail = _("Unable to retrieve batch requests");
10
    var ill_batch_unknown = _("Unknown");
11
    var ill_batch_unknown = _("Unknown");
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal.inc (+4 lines)
Lines 28-33 Link Here
28
                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
28
                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
29
                                    </select>
29
                                    </select>
30
                                </li>
30
                                </li>
31
                                <li id="batch_statuscode" style="display:none">
32
                                    <label class="required" for="statuscode">Status:</label>
33
                                    <select id="statuscode" name="statuscode"></select>
34
                                </li>
31
                            </ol>
35
                            </ol>
32
                        </fieldset>
36
                        </fieldset>
33
                        <fieldset id="add_batch_items" class="rows" style="display:none">
37
                        <fieldset id="add_batch_items" class="rows" style="display:none">
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch.inc (-2 / +1 lines)
Lines 6-11 Link Here
6
                <th scope="col">Batch ID</th>
6
                <th scope="col">Batch ID</th>
7
                <th scope="col">Name</th>
7
                <th scope="col">Name</th>
8
                <th scope="col">Number of requests</th>
8
                <th scope="col">Number of requests</th>
9
                <th scope="col">Status</th>
9
                <th scope="col">Patron</th>
10
                <th scope="col">Patron</th>
10
                <th scope="col">Branch</th>
11
                <th scope="col">Branch</th>
11
                <th scope="col"></th>
12
                <th scope="col"></th>
Lines 15-20 Link Here
15
        </tbody>
16
        </tbody>
16
    </table>
17
    </table>
17
</div>
18
</div>
18
[% ELSIF query_type == "batch_create" %]
19
20
[% END %]
19
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-toolbar.inc (-1 / +1 lines)
Lines 1-5 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% IF Koha.Preference('ILLModule ') && CAN_user_ill %]
2
[% IF Koha.Preference('ILLModule') && CAN_user_ill %]
3
    <div id="toolbar" class="btn-toolbar ill-toolbar">
3
    <div id="toolbar" class="btn-toolbar ill-toolbar">
4
        [% IF backends_available %]
4
        [% IF backends_available %]
5
          [% IF backends.size > 1 %]
5
          [% IF backends.size > 1 %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+4 lines)
Lines 287-292 Link Here
287
                        <dt><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></dt>
287
                        <dt><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></dt>
288
                        <dd>Define which keys trigger actions in the advanced cataloging editor</dd>
288
                        <dd>Define which keys trigger actions in the advanced cataloging editor</dd>
289
                    [% END %]
289
                    [% END %]
290
                    [% IF Koha.Preference('ILLModule') && CAN_user_ill %]
291
                        <dt><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a></dt>
292
                        <dd>Manage the statuses that can be assigned to Interlibrary Loan batches</dd>
293
                    [% END %]
290
                </dl>
294
                </dl>
291
            [% END %]
295
            [% END %]
292
            </div>
296
            </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/ill_batch_statuses.tt (+168 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Branches %]
4
[% USE Price %]
5
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
<title>
8
    [% IF op =='add_form' %]
9
       [% IF status.id %]
10
           Modify batch status
11
       [% ELSE %]
12
           New batch status
13
       [% END %] &rsaquo; [% END %]
14
    Interlibrary Loan batch statuses &rsaquo; Administration &rsaquo; Koha
15
</title>
16
[% INCLUDE 'doc-head-close.inc' %]
17
</head>
18
19
<body id="admin_ill_batch_statuses" class="admin">
20
[% INCLUDE 'header.inc' %]
21
[% INCLUDE 'prefs-admin-search.inc' %]
22
23
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
24
    <ol>
25
        <li>
26
            <a href="/cgi-bin/koha/mainpage.pl">Home</a>
27
        </li>
28
        <li>
29
            <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
30
        </li>
31
32
        [% IF op == 'add_form' %]
33
            <li>
34
                <a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a>
35
            </li>
36
            <li>
37
                <a href="#" aria-current="page">
38
                    [% IF status.id %]
39
                        Modify
40
                    [% ELSE %]
41
                        New
42
                    [% END %] batch status
43
                </a>
44
            </li>
45
46
        [% ELSE %]
47
            <li>
48
                <a href="#" aria-current="page">
49
                    Interlibrary Loan batch statuses
50
                </a>
51
            </li>
52
        [% END %]
53
    </ol>
54
</nav>
55
56
<div class="main container-fluid">
57
    <div class="row">
58
        <div class="col-sm-10 col-sm-push-2">
59
            <main>
60
61
                [% FOREACH m IN messages %]
62
                <div class="dialog [% m.type | html %]">
63
                    [% SWITCH m.code %]
64
                    [% CASE 'success_on_saving' %]
65
                        <span>Batch status saved successfully</span>
66
                    [% CASE 'success_on_delete' %]
67
                        <span>Batch status deleted successfully</span>
68
                    [% CASE 'error_on_saving' %]
69
                        <span>An error occurred when saving this batch status</span>
70
                    [% CASE 'error_on_delete' %]
71
                        <span>An error occurred when deleting this batch status</span>
72
                    [% CASE %]
73
                        <span>[% m.code | html %]</span>
74
                    [% END %]
75
                </div>
76
                [% END %]
77
78
                [% IF op == 'add_form' %]
79
                    [% IF status %]
80
                        <h1>Modify a batch status</h1>
81
                    [% ELSE %]
82
                        <h1>New batch status</h1>
83
                    [% END %]
84
85
                    <form action="/cgi-bin/koha/admin/ill_batch_statuses.pl" name="Aform" method="post" class="validated">
86
                        <input type="hidden" name="op" value="add_validate" />
87
                        <fieldset class="rows">
88
                            <ol>
89
                                <li>
90
                                    <label for="name" class="required">Name: </label>
91
                                    <input type="text" name="name" id="name" size="80" maxlength="100" class="required focus" required="required" value="[% status.name | html %]"><span class="required">Required. Maximum length is 100 letters</span>
92
                                </li>
93
                                <li>
94
                                    <label for="code">Code: </label>
95
                                    [% IF status %]
96
                                        <strong>[% status.code | html %]</strong>
97
                                        <input type="hidden" name="code" value="[% status.code | html %]" />
98
                                    [% ELSE %]
99
                                    <input type="text" name="code" id="code" size="80" maxlength="20" class="required" required="required" value="[% status.code | html %]"><span class="required">Required, specify UPPERCASE LETTERS. Maximum length is 20 letters</span>
100
                                    [% END %]
101
                                </li>
102
                                <li>
103
                                    <label for="is_system">Is a system status: </label>
104
                                    <strong>[% status.is_system ? "Yes" : "No" | html %]</strong>
105
                                    <input type="hidden" name="is_system" value="[% status.is_system | html %]" />
106
                                </li>
107
                            </ol>
108
                        </fieldset>
109
110
                        <fieldset class="action">
111
                            <button id="save_batch_status" class="btn btn-default">Save</button>
112
                            <a class="cancel" href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Cancel</a>
113
                        </fieldset>
114
                    </form>
115
                [% END %]
116
117
                [% IF op == 'list' %]
118
                    <div id="toolbar" class="btn-toolbar">
119
                        <a class="btn btn-default" id="newillbatchstatus" href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=add_form"><i class="fa fa-plus"></i> New batch status</a>
120
                    </div>
121
122
                    <h1>Interlibrary Loan batch statuses</h1>
123
                    [% IF statuses.count %]
124
                        <table id="table_batch_statuses">
125
                            <thead>
126
                                <th>Name</th>
127
                                <th>Code</th>
128
                                <th>Is system</th>
129
                                <th class="noExport">Actions</th>
130
                            </thead>
131
                            <tbody>
132
                                [% FOREACH status IN statuses %]
133
                                <tr>
134
                                    <td>[% status.name | html %]</td>
135
                                    <td>[% name.code | html %]</td>
136
                                    <td>[% status.is_system ? "Yes" : "No" | html %]</td>
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>
139
                                        [% IF !status.is_system %]
140
                                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=delete&amp;code=[% status.code | uri %]"><i class="fa fa-delete"></i> Delete</a>
141
                                        [% END %]
142
                                    </td>
143
                                </tr>
144
                                [% END %]
145
                            </tbody>
146
                        </table>
147
                    [% ELSE %]
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>
150
                        </div>
151
                    [% END %]
152
                [% END %]
153
            </main>
154
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
155
156
        <div class="col-sm-2 col-sm-pull-10">
157
            <aside>
158
                [% INCLUDE 'admin-menu.inc' %]
159
            </aside>
160
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
161
    </div> <!-- /.row -->
162
163
[% MACRO jsinclude BLOCK %]
164
    [% Asset.js("js/admin-menu.js") | $raw %]
165
    [% INCLUDE 'datatables.inc' %]
166
[% END %]
167
168
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (-2 / +4 lines)
Lines 877-886 Link Here
877
    <script>
877
    <script>
878
        var metadata_enrichment_services = [% metadata_enrichment_services | $raw %];
878
        var metadata_enrichment_services = [% metadata_enrichment_services | $raw %];
879
    </script>
879
    </script>
880
    [% END %]
881
    [% IF batch_availability_services %]
882
    <script>
880
    <script>
881
        [% IF batch_availability_services %]
883
        var batch_availability_services = [% batch_availability_services | $raw %];
882
        var batch_availability_services = [% batch_availability_services | $raw %];
883
        [% ELSE %]
884
        var batch_availability_services = [];
885
        [% END %]
884
    </script>
886
    </script>
885
    [% END %]
887
    [% END %]
886
    <script>
888
    <script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js (-8 / +70 lines)
Lines 19-24 Link Here
19
    var createProgressBar = document.getElementById("processed_progress_bar");
19
    var createProgressBar = document.getElementById("processed_progress_bar");
20
    var identifierTable = document.getElementById('identifier-table');
20
    var identifierTable = document.getElementById('identifier-table');
21
    var createRequestsButton = document.getElementById('create-requests-button');
21
    var createRequestsButton = document.getElementById('create-requests-button');
22
    var statusesSelect = document.getElementById('statuscode');
22
23
23
24
24
    // We need a data structure keyed on identifier type, which tells us how to parse that
25
    // We need a data structure keyed on identifier type, which tells us how to parse that
Lines 40-46 Link Here
40
        name: '',
41
        name: '',
41
        backend: null,
42
        backend: null,
42
        cardnumber: '',
43
        cardnumber: '',
43
        branchcode: ''
44
        branchcode: '',
45
        statuscode: 'NEW'
44
    };
46
    };
45
47
46
    // The object that holds the batch we're working with
48
    // The object that holds the batch we're working with
Lines 59-64 Link Here
59
                setFinishButton();
61
                setFinishButton();
60
                disableCardnumberInput();
62
                disableCardnumberInput();
61
                displayPatronName();
63
                displayPatronName();
64
                updateStatusesSelect();
62
            }
65
            }
63
        }
66
        }
64
    );
67
    );
Lines 82-87 Link Here
82
        }
85
        }
83
    );
86
    );
84
87
88
    // The object that holds the contents of the table
89
    // It's a proxy so we can update portions of the UI
90
    // upon changes
91
    var statuses = new Proxy(
92
        { data: [] },
93
        {
94
            get: function (obj, prop) {
95
                return obj[prop];
96
            },
97
            set: function (obj, prop, value) {
98
                obj[prop] = value;
99
                updateStatusesSelect();
100
            }
101
        }
102
    );
103
85
    var progressTotals = new Proxy(
104
    var progressTotals = new Proxy(
86
        {
105
        {
87
            data: {}
106
            data: {}
Lines 105-110 Link Here
105
    // so we don't duplicate them
124
    // so we don't duplicate them
106
    var availabilitySent = {};
125
    var availabilitySent = {};
107
126
127
    // Are we updating an existing batch
128
    var isUpdate = false;
129
108
    // The datatable
130
    // The datatable
109
    var table;
131
    var table;
110
    var tableEl = document.getElementById('identifier-table');
132
    var tableEl = document.getElementById('identifier-table');
Lines 155-165 Link Here
155
        };
177
        };
156
        if (batchId) {
178
        if (batchId) {
157
            fetchBatch();
179
            fetchBatch();
158
            setModalHeading(true);
180
            isUpdate = true;
181
            setModalHeading();
159
        } else {
182
        } else {
160
            batch.data = emptyBatch;
183
            batch.data = emptyBatch;
161
            setModalHeading();
184
            setModalHeading();
162
        }
185
        }
186
        fetchStatuses();
163
        finishButtonEventListener();
187
        finishButtonEventListener();
164
        processButtonEventListener();
188
        processButtonEventListener();
165
        identifierTextareaEventListener();
189
        identifierTextareaEventListener();
Lines 178-184 Link Here
178
        }
202
        }
179
    };
203
    };
180
204
181
    function setModalHeading(isUpdate) {
205
    function setModalHeading() {
182
        var heading = document.getElementById('ill-batch-modal-label');
206
        var heading = document.getElementById('ill-batch-modal-label');
183
        heading.textContent = isUpdate ? ill_batch_update : ill_batch_add;
207
        heading.textContent = isUpdate ? ill_batch_update : ill_batch_add;
184
    }
208
    }
Lines 323-328 Link Here
323
        }
347
        }
324
    };
348
    };
325
349
350
    function updateStatusesSelect() {
351
        while (statusesSelect.options.length > 0) {
352
            statusesSelect.remove(0);
353
        }
354
        statuses.data.forEach(function (status) {
355
            var option = document.createElement('option')
356
            option.value = status.code;
357
            option.text = status.name;
358
            if (batch.data.id && batch.data.statuscode === status.code) {
359
                option.selected = true;
360
            }
361
            statusesSelect.add(option);
362
        });
363
        if (isUpdate) {
364
            statusesSelect.parentElement.style.display = 'block';
365
        }
366
    };
367
326
    function removeEventListeners() {
368
    function removeEventListeners() {
327
        textarea.removeEventListener('paste', processButtonState);
369
        textarea.removeEventListener('paste', processButtonState);
328
        textarea.removeEventListener('keyup', processButtonState);
370
        textarea.removeEventListener('keyup', processButtonState);
Lines 414-419 Link Here
414
            });
456
            });
415
    };
457
    };
416
458
459
    // Get all batch statuses
460
    function fetchStatuses() {
461
        window.doApiRequest('/api/v1/illbatchstatuses')
462
            .then(function (response) {
463
                return response.json();
464
            })
465
            .then(function (jsoned) {
466
                statuses.data = jsoned;
467
            })
468
            .catch(function (e) {
469
                window.handleApiError(ill_batch_statuses_api_fail);
470
            });
471
    };
472
417
    // Get the batch
473
    // Get the batch
418
    function fetchBatch() {
474
    function fetchBatch() {
419
        window.doBatchApiRequest("/" + batchId)
475
        window.doBatchApiRequest("/" + batchId)
Lines 426-432 Link Here
426
                    name: jsoned.name,
482
                    name: jsoned.name,
427
                    backend: jsoned.backend,
483
                    backend: jsoned.backend,
428
                    cardnumber: jsoned.cardnumber,
484
                    cardnumber: jsoned.cardnumber,
429
                    branchcode: jsoned.branchcode
485
                    branchcode: jsoned.branchcode,
486
                    statuscode: jsoned.statuscode
430
                }
487
                }
431
                return jsoned;
488
                return jsoned;
432
            })
489
            })
Lines 436-446 Link Here
436
            .catch(function () {
493
            .catch(function () {
437
                window.handleApiError(ill_batch_api_fail);
494
                window.handleApiError(ill_batch_api_fail);
438
            });
495
            });
439
440
    };
496
    };
441
497
442
    function createBatch() {
498
    function createBatch() {
443
        var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
499
        var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
500
        var selectedStatuscode = statusesSelect.selectedOptions[0].value;
444
        return doBatchApiRequest('', {
501
        return doBatchApiRequest('', {
445
            method: 'POST',
502
            method: 'POST',
446
            headers: {
503
            headers: {
Lines 450-456 Link Here
450
                name: nameInput.value,
507
                name: nameInput.value,
451
                backend: backend,
508
                backend: backend,
452
                cardnumber: cardnumberInput.value,
509
                cardnumber: cardnumberInput.value,
453
                branchcode: selectedBranchcode
510
                branchcode: selectedBranchcode,
511
                statuscode: selectedStatuscode
454
            })
512
            })
455
        })
513
        })
456
            .then(function (response) {
514
            .then(function (response) {
Lines 464-470 Link Here
464
                    backend: body.backend,
522
                    backend: body.backend,
465
                    cardnumber: body.patron.cardnumber,
523
                    cardnumber: body.patron.cardnumber,
466
                    branchcode: body.branchcode,
524
                    branchcode: body.branchcode,
467
                    patron: body.patron
525
                    statuscode: body.statuscode,
526
                    patron: body.patron,
527
                    status: body.status
468
                };
528
                };
469
                initPostCreate();
529
                initPostCreate();
470
            })
530
            })
Lines 475-480 Link Here
475
535
476
    function updateBatch() {
536
    function updateBatch() {
477
        var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
537
        var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
538
        var selectedStatuscode = statusesSelect.selectedOptions[0].value;
478
        return doBatchApiRequest('/' + batch.data.id, {
539
        return doBatchApiRequest('/' + batch.data.id, {
479
            method: 'PUT',
540
            method: 'PUT',
480
            headers: {
541
            headers: {
Lines 484-490 Link Here
484
                name: nameInput.value,
545
                name: nameInput.value,
485
                backend: batch.data.backend,
546
                backend: batch.data.backend,
486
                cardnumber: batch.data.patron.cardnumber,
547
                cardnumber: batch.data.patron.cardnumber,
487
                branchcode: selectedBranchcode
548
                branchcode: selectedBranchcode,
549
                statuscode: selectedStatuscode
488
            })
550
            })
489
        })
551
        })
490
            .catch(function () {
552
            .catch(function () {
(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-table.js (-2 / +12 lines)
Lines 57-66 Link Here
57
                    data: 'requests_count',
57
                    data: 'requests_count',
58
                    width: '10%'
58
                    width: '10%'
59
                },
59
                },
60
                {
61
                    data: 'status',
62
                    render: createStatus,
63
                    width: '10%'
64
                },
60
                {
65
                {
61
                    data: 'patron',
66
                    data: 'patron',
62
                    render: createPatronLink,
67
                    render: createPatronLink,
63
                    width: '20%'
68
                    width: '10%'
64
                },
69
                },
65
                {
70
                {
66
                    data: 'branch',
71
                    data: 'branch',
Lines 82-88 Link Here
82
    // A render function for branch name
87
    // A render function for branch name
83
    var createBranch = function (data) {
88
    var createBranch = function (data) {
84
        return data.branchname;
89
        return data.branchname;
85
    }
90
    };
86
91
87
    // A render function for batch name
92
    // A render function for batch name
88
    var createName = function (x, y, data) {
93
    var createName = function (x, y, data) {
Lines 93-98 Link Here
93
        return a.outerHTML;
98
        return a.outerHTML;
94
    };
99
    };
95
100
101
    // A render function for batch status
102
    var createStatus = function (x, y, data) {
103
        return data.status.name;
104
    };
105
96
    // A render function for our patron link
106
    // A render function for our patron link
97
    var createPatronLink = function (data) {
107
    var createPatronLink = function (data) {
98
        var link = document.createElement('a');
108
        var link = document.createElement('a');
(-)a/t/db_dependent/IllbatchStatuses.t (+176 lines)
Line 0 Link Here
1
#s!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use File::Basename qw/basename/;
21
use Koha::Database;
22
use Koha::IllbatchStatus;
23
use Koha::IllbatchStatuses;
24
use Koha::Patrons;
25
use Koha::Libraries;
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
use Test::MockObject;
29
use Test::MockModule;
30
31
use Test::More tests => 12;
32
33
my $schema = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
35
use_ok('Koha::IllbatchStatus');
36
use_ok('Koha::IllbatchStatuses');
37
38
$schema->storage->txn_begin;
39
40
Koha::IllbatchStatuses->search->delete;
41
42
# Keep track of whether our CRUD logging side-effects are happening
43
my $effects = {
44
    batch_status_create => 0,
45
    batch_status_update => 0,
46
    batch_status_delete => 0
47
};
48
49
# Mock a logger so we can check it is called
50
my $logger = Test::MockModule->new('Koha::Illrequest::Logger');
51
$logger->mock('log_something', sub {
52
    my ($self, $to_log ) = @_;
53
    $effects->{$to_log->{actionname}} ++;
54
});
55
56
# Create a batch status
57
my $status = $builder->build({
58
    source => 'IllbatchStatus',
59
    value => {
60
        name      => "Feeling the call to the Dark Side",
61
        code      => "OH_NO",
62
        is_system => 1
63
    }
64
});
65
66
my $status_obj = Koha::IllbatchStatuses->find({ code => $status->{code} });
67
isa_ok( $status_obj, 'Koha::IllbatchStatus' );
68
69
# Try to delete the status, it's a system status, so this should fail
70
$status_obj->delete_and_log;
71
my $status_obj_del = Koha::IllbatchStatuses->find({ code => $status->{code} });
72
isa_ok( $status_obj_del, 'Koha::IllbatchStatus' );
73
74
## Status create
75
76
# Try creating a duplicate status
77
my $status2 = Koha::IllbatchStatus->new({
78
    name => "Obi-wan",
79
    code => $status->{code},
80
    is_system => 0
81
});
82
is_deeply(
83
    $status2->create_and_log,
84
    { error => "Duplicate status found" },
85
    "Creation of statuses with duplicate codes prevented"
86
);
87
88
# Create a non-duplicate status and ensure that the logger is called
89
my $status3 = Koha::IllbatchStatus->new({
90
    name => "Kylo",
91
    code => "DARK_SIDE",
92
    is_system => 0
93
});
94
$status3->create_and_log;
95
is(
96
    $effects->{'batch_status_create'},
97
    1,
98
    "Creation of status calls log_something"
99
);
100
101
## Status update
102
103
# Ensure only name can be updated
104
$status3->update_and_log({
105
    name      => "Rey",
106
    code      => "LIGHT_SIDE",
107
    is_system => 1
108
});
109
# Get our updated status, if we can get it by it's code, we know that hasn't changed
110
my $not_updated = Koha::IllbatchStatuses->find({ code => "DARK_SIDE" })->unblessed;
111
is($not_updated->{is_system}, 0, "is_system cannot be changed");
112
is($not_updated->{name}, "Rey", "name can be changed");
113
# Ensure the logger is called
114
is(
115
    $effects->{'batch_status_update'},
116
    1,
117
    "Update of status calls log_something"
118
);
119
120
## Status delete
121
122
# Prevent deletion of system statuses
123
my $cannot_delete = Koha::IllbatchStatus->new({
124
    name => "Palapatine",
125
    code => "SITH",
126
    is_system => 1
127
});
128
my $can_delete = Koha::IllbatchStatus->new({
129
    name => "Windu",
130
    code => "JEDI",
131
    is_system => 0
132
});
133
$cannot_delete->create_and_log;
134
$cannot_delete->delete_and_log;
135
my $not_deleted = Koha::IllbatchStatuses->find({ code => "SITH" });
136
isa_ok( $not_deleted, 'Koha::IllbatchStatus', "is_system statuses cannot be deleted" );
137
$can_delete->create_and_log;
138
$can_delete->delete_and_log;
139
# Ensure the logger is called following a successful delete
140
is(
141
    $effects->{'batch_status_delete'},
142
    1,
143
    "Delete of status calls log_something"
144
);
145
146
# Create a system "UNKNOWN" status
147
my $status_unknown = Koha::IllbatchStatus->new({
148
    name => "Unknown",
149
    code => "UNKNOWN",
150
    is_system => 1
151
});
152
$status_unknown->create_and_log;
153
# Create a batch and assign it a status
154
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
155
my $library = $builder->build_object({ class => 'Koha::Libraries' });
156
my $status5 = Koha::IllbatchStatus->new({
157
    name => "Plagueis",
158
    code => "DEAD_SITH",
159
    is_system => 0
160
});
161
$status5->create_and_log;
162
my $batch = Koha::Illbatch->new({
163
    name           => "My test batch",
164
    borrowernumber => $patron->borrowernumber,
165
    branchcode     => $library->branchcode,
166
    backend        => "TEST",
167
    statuscode     => $status5->code
168
});
169
$batch->create_and_log;
170
# Delete the batch status and ensure the batch's status has been changed
171
# to UNKNOWN
172
$status5->delete_and_log;
173
my $updated_code = Koha::Illbatches->find({ statuscode => "UNKNOWN" });
174
is($updated_code->statuscode, "UNKNOWN", "batches attached to deleted status have status changed to UNKNOWN");
175
176
$schema->storage->txn_rollback;
(-)a/t/db_dependent/api/v1/illbatchstatuses.t (-1 / +352 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 5;
21
use Test::Mojo;
22
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
26
use Koha::IllbatchStatus;
27
use Koha::IllbatchStatuses;
28
use Koha::Database;
29
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
my $t = Test::Mojo->new('Koha::REST::V1');
34
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
35
36
subtest 'list() tests' => sub {
37
38
    plan tests => 9;
39
40
    $schema->storage->txn_begin;
41
42
    Koha::IllbatchStatuses->search->delete;
43
44
    # Create an admin user
45
    my $librarian = $builder->build_object(
46
        {
47
            class => 'Koha::Patrons',
48
            value => {
49
                flags => 2 ** 22 # 22 => ill
50
            }
51
        }
52
    );
53
    my $password = 'yoda4ever!';
54
    $librarian->set_password( { password => $password, skip_validation => 1 } );
55
    my $userid = $librarian->userid;
56
57
    ## Authorized user tests
58
    # No statuses, so empty array should be returned
59
    $t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")
60
      ->status_is(200)
61
      ->json_is( [] );
62
63
    my $status = $builder->build_object({
64
        class => 'Koha::IllbatchStatuses',
65
        value => {
66
            name           => "Han Solo",
67
            code           => "SOLO",
68
            is_system      => 0
69
        }
70
    });
71
72
    # One batch created, should get returned
73
    $t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")
74
      ->status_is(200)
75
      ->json_has( '/0/id', 'ID' )
76
      ->json_has( '/0/name', 'Name' )
77
      ->json_has( '/0/code', 'Code' )
78
      ->json_has( '/0/is_system', 'is_system' );
79
80
    $schema->storage->txn_rollback;
81
};
82
83
subtest 'get() tests' => sub {
84
85
    plan tests => 11;
86
87
    $schema->storage->txn_begin;
88
89
    my $librarian = $builder->build_object(
90
        {
91
            class => 'Koha::Patrons',
92
            value => { flags => 2**22 }    # 22 => ill
93
        }
94
    );
95
    my $password = 'Rebelz4DaWin';
96
    $librarian->set_password( { password => $password, skip_validation => 1 } );
97
    my $userid = $librarian->userid;
98
99
    my $status = $builder->build_object({
100
        class => 'Koha::IllbatchStatuses',
101
        value => {
102
            name           => "Han Solo",
103
            code           => "SOLO",
104
            is_system      => 0
105
        }
106
    });
107
108
    # Unauthorised user
109
    my $patron = $builder->build_object(
110
        {
111
            class => 'Koha::Patrons',
112
            value => { flags => 0 }
113
        }
114
    );
115
    $patron->set_password( { password => $password, skip_validation => 1 } );
116
    my $unauth_userid = $patron->userid;
117
118
    $t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $status->code )
119
      ->status_is(200)
120
      ->json_has( '/id', 'ID' )
121
      ->json_has( '/name', 'Name' )
122
      ->json_has( '/code', 'Code' )
123
      ->json_has( '/is_system', 'is_system' );
124
125
    $t->get_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $status->id )
126
      ->status_is(403);
127
128
    my $status_to_delete = $builder->build_object({ class => 'Koha::IllbatchStatuses' });
129
    my $non_existent_code = $status_to_delete->code;
130
    $status_to_delete->delete;
131
132
    $t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" )
133
      ->status_is(404)
134
      ->json_is( '/error' => 'ILL batch status not found' );
135
136
    $schema->storage->txn_rollback;
137
};
138
139
subtest 'add() tests' => sub {
140
141
    plan tests =>14;
142
143
    $schema->storage->txn_begin;
144
145
    my $librarian = $builder->build_object(
146
        {
147
            class => 'Koha::Patrons',
148
            value => { flags => 2**22 }    # 22 => ill
149
        }
150
    );
151
    my $password = '3poRox';
152
    $librarian->set_password( { password => $password, skip_validation => 1 } );
153
    my $userid = $librarian->userid;
154
155
    my $patron = $builder->build_object(
156
        {
157
            class => 'Koha::Patrons',
158
            value => { flags => 0 }
159
        }
160
    );
161
    $patron->set_password( { password => $password, skip_validation => 1 } );
162
    my $unauth_userid = $patron->userid;
163
164
    my $status_metadata = {
165
        name           => "In a bacta tank",
166
        code           => "BACTA",
167
        is_system      => 0
168
    };
169
170
    # Unauthorized attempt to write
171
    $t->post_ok("//$unauth_userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata)
172
      ->status_is(403);
173
174
    # Authorized attempt to write invalid data
175
    my $status_with_invalid_field = {
176
        %{$status_metadata},
177
        doh => 1
178
    };
179
180
    $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_with_invalid_field )
181
      ->status_is(400)
182
      ->json_is(
183
        "/errors" => [
184
            {
185
                message => "Properties not allowed: doh.",
186
                path    => "/body"
187
            }
188
        ]
189
      );
190
191
    # Authorized attempt to write
192
    my $status_id =
193
      $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )
194
        ->status_is( 201 )
195
        ->json_has( '/id', 'ID' )
196
        ->json_has( '/name', 'Name' )
197
        ->json_has( '/code', 'Code' )
198
        ->json_has( '/is_system', 'is_system' );
199
200
    # Authorized attempt to create with null id
201
    $status_metadata->{id} = undef;
202
    $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )
203
      ->status_is(400)
204
      ->json_has('/errors');
205
206
    $schema->storage->txn_rollback;
207
};
208
209
subtest 'update() tests' => sub {
210
211
    plan tests => 13;
212
213
    $schema->storage->txn_begin;
214
215
    my $librarian = $builder->build_object(
216
        {
217
            class => 'Koha::Patrons',
218
            value => { flags => 2**22 }    # 22 => ill
219
        }
220
    );
221
    my $password = 'aw3s0m3y0d41z';
222
    $librarian->set_password( { password => $password, skip_validation => 1 } );
223
    my $userid = $librarian->userid;
224
225
    my $patron = $builder->build_object(
226
        {
227
            class => 'Koha::Patrons',
228
            value => { flags => 0 }
229
        }
230
    );
231
    $patron->set_password( { password => $password, skip_validation => 1 } );
232
    my $unauth_userid = $patron->userid;
233
234
    my $status_code = $builder->build_object({ class => 'Koha::IllbatchStatuses' } )->code;
235
236
    # Unauthorized attempt to update
237
    $t->put_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/$status_code" => json => { name => 'These are not the droids you are looking for' } )
238
      ->status_is(403);
239
240
    # Attempt partial update on a PUT
241
    my $status_with_missing_field = {
242
        code      => $status_code,
243
        is_system => 0
244
    };
245
246
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_missing_field )
247
      ->status_is(400)
248
      ->json_is( "/errors" =>
249
          [ { message => "Missing property.", path => "/body/name" } ]
250
      );
251
252
    # Full object update on PUT
253
    my $status_with_updated_field = {
254
        name           => "Master Ploo Koon",
255
        code           => $status_code,
256
        is_system      => 0
257
    };
258
259
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_updated_field )
260
      ->status_is(200)
261
      ->json_is( '/name' => 'Master Ploo Koon' );
262
263
    # Authorized attempt to write invalid data
264
    my $status_with_invalid_field = {
265
        doh  => 1,
266
        name => "Master Mace Windu",
267
        code => $status_code
268
    };
269
270
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_invalid_field )
271
      ->status_is(400)
272
      ->json_is(
273
        "/errors" => [
274
            {
275
                message => "Properties not allowed: doh.",
276
                path    => "/body"
277
            }
278
        ]
279
    );
280
281
    my $status_to_delete = $builder->build_object({ class => 'Koha::IllbatchStatuses' });
282
    my $non_existent_code = $status_to_delete->code;
283
    $status_to_delete->delete;
284
285
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" => json => $status_with_updated_field )
286
      ->status_is(404);
287
288
    $schema->storage->txn_rollback;
289
};
290
291
subtest 'delete() tests' => sub {
292
293
    plan tests => 9;
294
295
    $schema->storage->txn_begin;
296
297
    my $librarian = $builder->build_object(
298
        {
299
            class => 'Koha::Patrons',
300
            value => { flags => 2**22 }    # 22 => ill
301
        }
302
    );
303
    my $password = 's1th43v3r!';
304
    $librarian->set_password( { password => $password, skip_validation => 1 } );
305
    my $userid = $librarian->userid;
306
307
    my $patron = $builder->build_object(
308
        {
309
            class => 'Koha::Patrons',
310
            value => { flags => 0 }
311
        }
312
    );
313
314
    $patron->set_password( { password => $password, skip_validation => 1 } );
315
    my $unauth_userid = $patron->userid;
316
317
    my $non_system_status = $builder->build_object({
318
        class => 'Koha::IllbatchStatuses',
319
        value => {
320
            is_system => 0
321
        }
322
    });
323
324
    my $system_status = $builder->build_object({
325
        class => 'Koha::IllbatchStatuses',
326
        value => {
327
            is_system => 1
328
        }
329
    });
330
331
    # Unauthorized attempt to delete
332
    $t->delete_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )
333
      ->status_is(403);
334
335
    $t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )
336
      ->status_is(204);
337
338
    $t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )
339
      ->status_is(404);
340
341
    $t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $system_status->code )
342
      ->status_is(400)
343
      ->json_is(
344
        "/errors" => [
345
            {
346
                message => "ILL batch status cannot be deleted"
347
            }
348
        ]
349
      );
350
351
    $schema->storage->txn_rollback;
352
};

Return to bug 30719