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

(-)a/Koha/Illbatch.pm (-40 / +40 lines)
Lines 39-48 Return the status object associated with this batch Link Here
39
=cut
39
=cut
40
40
41
sub status {
41
sub status {
42
    my ( $self ) = @_;
42
    my ($self) = @_;
43
    return Koha::IllbatchStatus->_new_from_dbic(
43
    return Koha::IllbatchStatus->_new_from_dbic( scalar $self->_result->statuscode );
44
        scalar $self->_result->statuscode
45
    );
46
}
44
}
47
45
48
=head3 patron
46
=head3 patron
Lines 54-63 Return the patron object associated with this batch Link Here
54
=cut
52
=cut
55
53
56
sub patron {
54
sub patron {
57
    my ( $self ) = @_;
55
    my ($self) = @_;
58
    return Koha::Patron->_new_from_dbic(
56
    return Koha::Patron->_new_from_dbic( scalar $self->_result->borrowernumber );
59
        scalar $self->_result->borrowernumber
60
    );
61
}
57
}
62
58
63
=head3 branch
59
=head3 branch
Lines 69-78 Return the branch object associated with this batch Link Here
69
=cut
65
=cut
70
66
71
sub branch {
67
sub branch {
72
    my ( $self ) = @_;
68
    my ($self) = @_;
73
    return Koha::Library->_new_from_dbic(
69
    return Koha::Library->_new_from_dbic( scalar $self->_result->branchcode );
74
        scalar $self->_result->branchcode
75
    );
76
}
70
}
77
71
78
=head3 requests_count
72
=head3 requests_count
Lines 84-93 Return the number of requests associated with this batch Link Here
84
=cut
78
=cut
85
79
86
sub requests_count {
80
sub requests_count {
87
    my ( $self ) = @_;
81
    my ($self) = @_;
88
    return Koha::Illrequests->search({
82
    return Koha::Illrequests->search( { batch_id => $self->id } )->count;
89
        batch_id => $self->id
90
    })->count;
91
}
83
}
92
84
93
=head3 create_and_log
85
=head3 create_and_log
Lines 99-116 Log batch creation following storage Link Here
99
=cut
91
=cut
100
92
101
sub create_and_log {
93
sub create_and_log {
102
    my ( $self ) = @_;
94
    my ($self) = @_;
103
95
104
    $self->store;
96
    $self->store;
105
97
106
    my $logger = Koha::Illrequest::Logger->new;
98
    my $logger = Koha::Illrequest::Logger->new;
107
99
108
    $logger->log_something({
100
    $logger->log_something(
109
        modulename   => 'ILL',
101
        {
110
        actionname  => 'batch_create',
102
            modulename   => 'ILL',
111
        objectnumber => $self->id,
103
            actionname   => 'batch_create',
112
        infos        => to_json({})
104
            objectnumber => $self->id,
113
    });
105
            infos        => to_json( {} )
106
        }
107
    );
114
}
108
}
115
109
116
=head3 update_and_log
110
=head3 update_and_log
Lines 129-135 sub update_and_log { Link Here
129
        branchcode => $self->branchcode
123
        branchcode => $self->branchcode
130
    };
124
    };
131
125
132
    $self->set( $params );
126
    $self->set($params);
133
    my $update = $self->store;
127
    my $update = $self->store;
134
128
135
    my $after = {
129
    my $after = {
Lines 139-153 sub update_and_log { Link Here
139
133
140
    my $logger = Koha::Illrequest::Logger->new;
134
    my $logger = Koha::Illrequest::Logger->new;
141
135
142
    $logger->log_something({
136
    $logger->log_something(
143
        modulename   => 'ILL',
137
        {
144
        actionname  => 'batch_update',
138
            modulename   => 'ILL',
145
        objectnumber => $self->id,
139
            actionname   => 'batch_update',
146
        infos        => to_json({
140
            objectnumber => $self->id,
147
            before => $before,
141
            infos        => to_json(
148
            after  => $after
142
                {
149
        })
143
                    before => $before,
150
    });
144
                    after  => $after
145
                }
146
            )
147
        }
148
    );
151
}
149
}
152
150
153
=head3 delete_and_log
151
=head3 delete_and_log
Lines 159-174 Log batch delete Link Here
159
=cut
157
=cut
160
158
161
sub delete_and_log {
159
sub delete_and_log {
162
    my ( $self ) = @_;
160
    my ($self) = @_;
163
161
164
    my $logger = Koha::Illrequest::Logger->new;
162
    my $logger = Koha::Illrequest::Logger->new;
165
163
166
    $logger->log_something({
164
    $logger->log_something(
167
        modulename   => 'ILL',
165
        {
168
        actionname  => 'batch_delete',
166
            modulename   => 'ILL',
169
        objectnumber => $self->id,
167
            actionname   => 'batch_delete',
170
        infos        => to_json({})
168
            objectnumber => $self->id,
171
    });
169
            infos        => to_json( {} )
170
        }
171
    );
172
172
173
    $self->delete;
173
    $self->delete;
174
}
174
}
(-)a/Koha/IllbatchStatus.pm (-43 / +45 lines)
Lines 39-72 Log batch status creation following storage Link Here
39
=cut
39
=cut
40
40
41
sub create_and_log {
41
sub create_and_log {
42
    my ( $self ) = @_;
42
    my ($self) = @_;
43
43
44
    # Ensure code is uppercase and contains only word characters
44
    # Ensure code is uppercase and contains only word characters
45
    my $fixed_code = uc $self->code;
45
    my $fixed_code = uc $self->code;
46
    $fixed_code =~ s/\W/_/;
46
    $fixed_code =~ s/\W/_/;
47
47
48
    # Ensure this status doesn't already exist
48
    # Ensure this status doesn't already exist
49
    my $status = Koha::IllbatchStatuses->find({ code => $fixed_code });
49
    my $status = Koha::IllbatchStatuses->find( { code => $fixed_code } );
50
    if ($status) {
50
    if ($status) {
51
        return {
51
        return { error => "Duplicate status found" };
52
            error => "Duplicate status found"
53
        };
54
    }
52
    }
55
53
56
    # Ensure system statuses can't be created
54
    # Ensure system statuses can't be created
57
    $self->set({
55
    $self->set(
58
        code      => $fixed_code,
56
        {
59
        is_system => 0
57
            code      => $fixed_code,
60
    })->store;
58
            is_system => 0
59
        }
60
    )->store;
61
61
62
    my $logger = Koha::Illrequest::Logger->new;
62
    my $logger = Koha::Illrequest::Logger->new;
63
63
64
    $logger->log_something({
64
    $logger->log_something(
65
        modulename   => 'ILL',
65
        {
66
        actionname   => 'batch_status_create',
66
            modulename   => 'ILL',
67
        objectnumber => $self->id,
67
            actionname   => 'batch_status_create',
68
        infos        => to_json({})
68
            objectnumber => $self->id,
69
    });
69
            infos        => to_json( {} )
70
        }
71
    );
70
}
72
}
71
73
72
=head3 update_and_log
74
=head3 update_and_log
Lines 80-110 Log batch status update following storage Link Here
80
sub update_and_log {
82
sub update_and_log {
81
    my ( $self, $params ) = @_;
83
    my ( $self, $params ) = @_;
82
84
83
    my $before = {
85
    my $before = { name => $self->name };
84
        name => $self->name
85
    };
86
86
87
    # Ensure only the name can be changed
87
    # Ensure only the name can be changed
88
    $self->set({
88
    $self->set( { name => $params->{name} } );
89
        name => $params->{name}
90
    });
91
    my $update = $self->store;
89
    my $update = $self->store;
92
90
93
    my $after = {
91
    my $after = { name => $self->name };
94
        name => $self->name
95
    };
96
92
97
    my $logger = Koha::Illrequest::Logger->new;
93
    my $logger = Koha::Illrequest::Logger->new;
98
94
99
    $logger->log_something({
95
    $logger->log_something(
100
        modulename   => 'ILL',
96
        {
101
        actionname  => 'batch_status_update',
97
            modulename   => 'ILL',
102
        objectnumber => $self->id,
98
            actionname   => 'batch_status_update',
103
        infos        => to_json({
99
            objectnumber => $self->id,
104
            before => $before,
100
            infos        => to_json(
105
            after  => $after
101
                {
106
        })
102
                    before => $before,
107
    });
103
                    after  => $after
104
                }
105
            )
106
        }
107
    );
108
}
108
}
109
109
110
=head3 delete_and_log
110
=head3 delete_and_log
Lines 116-140 Log batch status delete Link Here
116
=cut
116
=cut
117
117
118
sub delete_and_log {
118
sub delete_and_log {
119
    my ( $self ) = @_;
119
    my ($self) = @_;
120
120
121
    # Don't permit deletion of system statuses
121
    # Don't permit deletion of system statuses
122
    if ($self->is_system) {
122
    if ( $self->is_system ) {
123
        return;
123
        return;
124
    }
124
    }
125
125
126
    # Update all batches that use this status to have status UNKNOWN
126
    # Update all batches that use this status to have status UNKNOWN
127
    my $affected = Koha::Illbatches->search({ statuscode => $self->code });
127
    my $affected = Koha::Illbatches->search( { statuscode => $self->code } );
128
    $affected->update({ statuscode => 'UNKNOWN'});
128
    $affected->update( { statuscode => 'UNKNOWN' } );
129
129
130
    my $logger = Koha::Illrequest::Logger->new;
130
    my $logger = Koha::Illrequest::Logger->new;
131
131
132
    $logger->log_something({
132
    $logger->log_something(
133
        modulename   => 'ILL',
133
        {
134
        actionname   => 'batch_status_delete',
134
            modulename   => 'ILL',
135
        objectnumber => $self->id,
135
            actionname   => 'batch_status_delete',
136
        infos        => to_json({})
136
            objectnumber => $self->id,
137
    });
137
            infos        => to_json( {} )
138
        }
139
    );
138
140
139
    $self->delete;
141
    $self->delete;
140
}
142
}
(-)a/Koha/REST/V1/IllbatchStatuses.pm (-21 / +20 lines)
Lines 52-71 sub get { Link Here
52
52
53
    my $status_code = $c->validation->param('illbatchstatus_code');
53
    my $status_code = $c->validation->param('illbatchstatus_code');
54
54
55
    my $status = Koha::IllbatchStatuses->find({ code => $status_code });
55
    my $status = Koha::IllbatchStatuses->find( { code => $status_code } );
56
56
57
    if (not defined $status) {
57
    if ( not defined $status ) {
58
        return $c->render(
58
        return $c->render(
59
            status => 404,
59
            status  => 404,
60
            openapi => { error => "ILL batch status not found" }
60
            openapi => { error => "ILL batch status not found" }
61
        );
61
        );
62
    }
62
    }
63
63
64
    return $c->render(
64
    return $c->render(
65
        status => 200,
65
        status  => 200,
66
        openapi => {
66
        openapi => { %{ $status->unblessed } }
67
            %{$status->unblessed}
68
        }
69
    );
67
    );
70
}
68
}
71
69
Lines 80-90 sub add { Link Here
80
78
81
    my $body = $c->validation->param('body');
79
    my $body = $c->validation->param('body');
82
80
83
    my $status = Koha::IllbatchStatus->new( $body );
81
    my $status = Koha::IllbatchStatus->new($body);
84
82
85
    return try {
83
    return try {
86
        my $return = $status->create_and_log;
84
        my $return = $status->create_and_log;
87
        if ($return && $return->{error}) {
85
        if ( $return && $return->{error} ) {
88
            return $c->render(
86
            return $c->render(
89
                status  => 500,
87
                status  => 500,
90
                openapi => $return
88
                openapi => $return
Lines 95-102 sub add { Link Here
95
                openapi => $status
93
                openapi => $status
96
            );
94
            );
97
        }
95
        }
98
    }
96
    } catch {
99
    catch {
100
        $c->unhandled_exception($_);
97
        $c->unhandled_exception($_);
101
    };
98
    };
102
}
99
}
Lines 110-116 Update a batch status Link Here
110
sub update {
107
sub update {
111
    my $c = shift->openapi->valid_input or return;
108
    my $c = shift->openapi->valid_input or return;
112
109
113
    my $status = Koha::IllbatchStatuses->find({ code => $c->validation->param('illbatchstatus_code') });
110
    my $status = Koha::IllbatchStatuses->find( { code => $c->validation->param('illbatchstatus_code') } );
114
111
115
    if ( not defined $status ) {
112
    if ( not defined $status ) {
116
        return $c->render(
113
        return $c->render(
Lines 122-136 sub update { Link Here
122
    my $params = $c->req->json;
119
    my $params = $c->req->json;
123
120
124
    return try {
121
    return try {
122
125
        # Only permit updating of name
123
        # Only permit updating of name
126
        $status->update_and_log({ name => $params->{name} });
124
        $status->update_and_log( { name => $params->{name} } );
127
125
128
        return $c->render(
126
        return $c->render(
129
            status  => 200,
127
            status  => 200,
130
            openapi => $status
128
            openapi => $status
131
        );
129
        );
132
    }
130
    } catch {
133
    catch {
134
        $c->unhandled_exception($_);
131
        $c->unhandled_exception($_);
135
    };
132
    };
136
}
133
}
Lines 145-165 sub delete { Link Here
145
142
146
    my $c = shift->openapi->valid_input or return;
143
    my $c = shift->openapi->valid_input or return;
147
144
148
    my $status = Koha::IllbatchStatuses->find({ code => $c->validation->param( 'illbatchstatus_code' ) });
145
    my $status = Koha::IllbatchStatuses->find( { code => $c->validation->param('illbatchstatus_code') } );
149
146
150
    if ( not defined $status ) {
147
    if ( not defined $status ) {
151
        return $c->render( status => 404, openapi => { errors => [ { message => "ILL batch status not found" } ] } );
148
        return $c->render( status => 404, openapi => { errors => [ { message => "ILL batch status not found" } ] } );
152
    }
149
    }
153
150
154
    if ( $status->is_system) {
151
    if ( $status->is_system ) {
155
        return $c->render( status => 400, openapi => { errors => [ { message => "ILL batch status cannot be deleted" } ] } );
152
        return $c->render(
153
            status  => 400,
154
            openapi => { errors => [ { message => "ILL batch status cannot be deleted" } ] }
155
        );
156
    }
156
    }
157
157
158
    return try {
158
    return try {
159
        $status->delete_and_log;
159
        $status->delete_and_log;
160
        return $c->render( status => 204, openapi => '');
160
        return $c->render( status => 204, openapi => '' );
161
    }
161
    } catch {
162
    catch {
163
        $c->unhandled_exception($_);
162
        $c->unhandled_exception($_);
164
    };
163
    };
165
}
164
}
(-)a/Koha/REST/V1/Illbatches.pm (-47 / +61 lines)
Lines 47-93 sub list { Link Here
47
    # Get all patrons associated with all our batches
47
    # Get all patrons associated with all our batches
48
    # in one go
48
    # in one go
49
    my $patrons = {};
49
    my $patrons = {};
50
    foreach my $batch(@batches) {
50
    foreach my $batch (@batches) {
51
        my $patron_id = $batch->borrowernumber;
51
        my $patron_id = $batch->borrowernumber;
52
        $patrons->{$patron_id} = 1
52
        $patrons->{$patron_id} = 1;
53
    };
53
    }
54
    my @patron_ids = keys %{$patrons};
54
    my @patron_ids     = keys %{$patrons};
55
    my $patron_results = Koha::Patrons->search({
55
    my $patron_results = Koha::Patrons->search( { borrowernumber => { -in => \@patron_ids } } );
56
        borrowernumber => { -in => \@patron_ids }
57
    });
58
56
59
    # Get all branches associated with all our batches
57
    # Get all branches associated with all our batches
60
    # in one go
58
    # in one go
61
    my $branches = {};
59
    my $branches = {};
62
    foreach my $batch(@batches) {
60
    foreach my $batch (@batches) {
63
        my $branch_id = $batch->branchcode;
61
        my $branch_id = $batch->branchcode;
64
        $branches->{$branch_id} = 1
62
        $branches->{$branch_id} = 1;
65
    };
63
    }
66
    my @branchcodes = keys %{$branches};
64
    my @branchcodes    = keys %{$branches};
67
    my $branch_results = Koha::Libraries->search({
65
    my $branch_results = Koha::Libraries->search( { branchcode => { -in => \@branchcodes } } );
68
        branchcode => { -in => \@branchcodes }
69
    });
70
66
71
    # Get all batch statuses associated with all our batches
67
    # Get all batch statuses associated with all our batches
72
    # in one go
68
    # in one go
73
    my $statuses = {};
69
    my $statuses = {};
74
    foreach my $batch(@batches) {
70
    foreach my $batch (@batches) {
75
        my $code = $batch->statuscode;
71
        my $code = $batch->statuscode;
76
        $statuses->{$code} = 1
72
        $statuses->{$code} = 1;
77
    };
73
    }
78
    my @statuscodes = keys %{$statuses};
74
    my @statuscodes    = keys %{$statuses};
79
    my $status_results = Koha::IllbatchStatuses->search({
75
    my $status_results = Koha::IllbatchStatuses->search( { code => { -in => \@statuscodes } } );
80
        code => { -in => \@statuscodes }
81
    });
82
76
83
    # Populate the response
77
    # Populate the response
84
    my @to_return = ();
78
    my @to_return = ();
85
    foreach my $it_batch(@batches) {
79
    foreach my $it_batch (@batches) {
86
        my $patron = $patron_results->find({ borrowernumber => $it_batch->borrowernumber});
80
        my $patron = $patron_results->find( { borrowernumber => $it_batch->borrowernumber } );
87
        my $branch = $branch_results->find({ branchcode => $it_batch->branchcode });
81
        my $branch = $branch_results->find( { branchcode     => $it_batch->branchcode } );
88
        my $status = $status_results->find({ code => $it_batch->statuscode });
82
        my $status = $status_results->find( { code           => $it_batch->statuscode } );
89
        push @to_return, {
83
        push @to_return, {
90
            %{$it_batch->unblessed},
84
            batch_id       => $it_batch->id,
85
            backend        => $it_batch->backend,
86
            library_id     => $it_batch->branchcode,
87
            name           => $it_batch->name,
88
            statuscode     => $it_batch->statuscode,
89
            patron_id      => $it_batch->borrowernumber,
91
            patron         => $patron,
90
            patron         => $patron,
92
            branch         => $branch,
91
            branch         => $branch,
93
            status         => $status,
92
            status         => $status,
Lines 111-127 sub get { Link Here
111
110
112
    my $batch = Koha::Illbatches->find($batchid);
111
    my $batch = Koha::Illbatches->find($batchid);
113
112
114
    if (not defined $batch) {
113
    if ( not defined $batch ) {
115
        return $c->render(
114
        return $c->render(
116
            status => 404,
115
            status  => 404,
117
            openapi => { error => "ILL batch not found" }
116
            openapi => { error => "ILL batch not found" }
118
        );
117
        );
119
    }
118
    }
120
119
121
    return $c->render(
120
    return $c->render(
122
        status => 200,
121
        status  => 200,
123
        openapi => {
122
        openapi => {
124
            %{$batch->unblessed},
123
            batch_id       => $batch->id,
124
            backend        => $batch->backend,
125
            library_id     => $batch->branchcode,
126
            name           => $batch->name,
127
            statuscode     => $batch->statuscode,
128
            patron_id      => $batch->borrowernumber,
125
            patron         => $batch->patron->unblessed,
129
            patron         => $batch->patron->unblessed,
126
            branch         => $batch->branch->unblessed,
130
            branch         => $batch->branch->unblessed,
127
            status         => $batch->status->unblessed,
131
            status         => $batch->status->unblessed,
Lines 143-149 sub add { Link Here
143
147
144
    # We receive cardnumber, so we need to look up the corresponding
148
    # We receive cardnumber, so we need to look up the corresponding
145
    # borrowernumber
149
    # borrowernumber
146
    my $patron = Koha::Patrons->find({ cardnumber => $body->{cardnumber} });
150
    my $patron = Koha::Patrons->find( { cardnumber => $body->{cardnumber} } );
147
151
148
    if ( not defined $patron ) {
152
    if ( not defined $patron ) {
149
        return $c->render(
153
        return $c->render(
Lines 154-179 sub add { Link Here
154
158
155
    delete $body->{cardnumber};
159
    delete $body->{cardnumber};
156
    $body->{borrowernumber} = $patron->borrowernumber;
160
    $body->{borrowernumber} = $patron->borrowernumber;
161
    $body->{branchcode}     = delete $body->{library_id};
157
162
158
    return try {
163
    return try {
159
        my $batch = Koha::Illbatch->new( $body );
164
        my $batch = Koha::Illbatch->new($body);
160
        $batch->create_and_log;
165
        $batch->create_and_log;
161
        $c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
166
        $c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
162
167
163
        my $ret = {
168
        my $ret = {
164
            %{$batch->unblessed},
169
            batch_id       => $batch->id,
165
            patron           => $batch->patron->unblessed,
170
            backend        => $batch->backend,
166
            branch           => $batch->branch->unblessed,
171
            library_id     => $batch->branchcode,
167
            status           => $batch->status->unblessed,
172
            name           => $batch->name,
168
            requests_count   => 0
173
            statuscode     => $batch->statuscode,
174
            patron_id      => $batch->borrowernumber,
175
            patron         => $batch->patron->unblessed,
176
            branch         => $batch->branch->unblessed,
177
            status         => $batch->status->unblessed,
178
            requests_count => 0
169
        };
179
        };
170
180
171
        return $c->render(
181
        return $c->render(
172
            status  => 201,
182
            status  => 201,
173
            openapi => $ret
183
            openapi => $ret
174
        );
184
        );
175
    }
185
    } catch {
176
    catch {
177
        if ( blessed $_ ) {
186
        if ( blessed $_ ) {
178
            if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
187
            if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
179
                return $c->render(
188
                return $c->render(
Lines 206-217 sub update { Link Here
206
215
207
    my $params = $c->req->json;
216
    my $params = $c->req->json;
208
    delete $params->{cardnumber};
217
    delete $params->{cardnumber};
218
    $params->{borrowernumber} = delete $params->{patron_id}  if $params->{patron_id};
219
    $params->{branchcode}     = delete $params->{library_id} if $params->{library_id};
209
220
210
    return try {
221
    return try {
211
        $batch->update_and_log( $params );
222
        $batch->update_and_log($params);
212
223
213
        my $ret = {
224
        my $ret = {
214
            %{$batch->unblessed},
225
            batch_id       => $batch->id,
226
            backend        => $batch->backend,
227
            library_id     => $batch->branchcode,
228
            name           => $batch->name,
229
            statuscode     => $batch->statuscode,
230
            patron_id      => $batch->borrowernumber,
215
            patron         => $batch->patron->unblessed,
231
            patron         => $batch->patron->unblessed,
216
            branch         => $batch->branch->unblessed,
232
            branch         => $batch->branch->unblessed,
217
            status         => $batch->status->unblessed,
233
            status         => $batch->status->unblessed,
Lines 222-229 sub update { Link Here
222
            status  => 200,
238
            status  => 200,
223
            openapi => $ret
239
            openapi => $ret
224
        );
240
        );
225
    }
241
    } catch {
226
    catch {
227
        $c->unhandled_exception($_);
242
        $c->unhandled_exception($_);
228
    };
243
    };
229
}
244
}
Lines 238-244 sub delete { Link Here
238
253
239
    my $c = shift->openapi->valid_input or return;
254
    my $c = shift->openapi->valid_input or return;
240
255
241
    my $batch = Koha::Illbatches->find( $c->validation->param( 'illbatch_id' ) );
256
    my $batch = Koha::Illbatches->find( $c->validation->param('illbatch_id') );
242
257
243
    if ( not defined $batch ) {
258
    if ( not defined $batch ) {
244
        return $c->render( status => 404, openapi => { error => "ILL batch not found" } );
259
        return $c->render( status => 404, openapi => { error => "ILL batch not found" } );
Lines 246-254 sub delete { Link Here
246
261
247
    return try {
262
    return try {
248
        $batch->delete_and_log;
263
        $batch->delete_and_log;
249
        return $c->render( status => 204, openapi => '');
264
        return $c->render( status => 204, openapi => '' );
250
    }
265
    } catch {
251
    catch {
252
        $c->unhandled_exception($_);
266
        $c->unhandled_exception($_);
253
    };
267
    };
254
}
268
}
(-)a/Koha/REST/V1/Illrequests.pm (-5 / +3 lines)
Lines 93-106 sub add { Link Here
93
                my $create_result = &{$create_api}($body, $request);
93
                my $create_result = &{$create_api}($body, $request);
94
                my $new_id = $create_result->illrequest_id;
94
                my $new_id = $create_result->illrequest_id;
95
95
96
                my @new_req = Koha::Illrequests->search({
96
                my $new_req = Koha::Illrequests->find($new_id);
97
                    illrequest_id => $new_id
98
                })->as_list;
99
97
100
                $c->res->headers->location($c->req->url->to_string . '/' . $new_req[0]->illrequest_id);
98
                $c->res->headers->location($c->req->url->to_string . '/' . $new_req->illrequest_id);
101
                return $c->render(
99
                return $c->render(
102
                    status  => 201,
100
                    status  => 201,
103
                    openapi => $new_req[0]->to_api
101
                    openapi => $new_req->to_api
104
                );
102
                );
105
            }
103
            }
106
        );
104
        );
(-)a/Koha/Schema/Result/Illbatch.pm (+8 lines)
Lines 197-200 __PACKAGE__->belongs_to( Link Here
197
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
197
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
198
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YKxQxJMKxdBP9X4+i0Rfzw
198
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YKxQxJMKxdBP9X4+i0Rfzw
199
199
200
sub koha_object_class {
201
    'Koha::Illbatch';
202
}
203
204
sub koha_objects_class {
205
    'Koha::Illbatches';
206
}
207
200
1;
208
1;
(-)a/Koha/Schema/Result/IllbatchStatus.pm (+12 lines)
Lines 114-117 __PACKAGE__->has_many( Link Here
114
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
114
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
115
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yo60FJ+kyRj8QuEMac8CFA
115
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yo60FJ+kyRj8QuEMac8CFA
116
116
117
__PACKAGE__->add_columns(
118
    '+is_system' => { is_boolean => 1 },
119
);
120
121
sub koha_object_class {
122
    'Koha::IllbatchStatus';
123
}
124
125
sub koha_objects_class {
126
    'Koha::IllbatchStatuses';
127
}
128
117
1;
129
1;
(-)a/admin/columns_settings.yml (+1 lines)
Lines 827-832 modules: Link Here
827
              columnname: ill_request_id
827
              columnname: ill_request_id
828
            -
828
            -
829
              columnname: batch
829
              columnname: batch
830
              is_hidden: 1
830
            -
831
            -
831
              columnname: metadata_author
832
              columnname: metadata_author
832
            -
833
            -
(-)a/admin/ill_batch_statuses.pl (-24 / +20 lines)
Lines 18-28 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
21
use CGI       qw ( -utf8 );
22
use Try::Tiny qw( catch try );
22
use Try::Tiny qw( catch try );
23
23
24
use C4::Context;
24
use C4::Context;
25
use C4::Auth qw( get_template_and_user );
25
use C4::Auth   qw( get_template_and_user );
26
use C4::Output qw( output_html_with_http_headers );
26
use C4::Output qw( output_html_with_http_headers );
27
27
28
use Koha::IllbatchStatus;
28
use Koha::IllbatchStatus;
Lines 35-89 my @messages; Link Here
35
35
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
    {
37
    {
38
        template_name   => "admin/ill_batch_statuses.tt",
38
        template_name => "admin/ill_batch_statuses.tt",
39
        query           => $input,
39
        query         => $input,
40
        type            => "intranet",
40
        type          => "intranet",
41
        flagsrequired   => { parameters => 'ill' },
41
        flagsrequired => { parameters => 'ill' },
42
    }
42
    }
43
);
43
);
44
44
45
my $status;
45
my $status;
46
if ($code) {
46
if ($code) {
47
    $status = Koha::IllbatchStatuses->find({ code => $code });
47
    $status = Koha::IllbatchStatuses->find( { code => $code } );
48
}
48
}
49
49
50
if ( $op eq 'add_form' ) {
50
if ( $op eq 'add_form' ) {
51
    if ($status) {
51
    if ($status) {
52
        $template->param(
52
        $template->param( status => $status );
53
            status => $status
54
        );
55
    }
53
    }
56
}
54
} elsif ( $op eq 'add_validate' ) {
57
elsif ( $op eq 'add_validate' ) {
58
    my $name = $input->param('name');
55
    my $name = $input->param('name');
59
    my $code = $input->param('code');
56
    my $code = $input->param('code');
60
57
61
    if ( not defined $status ) {
58
    if ( not defined $status ) {
62
        $status = Koha::IllbatchStatus->new( {
59
        $status = Koha::IllbatchStatus->new(
63
            name => $name,
60
            {
64
            code => $code
61
                name => $name,
65
        } );
62
                code => $code
63
            }
64
        );
66
    }
65
    }
67
66
68
    try {
67
    try {
69
        if ($status->id) {
68
        if ( $status->id ) {
70
            $status->update_and_log({ name => $name });
69
            $status->update_and_log( { name => $name } );
71
        } else {
70
        } else {
72
            $status->create_and_log;
71
            $status->create_and_log;
73
        }
72
        }
74
        push @messages, { type => 'message', code => 'success_on_saving' };
73
        push @messages, { type => 'message', code => 'success_on_saving' };
75
    }
74
    } catch {
76
    catch {
77
        push @messages, { type => 'error', code => 'error_on_saving' };
75
        push @messages, { type => 'error', code => 'error_on_saving' };
78
    };
76
    };
79
    $op = 'list';
77
    $op = 'list';
80
}
78
} elsif ( $op eq 'delete' ) {
81
elsif ( $op eq 'delete' ) {
82
    try {
79
    try {
83
        $status->delete_and_log;
80
        $status->delete_and_log;
84
        push @messages, { code => 'success_on_delete', type => 'message' };
81
        push @messages, { code => 'success_on_delete', type => 'message' };
85
    }
82
    } catch {
86
    catch {
87
        push @messages, { code => 'error_on_delete', type => 'alert' };
83
        push @messages, { code => 'error_on_delete', type => 'alert' };
88
84
89
    };
85
    };
(-)a/api/v1/swagger/definitions/illbatch.yaml (-4 / +4 lines)
Lines 1-7 Link Here
1
---
1
---
2
type: object
2
type: object
3
properties:
3
properties:
4
  id:
4
  batch_id:
5
    type: string
5
    type: string
6
    description: Internal ILL batch identifier
6
    description: Internal ILL batch identifier
7
  name:
7
  name:
Lines 13-22 properties: Link Here
13
  cardnumber:
13
  cardnumber:
14
    type: string
14
    type: string
15
    description: Card number of the patron of the ILL batch
15
    description: Card number of the patron of the ILL batch
16
  borrowernumber:
16
  patron_id:
17
    type: string
17
    type: string
18
    description: Borrower number of the patron of the ILL batch
18
    description: Borrower number of the patron of the ILL batch
19
  branchcode:
19
  library_id:
20
    type: string
20
    type: string
21
    description: Branch code of the branch of the ILL batch
21
    description: Branch code of the branch of the ILL batch
22
  patron:
22
  patron:
Lines 44-48 additionalProperties: false Link Here
44
required:
44
required:
45
  - name
45
  - name
46
  - backend
46
  - backend
47
  - branchcode
47
  - library_id
48
  - statuscode
48
  - statuscode
(-)a/api/v1/swagger/definitions/illbatchstatus.yaml (-1 / +1 lines)
Lines 11-17 properties: Link Here
11
    type: string
11
    type: string
12
    description: Unique, immutable status code
12
    description: Unique, immutable status code
13
  is_system:
13
  is_system:
14
    type: string
14
    type: boolean
15
    description: Is this status required for system operation
15
    description: Is this status required for system operation
16
additionalProperties: false
16
additionalProperties: false
17
required:
17
required:
(-)a/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl (-43 / +146 lines)
Lines 1-54 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "30719",
4
    bug_number  => "30719",
5
    description => "Add ILL batches",
5
    description => "Add ILL batches",
6
    up => sub {
6
    up          => sub {
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(
10
            CREATE TABLE IF NOT EXISTS `illbatches` (
10
            q{
11
                `id` int(11) NOT NULL auto_increment, -- Batch ID
12
                `name` varchar(100) NOT NULL,         -- Unique name of batch
13
                `backend` varchar(20) NOT NULL,       -- Name of batch backend
14
                `borrowernumber` int(11),             -- Patron associated with batch
15
                `branchcode` varchar(50),             -- Branch associated with batch
16
                `statuscode` varchar(20),             -- Status of batch
17
                PRIMARY KEY (`id`),
18
                UNIQUE KEY `u_illbatches__name` (`name`)
19
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
20
        });
21
        $dbh->do(q{
22
            CREATE TABLE IF NOT EXISTS `illbatch_statuses` (
11
            CREATE TABLE IF NOT EXISTS `illbatch_statuses` (
23
                `id` int(11) NOT NULL auto_increment, -- Status ID
12
                `id` int(11) NOT NULL auto_increment COMMENT "Status ID",
24
                `name` varchar(100) NOT NULL,         -- Name of status
13
                `name` varchar(100) NOT NULL COMMENT "Name of status",
25
                `code` varchar(20) NOT NULL,          -- Unique, immutable code for status
14
                `code` varchar(20) NOT NULL COMMENT "Unique, immutable code for status",
26
                `is_system` int(1),                   -- Is this status required for system operation
15
                `is_system` tinyint(1) COMMENT "Is this status required for system operation",
27
                PRIMARY KEY (`id`),
16
                PRIMARY KEY (`id`),
28
                UNIQUE KEY `u_illbatchstatuses__code` (`code`)
17
                UNIQUE KEY `u_illbatchstatuses__code` (`code`)
29
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
18
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
30
        });
19
        }
31
        $dbh->do(q{
20
        );
32
            ALTER TABLE `illrequests`
21
        $dbh->do(
33
                ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to
22
            q{
34
        });
23
            CREATE TABLE IF NOT EXISTS `illbatches` (
35
        $dbh->do(q{
24
                `id` int(11) NOT NULL auto_increment COMMENT "Batch ID",
36
            ALTER TABLE `illrequests`
25
                `name` varchar(100) NOT NULL COMMENT "Unique name of batch",
37
                ADD CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
26
                `backend` varchar(20) NOT NULL COMMENT "Name of batch backend",
38
        });
27
                `borrowernumber` int(11) COMMENT "Patron associated with batch",
39
        $dbh->do(q{
28
                `branchcode` varchar(50) COMMENT "Branch associated with batch",
40
            ALTER TABLE `illbatches`
29
                `statuscode` varchar(20) COMMENT "Status of batch",
41
                ADD CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
30
                PRIMARY KEY (`id`),
42
        });
31
                UNIQUE KEY `u_illbatches__name` (`name`),
43
        $dbh->do(q{
32
                CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
44
            ALTER TABLE `illbatches`
33
                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
34
                CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
46
        });
35
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
47
        $dbh->do(q{
36
        }
48
            ALTER TABLE `illbatches`
37
        );
49
                ADD CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
38
        unless ( column_exists( 'illrequests', 'batch_id' ) ) {
50
        });
39
            $dbh->do(
51
40
                q{
52
        say $out "Bug 30719: Add ILL batches completed"
41
                ALTER TABLE `illrequests`
42
                    ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to
43
            }
44
            );
45
        }
46
47
        unless ( foreign_key_exists( 'illrequests', 'illrequests_ibfk' ) ) {
48
            $dbh->do(
49
                q{
50
                ALTER TABLE `illrequests`
51
                    ADD CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
52
            }
53
            );
54
        }
55
56
        unless ( foreign_key_exists( 'illbatches', 'illbatches_bnfk' ) ) {
57
            $dbh->do(
58
                q{
59
                ALTER TABLE `illbatches`
60
                    ADD CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
61
            }
62
            );
63
        }
64
65
        unless ( foreign_key_exists( 'illbatches', 'illbatches_bcfk' ) ) {
66
            $dbh->do(
67
                q{
68
                ALTER TABLE `illbatches`
69
                    ADD CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
70
            }
71
            );
72
        }
73
74
        unless ( foreign_key_exists( 'illbatches', 'illbatches_sfk' ) ) {
75
            $dbh->do(
76
                q{
77
                ALTER TABLE `illbatches`
78
                    ADD CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
79
            }
80
            );
81
        }
82
83
        # Get any existing NEW batch status
84
        my ($new_status) = $dbh->selectrow_array(
85
            q|
86
            SELECT name FROM illbatch_statuses WHERE code='NEW';
87
        |
88
        );
89
90
        if ($new_status) {
91
            say $out "Bug 30719: NEW ILL batch status found. Update has already been run.";
92
        } else {
93
            $dbh->do(
94
                qq{
95
            INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES ('New', 'NEW', '1')
96
            }
97
            );
98
            say $out "Bug 30719: Added NEW ILL batch status";
99
        }
100
101
        # Get any existing IN_PROGRESS batch status
102
        my ($in_progress_status) = $dbh->selectrow_array(
103
            q|
104
            SELECT name FROM illbatch_statuses WHERE code='IN_PROGRESS';
105
        |
106
        );
107
108
        if ($in_progress_status) {
109
            say $out "Bug 30719: IN_PROGRESS ILL batch status found. Update has already been run.";
110
        } else {
111
            $dbh->do(
112
                qq{
113
            INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'In progress', 'IN_PROGRESS', '1' )
114
            }
115
            );
116
            say $out "Bug 30719: Added IN_PROGRESS ILL batch status";
117
        }
118
119
        # Get any existing COMPLETED batch status
120
        my ($completed_status) = $dbh->selectrow_array(
121
            q|
122
            SELECT name FROM illbatch_statuses WHERE code='COMPLETED';
123
        |
124
        );
125
126
        if ($completed_status) {
127
            say $out "Bug 30719: COMPLETED ILL batch status found. Update has already been run.";
128
        } else {
129
            $dbh->do(
130
                qq{
131
            INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Completed', 'COMPLETED', '1' )
132
            }
133
            );
134
            say $out "Bug 30719: Added COMPLETED ILL batch status";
135
        }
136
137
        # Get any existing UNKNOWN batch status
138
        my ($unknown_status) = $dbh->selectrow_array(
139
            q|
140
            SELECT name FROM illbatch_statuses WHERE code='UNKNOWN';
141
        |
142
        );
143
144
        if ($unknown_status) {
145
            say $out "Bug 30719: UNKNOWN ILL batch status found. Update has already been run.";
146
        } else {
147
            $dbh->do(
148
                qq{
149
            INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Unknown', 'UNKNOWN', '1' )
150
            }
151
            );
152
            say $out "Bug 30719: Added UNKNOWN ILL batch status";
153
        }
154
155
        say $out "Bug 30719: Add ILL batches completed";
53
    },
156
    },
54
};
157
};
(-)a/installer/data/mysql/en/mandatory/illbatch_statuses.yml (+42 lines)
Line 0 Link Here
1
---
2
#
3
#  Copyright 2023 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
description:
21
  - "ILL batch statuses used in Koha"
22
23
tables:
24
  - illbatch_statuses:
25
      translatable: [ description ]
26
      multiline: []
27
      rows:
28
        - code: "NEW"
29
          name: "New"
30
          is_system: "1"
31
32
        - code: "IN_PROGRESS"
33
          name: "In progress"
34
          is_system: "1"
35
36
        - code: "COMPLETED"
37
          name: "Completed"
38
          is_system: "1"
39
40
        - code: "UNKNOWN"
41
          name: "Unknown"
42
          is_system: "1"
(-)a/installer/data/mysql/kohastructure.sql (-10 / +10 lines)
Lines 3306-3315 CREATE TABLE `illrequestattributes` ( Link Here
3306
--
3306
--
3307
DROP TABLE IF EXISTS `illbatch_statuses`;
3307
DROP TABLE IF EXISTS `illbatch_statuses`;
3308
CREATE TABLE `illbatch_statuses` (
3308
CREATE TABLE `illbatch_statuses` (
3309
    `id` int(11) NOT NULL auto_increment, -- Status ID
3309
    `id` int(11) NOT NULL auto_increment COMMENT "Status ID",
3310
    `name` varchar(100) NOT NULL,         -- Name of status
3310
    `name` varchar(100) NOT NULL COMMENT "Name of status",
3311
    `code` varchar(20) NOT NULL,          -- Unique, immutable code for status
3311
    `code` varchar(20) NOT NULL COMMENT "Unique, immutable code for status",
3312
    `is_system` int(1),                   -- Is this status required for system operation
3312
    `is_system` tinyint(1) COMMENT "Is this status required for system operation",
3313
    PRIMARY KEY (`id`),
3313
    PRIMARY KEY (`id`),
3314
    UNIQUE KEY `u_illbatchstatuses__code` (`code`)
3314
    UNIQUE KEY `u_illbatchstatuses__code` (`code`)
3315
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3315
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Lines 3319-3330 CREATE TABLE `illbatch_statuses` ( Link Here
3319
--
3319
--
3320
DROP TABLE IF EXISTS `illbatches`;
3320
DROP TABLE IF EXISTS `illbatches`;
3321
CREATE TABLE `illbatches` (
3321
CREATE TABLE `illbatches` (
3322
    `id` int(11) NOT NULL auto_increment, -- Batch ID
3322
    `id` int(11) NOT NULL auto_increment COMMENT "Batch ID",
3323
    `name` varchar(100) NOT NULL,         -- Unique name of batch
3323
    `name` varchar(100) NOT NULL COMMENT "Unique name of batch",
3324
    `backend` varchar(20) NOT NULL,       -- Name of batch backend
3324
    `backend` varchar(20) NOT NULL COMMENT "Name of batch backend",
3325
    `borrowernumber` int(11),             -- Patron associated with batch
3325
    `borrowernumber` int(11) COMMENT "Patron associated with batch",
3326
    `branchcode` varchar(50),             -- Branch associated with batch
3326
    `branchcode` varchar(50) COMMENT "Branch associated with batch",
3327
    `statuscode` varchar(20),             -- Status of batch
3327
    `statuscode` varchar(20) COMMENT "Status of batch",
3328
    PRIMARY KEY (`id`),
3328
    PRIMARY KEY (`id`),
3329
    UNIQUE KEY `u_illbatches__name` (`name`),
3329
    UNIQUE KEY `u_illbatches__name` (`name`),
3330
    CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3330
    CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
(-)a/installer/data/mysql/mandatory/illbatch_statuses.sql (-5 lines)
Lines 1-5 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 (-1 / +1 lines)
Lines 178-184 Link Here
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 %]
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>
181
                <li><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary loan batch statuses</a></li>
182
            [% END %]
182
            [% END %]
183
        </ul>
183
        </ul>
184
    [% END %]
184
    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal-strings.inc (-1 / +1 lines)
Lines 16-22 Link Here
16
    var ill_button_remove = _("Remove");
16
    var ill_button_remove = _("Remove");
17
    var ill_batch_create_api_fail = _("Unable to create batch request");
17
    var ill_batch_create_api_fail = _("Unable to create batch request");
18
    var ill_batch_update_api_fail = _("Unable to updatecreate batch request");
18
    var ill_batch_update_api_fail = _("Unable to updatecreate batch request");
19
    var ill_batch_item_remove = _("Are you sure you want to remove this item from the batch");
19
    var ill_batch_item_remove = _("Are you sure you want to remove this item from the batch?");
20
    var ill_batch_create_cancel_button = _("Close");
20
    var ill_batch_create_cancel_button = _("Close");
21
    var ill_batch_metadata_more = _("More");
21
    var ill_batch_metadata_more = _("More");
22
    var ill_batch_metadata_less = _("Less");
22
    var ill_batch_metadata_less = _("Less");
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch.inc (-2 / +6 lines)
Lines 1-5 Link Here
1
[% IF query_type == "batch_list" %]
1
[% IF query_type == "batch_list" %]
2
<div>
2
<h1>
3
    <span>View ILL requests batches</span>
4
</h1>
5
<div class="page-section">
6
    <h2>Details for all batches</h2>
3
    <table id="ill-batch-requests">
7
    <table id="ill-batch-requests">
4
        <thead>
8
        <thead>
5
            <tr id="ill-batch-header">
9
            <tr id="ill-batch-header">
Lines 8-14 Link Here
8
                <th scope="col">Number of requests</th>
12
                <th scope="col">Number of requests</th>
9
                <th scope="col">Status</th>
13
                <th scope="col">Status</th>
10
                <th scope="col">Patron</th>
14
                <th scope="col">Patron</th>
11
                <th scope="col">Branch</th>
15
                <th scope="col">Library</th>
12
                <th scope="col"></th>
16
                <th scope="col"></th>
13
            </tr>
17
            </tr>
14
        </thead>
18
        </thead>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-toolbar.inc (-1 / +1 lines)
Lines 37-43 Link Here
37
        <div id="ill-batch">
37
        <div id="ill-batch">
38
            <div class="dropdown btn-group">
38
            <div class="dropdown btn-group">
39
                <button class="btn btn-default dropdown-toggle" type="button" id="ill-batch-backend-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
39
                <button class="btn btn-default dropdown-toggle" type="button" id="ill-batch-backend-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
40
                    <i class="fa fa-plus"></i> New ILL batch request <span class="caret"></span>
40
                    <i class="fa fa-plus"></i> New ILL requests batch <span class="caret"></span>
41
                </button>
41
                </button>
42
                <ul class="dropdown-menu" aria-labelledby="ill-batch-backend-dropdown">
42
                <ul class="dropdown-menu" aria-labelledby="ill-batch-backend-dropdown">
43
                    [% FOREACH backend IN have_batch %]
43
                    [% FOREACH backend IN have_batch %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-2 / +2 lines)
Lines 286-293 Link Here
286
                        <dd>Define which keys trigger actions in the advanced cataloging editor</dd>
286
                        <dd>Define which keys trigger actions in the advanced cataloging editor</dd>
287
                    [% END %]
287
                    [% END %]
288
                    [% IF Koha.Preference('ILLModule') && CAN_user_ill %]
288
                    [% IF Koha.Preference('ILLModule') && CAN_user_ill %]
289
                        <dt><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a></dt>
289
                        <dt><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary loan batch statuses</a></dt>
290
                        <dd>Manage the statuses that can be assigned to Interlibrary Loan batches</dd>
290
                        <dd>Manage the statuses that can be assigned to Interlibrary loan batches</dd>
291
                    [% END %]
291
                    [% END %]
292
                </dl>
292
                </dl>
293
            [% END %]
293
            [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/ill_batch_statuses.tt (-55 / +52 lines)
Lines 11-17 Link Here
11
       [% ELSE %]
11
       [% ELSE %]
12
           New batch status
12
           New batch status
13
       [% END %] &rsaquo; [% END %]
13
       [% END %] &rsaquo; [% END %]
14
    Interlibrary Loan batch statuses &rsaquo; Administration &rsaquo; Koha
14
    Interlibrary loan batch statuses &rsaquo; Administration &rsaquo; Koha
15
</title>
15
</title>
16
[% INCLUDE 'doc-head-close.inc' %]
16
[% INCLUDE 'doc-head-close.inc' %]
17
</head>
17
</head>
Lines 20-57 Link Here
20
[% INCLUDE 'header.inc' %]
20
[% INCLUDE 'header.inc' %]
21
[% INCLUDE 'prefs-admin-search.inc' %]
21
[% INCLUDE 'prefs-admin-search.inc' %]
22
22
23
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
23
[% WRAPPER 'sub-header.inc' %]
24
    <ol>
24
    [% WRAPPER breadcrumbs %]
25
        <li>
25
        [% WRAPPER breadcrumb_item %]
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>
26
            <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
30
        </li>
27
        [% END %]
31
32
        [% IF op == 'add_form' %]
28
        [% IF op == 'add_form' %]
33
            <li>
29
            [% WRAPPER breadcrumb_item %]
34
                <a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a>
30
                <a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary loan batch statuses</a>
35
            </li>
31
            [% END %]
36
            <li>
32
            [% WRAPPER breadcrumb_item bc_active= 1 %]
37
                <a href="#" aria-current="page">
33
                [% IF status.id %]
38
                    [% IF status.id %]
34
                    <span>Modify batch status</span>
39
                        Modify
35
                [% ELSE %]
40
                    [% ELSE %]
36
                    <span>New batch status</span>
41
                        New
37
                [% END %]
42
                    [% END %] batch status
38
            [% END %]
43
                </a>
44
            </li>
45
46
        [% ELSE %]
39
        [% ELSE %]
47
            <li>
40
            [% WRAPPER breadcrumb_item bc_active= 1 %]
48
                <a href="#" aria-current="page">
41
                Interlibrary loan batch statuses
49
                    Interlibrary Loan batch statuses
42
            [% END %]
50
                </a>
51
            </li>
52
        [% END %]
43
        [% END %]
53
    </ol>
44
    [% END #/ WRAPPER breadcrumbs %]
54
</nav>
45
[% END #/ WRAPPER sub-header.inc %]
55
46
56
<div class="main container-fluid">
47
<div class="main container-fluid">
57
    <div class="row">
48
    <div class="row">
Lines 101-114 Link Here
101
                                </li>
92
                                </li>
102
                                <li>
93
                                <li>
103
                                    <label for="is_system">Is a system status: </label>
94
                                    <label for="is_system">Is a system status: </label>
104
                                    <strong>[% status.is_system ? "Yes" : "No" | html %]</strong>
95
                                    [% IF status.is_system %]
96
                                        <strong>Yes</strong>
97
                                    [% ELSE %]
98
                                        <strong>No</strong>
99
                                    [% END %]
105
                                    <input type="hidden" name="is_system" value="[% status.is_system | html %]" />
100
                                    <input type="hidden" name="is_system" value="[% status.is_system | html %]" />
106
                                </li>
101
                                </li>
107
                            </ol>
102
                            </ol>
108
                        </fieldset>
103
                        </fieldset>
109
104
110
                        <fieldset class="action">
105
                        <fieldset class="action">
111
                            <button id="save_batch_status" class="btn btn-default">Save</button>
106
                            <button id="save_batch_status" class="btn btn-primary">Save</button>
112
                            <a class="cancel" href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Cancel</a>
107
                            <a class="cancel" href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Cancel</a>
113
                        </fieldset>
108
                        </fieldset>
114
                    </form>
109
                    </form>
Lines 119-149 Link Here
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>
114
                        <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>
115
                    </div>
121
116
122
                    <h1>Interlibrary Loan batch statuses</h1>
117
                    <h1>Interlibrary loan batch statuses</h1>
123
                    [% IF statuses.count %]
118
                    [% IF statuses.count %]
124
                        <table id="table_batch_statuses">
119
                        <div class="page-section">
125
                            <thead>
120
                            <table id="table_batch_statuses">
126
                                <th>Name</th>
121
                                <thead>
127
                                <th>Code</th>
122
                                    <th>Name</th>
128
                                <th>Is system</th>
123
                                    <th>Code</th>
129
                                <th class="noExport">Actions</th>
124
                                    <th>Is system</th>
130
                            </thead>
125
                                    <th class="noExport">Actions</th>
131
                            <tbody>
126
                                </thead>
132
                                [% FOREACH status IN statuses %]
127
                                <tbody>
133
                                <tr>
128
                                    [% FOREACH status IN statuses %]
134
                                    <td>[% status.name | html %]</td>
129
                                    <tr>
135
                                    <td>[% status.code | html %]</td>
130
                                        <td>[% status.name | html %]</td>
136
                                    <td>[% status.is_system ? "Yes" : "No" | html %]</td>
131
                                        <td>[% status.code | html %]</td>
137
                                    <td class="actions">
132
                                        <td>[% status.is_system ? "Yes" : "No" | html %]</td>
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>
133
                                        <td class="actions">
139
                                        [% IF !status.is_system %]
134
                                            <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>
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>
135
                                            [% IF !status.is_system %]
141
                                        [% END %]
136
                                            <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>
142
                                    </td>
137
                                            [% END %]
143
                                </tr>
138
                                        </td>
144
                                [% END %]
139
                                    </tr>
145
                            </tbody>
140
                                    [% END %]
146
                        </table>
141
                                </tbody>
142
                            </table>
143
                        </page-section>
147
                    [% ELSE %]
144
                    [% ELSE %]
148
                        <div class="dialog message">
145
                        <div class="dialog message">
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>
146
                            There are no batch statuses defined. <a href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=add_form">Create new batch status</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (-4 / +5 lines)
Lines 669-675 Link Here
669
                                [% IF request.batch > 0 %]
669
                                [% IF request.batch > 0 %]
670
                                <li class="batch">
670
                                <li class="batch">
671
                                    <span class="label batch">Batch:</span>
671
                                    <span class="label batch">Batch:</span>
672
                                    <a href="/cgi-bin/koha/ill/ill-requests.pl?batch_id=[% request.batch.id | html %]">
672
                                    <a href="/cgi-bin/koha/ill/ill-requests.pl?batch_id=[% request.batch.id | uri %]">
673
                                    [% request.batch.name | html %]
673
                                    [% request.batch.name | html %]
674
                                    </a>
674
                                    </a>
675
                                </li>
675
                                </li>
Lines 806-814 Link Here
806
                [% ELSIF query_type == 'illlist' %]
806
                [% ELSIF query_type == 'illlist' %]
807
                    <!-- illlist -->
807
                    <!-- illlist -->
808
                    <h1>
808
                    <h1>
809
                        View ILL requests
809
                        [% IF !batch %]
810
                        [% IF batch %]
810
                        <span>View ILL requests</span>
811
                        for batch "[% batch.name | html %]"
811
                        [% ELSIF batch %]
812
                        <span>View ILL requests for batch "[% batch.name | html %]"</span>
812
                        [% END %]
813
                        [% END %]
813
                    </h1>
814
                    </h1>
814
                    <div id="results" class="page-section">
815
                    <div id="results" class="page-section">
(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js (-14 / +14 lines)
Lines 310-316 Link Here
310
            batch_id: batchId,
310
            batch_id: batchId,
311
            ill_backend_id: batch.data.backend,
311
            ill_backend_id: batch.data.backend,
312
            patron_id: batch.data.patron.borrowernumber,
312
            patron_id: batch.data.patron.borrowernumber,
313
            library_id: batch.data.branchcode,
313
            library_id: batch.data.library_id,
314
            extended_attributes: extended_attributes
314
            extended_attributes: extended_attributes
315
        };
315
        };
316
        window.doCreateSubmission(payload)
316
        window.doCreateSubmission(payload)
Lines 378-384 Link Here
378
            var option = document.createElement('option')
378
            var option = document.createElement('option')
379
            option.value = status.code;
379
            option.value = status.code;
380
            option.text = status.name;
380
            option.text = status.name;
381
            if (batch.data.id && batch.data.statuscode === status.code) {
381
            if (batch.data.batch_id && batch.data.statuscode === status.code) {
382
                option.selected = true;
382
                option.selected = true;
383
            }
383
            }
384
            statusesSelect.add(option);
384
            statusesSelect.add(option);
Lines 479-485 Link Here
479
        updateBatch()
479
        updateBatch()
480
            .then(function () {
480
            .then(function () {
481
                $('#ill-batch-modal').modal({ show: false });
481
                $('#ill-batch-modal').modal({ show: false });
482
                location.href = '/cgi-bin/koha/ill/ill-requests.pl?batch_id=' + batch.data.id;
482
                location.href = '/cgi-bin/koha/ill/ill-requests.pl?batch_id=' + batch.data.batch_id;
483
            });
483
            });
484
    };
484
    };
485
485
Lines 505-515 Link Here
505
            })
505
            })
506
            .then(function (jsoned) {
506
            .then(function (jsoned) {
507
                batch.data = {
507
                batch.data = {
508
                    id: jsoned.id,
508
                    batch_id: jsoned.batch_id,
509
                    name: jsoned.name,
509
                    name: jsoned.name,
510
                    backend: jsoned.backend,
510
                    backend: jsoned.backend,
511
                    cardnumber: jsoned.cardnumber,
511
                    cardnumber: jsoned.cardnumber,
512
                    branchcode: jsoned.branchcode,
512
                    library_id: jsoned.library_id,
513
                    statuscode: jsoned.statuscode
513
                    statuscode: jsoned.statuscode
514
                }
514
                }
515
                return jsoned;
515
                return jsoned;
Lines 534-540 Link Here
534
                name: nameInput.value,
534
                name: nameInput.value,
535
                backend: backend,
535
                backend: backend,
536
                cardnumber: cardnumberInput.value,
536
                cardnumber: cardnumberInput.value,
537
                branchcode: selectedBranchcode,
537
                library_id: selectedBranchcode,
538
                statuscode: selectedStatuscode
538
                statuscode: selectedStatuscode
539
            })
539
            })
540
        })
540
        })
Lines 545-557 Link Here
545
                return Promise.reject(response);
545
                return Promise.reject(response);
546
            })
546
            })
547
            .then(function (body) {
547
            .then(function (body) {
548
                batchId = body.id;
548
                batchId = body.batch_id;
549
                batch.data = {
549
                batch.data = {
550
                    id: body.id,
550
                    batch_id: body.batch_id,
551
                    name: body.name,
551
                    name: body.name,
552
                    backend: body.backend,
552
                    backend: body.backend,
553
                    cardnumber: body.patron.cardnumber,
553
                    cardnumber: body.patron.cardnumber,
554
                    branchcode: body.branchcode,
554
                    library_id: body.library_id,
555
                    statuscode: body.statuscode,
555
                    statuscode: body.statuscode,
556
                    patron: body.patron,
556
                    patron: body.patron,
557
                    status: body.status
557
                    status: body.status
Lines 572-578 Link Here
572
    function updateBatch() {
572
    function updateBatch() {
573
        var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
573
        var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
574
        var selectedStatuscode = statusesSelect.selectedOptions[0].value;
574
        var selectedStatuscode = statusesSelect.selectedOptions[0].value;
575
        return doBatchApiRequest('/' + batch.data.id, {
575
        return doBatchApiRequest('/' + batch.data.batch_id, {
576
            method: 'PUT',
576
            method: 'PUT',
577
            headers: {
577
            headers: {
578
                'Content-type': 'application/json'
578
                'Content-type': 'application/json'
Lines 581-587 Link Here
581
                name: nameInput.value,
581
                name: nameInput.value,
582
                backend: batch.data.backend,
582
                backend: batch.data.backend,
583
                cardnumber: batch.data.patron.cardnumber,
583
                cardnumber: batch.data.patron.cardnumber,
584
                branchcode: selectedBranchcode,
584
                library_id: selectedBranchcode,
585
                statuscode: selectedStatuscode
585
                statuscode: selectedStatuscode
586
            })
586
            })
587
        })
587
        })
Lines 966-972 Link Here
966
                {
966
                {
967
                    width: '18%',
967
                    width: '18%',
968
                    render: createActions,
968
                    render: createActions,
969
                    className: 'action-column'
969
                    className: 'action-column noExport'
970
                }
970
                }
971
            ],
971
            ],
972
            createdRow: function (row, data) {
972
            createdRow: function (row, data) {
Lines 1039-1051 Link Here
1039
    }
1039
    }
1040
1040
1041
    function manageBatchItemsDisplay() {
1041
    function manageBatchItemsDisplay() {
1042
        batchItemsDisplay.style.display = batch.data.id ? 'block' : 'none'
1042
        batchItemsDisplay.style.display = batch.data.batch_id ? 'block' : 'none'
1043
    };
1043
    };
1044
1044
1045
    function updateBatchInputs() {
1045
    function updateBatchInputs() {
1046
        nameInput.value = batch.data.name || '';
1046
        nameInput.value = batch.data.name || '';
1047
        cardnumberInput.value = batch.data.cardnumber || '';
1047
        cardnumberInput.value = batch.data.cardnumber || '';
1048
        branchcodeSelect.value = batch.data.branchcode || '';
1048
        branchcodeSelect.value = batch.data.library_id || '';
1049
    }
1049
    }
1050
1050
1051
    function debounce(func) {
1051
    function debounce(func) {
(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-table.js (-13 / +8 lines)
Lines 46-52 Link Here
46
            data: batchesProxy.data,
46
            data: batchesProxy.data,
47
            columns: [
47
            columns: [
48
                {
48
                {
49
                    data: 'id',
49
                    data: 'batch_id',
50
                    width: '10%'
50
                    width: '10%'
51
                },
51
                },
52
                {
52
                {
Lines 76-82 Link Here
76
                {
76
                {
77
                    render: createActions,
77
                    render: createActions,
78
                    width: '10%',
78
                    width: '10%',
79
                    orderable: false
79
                    orderable: false,
80
                    className: 'noExport'
80
                }
81
                }
81
            ],
82
            ],
82
            processing: true,
83
            processing: true,
Lines 93-99 Link Here
93
    // A render function for batch name
94
    // A render function for batch name
94
    var createName = function (x, y, data) {
95
    var createName = function (x, y, data) {
95
        var a = document.createElement('a');
96
        var a = document.createElement('a');
96
        a.setAttribute('href', '/cgi-bin/koha/ill/ill-requests.pl?batch_id=' + data.id);
97
        a.setAttribute('href', '/cgi-bin/koha/ill/ill-requests.pl?batch_id=' + data.batch_id);
97
        a.setAttribute('title', data.name);
98
        a.setAttribute('title', data.name);
98
        a.textContent = data.name;
99
        a.textContent = data.name;
99
        return a.outerHTML;
100
        return a.outerHTML;
Lines 106-118 Link Here
106
107
107
    // A render function for our patron link
108
    // A render function for our patron link
108
    var createPatronLink = function (data) {
109
    var createPatronLink = function (data) {
109
        var link = document.createElement('a');
110
        return data ? $patron_to_html(data, { display_cardnumber: true, url: true }) : '';
110
        link.setAttribute('title', ill_batch_borrower_details);
111
        link.setAttribute('href', '/cgi-bin/koha/members/moremember.pl?borrowernumber=' + data.borrowernumber);
112
        var displayText = [data.firstname, data.surname].join(' ') + ' ( ' + data.cardnumber + ' )';
113
        link.appendChild(document.createTextNode(displayText));
114
115
        return link.outerHTML;
116
    };
111
    };
117
112
118
    // A render function for our row action buttons
113
    // A render function for our row action buttons
Lines 123-135 Link Here
123
        var editButton = document.createElement('button');
118
        var editButton = document.createElement('button');
124
        editButton.setAttribute('type', 'button');
119
        editButton.setAttribute('type', 'button');
125
        editButton.setAttribute('class', 'editButton btn btn-xs btn-default');
120
        editButton.setAttribute('class', 'editButton btn btn-xs btn-default');
126
        editButton.setAttribute('data-batch-id', row.id);
121
        editButton.setAttribute('data-batch-id', row.batch_id);
127
        editButton.appendChild(document.createTextNode(ill_batch_edit));
122
        editButton.appendChild(document.createTextNode(ill_batch_edit));
128
123
129
        var deleteButton = document.createElement('button');
124
        var deleteButton = document.createElement('button');
130
        deleteButton.setAttribute('type', 'button');
125
        deleteButton.setAttribute('type', 'button');
131
        deleteButton.setAttribute('class', 'deleteButton btn btn-xs btn-danger');
126
        deleteButton.setAttribute('class', 'deleteButton btn btn-xs btn-danger');
132
        deleteButton.setAttribute('data-batch-id', row.id);
127
        deleteButton.setAttribute('data-batch-id', row.batch_id);
133
        deleteButton.appendChild(document.createTextNode(ill_batch_delete));
128
        deleteButton.appendChild(document.createTextNode(ill_batch_delete));
134
129
135
        div.appendChild(editButton);
130
        div.appendChild(editButton);
Lines 201-207 Link Here
201
    // Remove a batch from our proxy data
196
    // Remove a batch from our proxy data
202
    var removeBatch = function(id) {
197
    var removeBatch = function(id) {
203
        batchesProxy.data = batchesProxy.data.filter(function (batch) {
198
        batchesProxy.data = batchesProxy.data.filter(function (batch) {
204
            return batch.id != id;
199
            return batch.batch_id != id;
205
        });
200
        });
206
    };
201
    };
207
202
(-)a/t/db_dependent/IllbatchStatuses.t (-72 / +100 lines)
Lines 30-36 use Test::MockModule; Link Here
30
30
31
use Test::More tests => 13;
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;
35
use_ok('Koha::IllbatchStatus');
35
use_ok('Koha::IllbatchStatus');
36
use_ok('Koha::IllbatchStatuses');
36
use_ok('Koha::IllbatchStatuses');
Lines 48-84 my $effects = { Link Here
48
48
49
# Mock a logger so we can check it is called
49
# Mock a logger so we can check it is called
50
my $logger = Test::MockModule->new('Koha::Illrequest::Logger');
50
my $logger = Test::MockModule->new('Koha::Illrequest::Logger');
51
$logger->mock('log_something', sub {
51
$logger->mock(
52
    my ($self, $to_log ) = @_;
52
    'log_something',
53
    $effects->{$to_log->{actionname}} ++;
53
    sub {
54
});
54
        my ( $self, $to_log ) = @_;
55
        $effects->{ $to_log->{actionname} }++;
56
    }
57
);
55
58
56
# Create a batch status
59
# Create a batch status
57
my $status = $builder->build({
60
my $status = $builder->build(
58
    source => 'IllbatchStatus',
61
    {
59
    value => {
62
        source => 'IllbatchStatus',
60
        name      => "Feeling the call to the Dark Side",
63
        value  => {
61
        code      => "OH_NO",
64
            name      => "Feeling the call to the Dark Side",
62
        is_system => 1
65
            code      => "OH_NO",
66
            is_system => 1
67
        }
63
    }
68
    }
64
});
69
);
65
70
66
my $status_obj = Koha::IllbatchStatuses->find({ code => $status->{code} });
71
my $status_obj = Koha::IllbatchStatuses->find( { code => $status->{code} } );
67
isa_ok( $status_obj, 'Koha::IllbatchStatus' );
72
isa_ok( $status_obj, 'Koha::IllbatchStatus' );
68
73
69
# Try to delete the status, it's a system status, so this should fail
74
# Try to delete the status, it's a system status, so this should fail
70
$status_obj->delete_and_log;
75
$status_obj->delete_and_log;
71
my $status_obj_del = Koha::IllbatchStatuses->find({ code => $status->{code} });
76
my $status_obj_del = Koha::IllbatchStatuses->find( { code => $status->{code} } );
72
isa_ok( $status_obj_del, 'Koha::IllbatchStatus' );
77
isa_ok( $status_obj_del, 'Koha::IllbatchStatus' );
73
78
74
## Status create
79
## Status create
75
80
76
# Try creating a duplicate status
81
# Try creating a duplicate status
77
my $status2 = Koha::IllbatchStatus->new({
82
my $status2 = Koha::IllbatchStatus->new(
78
    name => "Obi-wan",
83
    {
79
    code => $status->{code},
84
        name      => "Obi-wan",
80
    is_system => 0
85
        code      => $status->{code},
81
});
86
        is_system => 0
87
    }
88
);
82
is_deeply(
89
is_deeply(
83
    $status2->create_and_log,
90
    $status2->create_and_log,
84
    { error => "Duplicate status found" },
91
    { error => "Duplicate status found" },
Lines 86-96 is_deeply( Link Here
86
);
93
);
87
94
88
# Create a non-duplicate status and ensure that the logger is called
95
# Create a non-duplicate status and ensure that the logger is called
89
my $status3 = Koha::IllbatchStatus->new({
96
my $status3 = Koha::IllbatchStatus->new(
90
    name => "Kylo",
97
    {
91
    code => "DARK_SIDE",
98
        name      => "Kylo",
92
    is_system => 0
99
        code      => "DARK_SIDE",
93
});
100
        is_system => 0
101
    }
102
);
94
$status3->create_and_log;
103
$status3->create_and_log;
95
is(
104
is(
96
    $effects->{'batch_status_create'},
105
    $effects->{'batch_status_create'},
Lines 99-125 is( Link Here
99
);
108
);
100
109
101
# Try creating a system status and ensure it's not created
110
# Try creating a system status and ensure it's not created
102
my $cannot_create_system = Koha::IllbatchStatus->new({
111
my $cannot_create_system = Koha::IllbatchStatus->new(
103
    name => "Jar Jar Binks",
112
    {
104
    code => "GUNGAN",
113
        name      => "Jar Jar Binks",
105
    is_system => 1
114
        code      => "GUNGAN",
106
});
115
        is_system => 1
116
    }
117
);
107
$cannot_create_system->create_and_log;
118
$cannot_create_system->create_and_log;
108
my $created_but_not_system = Koha::IllbatchStatuses->find({ code => "GUNGAN" });
119
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");
120
is( $created_but_not_system->{is_system}, undef, "is_system statuses cannot be created" );
110
121
111
## Status update
122
## Status update
112
123
113
# Ensure only name can be updated
124
# Ensure only name can be updated
114
$status3->update_and_log({
125
$status3->update_and_log(
115
    name      => "Rey",
126
    {
116
    code      => "LIGHT_SIDE",
127
        name      => "Rey",
117
    is_system => 1
128
        code      => "LIGHT_SIDE",
118
});
129
        is_system => 1
130
    }
131
);
132
119
# Get our updated status, if we can get it by it's code, we know that hasn't changed
133
# Get our updated status, if we can get it by it's code, we know that hasn't changed
120
my $not_updated = Koha::IllbatchStatuses->find({ code => "DARK_SIDE" })->unblessed;
134
my $not_updated = Koha::IllbatchStatuses->find( { code => "DARK_SIDE" } )->unblessed;
121
is($not_updated->{is_system}, 0, "is_system cannot be changed");
135
is( $not_updated->{is_system}, 0,     "is_system cannot be changed" );
122
is($not_updated->{name}, "Rey", "name can be changed");
136
is( $not_updated->{name},      "Rey", "name can be changed" );
137
123
# Ensure the logger is called
138
# Ensure the logger is called
124
is(
139
is(
125
    $effects->{'batch_status_update'},
140
    $effects->{'batch_status_update'},
Lines 128-148 is( Link Here
128
);
143
);
129
144
130
## Status delete
145
## Status delete
131
my $cannot_delete = Koha::IllbatchStatus->new({
146
my $cannot_delete = Koha::IllbatchStatus->new(
132
    name => "Palapatine",
147
    {
133
    code => "SITH",
148
        name      => "Palapatine",
134
    is_system => 1
149
        code      => "SITH",
135
})->store;
150
        is_system => 1
136
my $can_delete = Koha::IllbatchStatus->new({
151
    }
137
    name => "Windu",
152
)->store;
138
    code => "JEDI",
153
my $can_delete = Koha::IllbatchStatus->new(
139
    is_system => 0
154
    {
140
});
155
        name      => "Windu",
156
        code      => "JEDI",
157
        is_system => 0
158
    }
159
);
141
$cannot_delete->delete_and_log;
160
$cannot_delete->delete_and_log;
142
my $not_deleted = Koha::IllbatchStatuses->find({ code => "SITH" });
161
my $not_deleted = Koha::IllbatchStatuses->find( { code => "SITH" } );
143
isa_ok( $not_deleted, 'Koha::IllbatchStatus', "is_system statuses cannot be deleted" );
162
isa_ok( $not_deleted, 'Koha::IllbatchStatus', "is_system statuses cannot be deleted" );
144
$can_delete->create_and_log;
163
$can_delete->create_and_log;
145
$can_delete->delete_and_log;
164
$can_delete->delete_and_log;
165
146
# Ensure the logger is called following a successful delete
166
# Ensure the logger is called following a successful delete
147
is(
167
is(
148
    $effects->{'batch_status_delete'},
168
    $effects->{'batch_status_delete'},
Lines 151-183 is( Link Here
151
);
171
);
152
172
153
# Create a system "UNKNOWN" status
173
# Create a system "UNKNOWN" status
154
my $status_unknown = Koha::IllbatchStatus->new({
174
my $status_unknown = Koha::IllbatchStatus->new(
155
    name => "Unknown",
175
    {
156
    code => "UNKNOWN",
176
        name      => "Unknown",
157
    is_system => 1
177
        code      => "UNKNOWN",
158
});
178
        is_system => 1
179
    }
180
);
159
$status_unknown->create_and_log;
181
$status_unknown->create_and_log;
182
160
# Create a batch and assign it a status
183
# Create a batch and assign it a status
161
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
184
my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
162
my $library = $builder->build_object({ class => 'Koha::Libraries' });
185
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
163
my $status5 = Koha::IllbatchStatus->new({
186
my $status5 = Koha::IllbatchStatus->new(
164
    name => "Plagueis",
187
    {
165
    code => "DEAD_SITH",
188
        name      => "Plagueis",
166
    is_system => 0
189
        code      => "DEAD_SITH",
167
});
190
        is_system => 0
191
    }
192
);
168
$status5->create_and_log;
193
$status5->create_and_log;
169
my $batch = Koha::Illbatch->new({
194
my $batch = Koha::Illbatch->new(
170
    name           => "My test batch",
195
    {
171
    borrowernumber => $patron->borrowernumber,
196
        name           => "My test batch",
172
    branchcode     => $library->branchcode,
197
        borrowernumber => $patron->borrowernumber,
173
    backend        => "TEST",
198
        branchcode     => $library->branchcode,
174
    statuscode     => $status5->code
199
        backend        => "TEST",
175
});
200
        statuscode     => $status5->code
201
    }
202
);
176
$batch->create_and_log;
203
$batch->create_and_log;
204
177
# Delete the batch status and ensure the batch's status has been changed
205
# Delete the batch status and ensure the batch's status has been changed
178
# to UNKNOWN
206
# to UNKNOWN
179
$status5->delete_and_log;
207
$status5->delete_and_log;
180
my $updated_code = Koha::Illbatches->find({ statuscode => "UNKNOWN" });
208
my $updated_code = Koha::Illbatches->find( { statuscode => "UNKNOWN" } );
181
is($updated_code->statuscode, "UNKNOWN", "batches attached to deleted status have status changed to UNKNOWN");
209
is( $updated_code->statuscode, "UNKNOWN", "batches attached to deleted status have status changed to UNKNOWN" );
182
210
183
$schema->storage->txn_rollback;
211
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Illbatches.t (-26 / +28 lines)
Lines 30-36 use Test::MockModule; Link Here
30
30
31
use Test::More tests => 8;
31
use Test::More tests => 8;
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;
35
use_ok('Koha::Illbatch');
35
use_ok('Koha::Illbatch');
36
use_ok('Koha::Illbatches');
36
use_ok('Koha::Illbatches');
Lines 40-82 $schema->storage->txn_begin; Link Here
40
Koha::Illrequests->search->delete;
40
Koha::Illrequests->search->delete;
41
41
42
# Create a patron
42
# Create a patron
43
my $patron = $builder->build({ source => 'Borrower' });
43
my $patron = $builder->build( { source => 'Borrower' } );
44
44
45
# Create a librarian
45
# Create a librarian
46
my $librarian = $builder->build({
46
my $librarian = $builder->build(
47
    source => 'Borrower',
47
    {
48
    value => {
48
        source => 'Borrower',
49
        firstname => "Grogu"
49
        value  => { firstname => "Grogu" }
50
    }
50
    }
51
});
51
);
52
52
53
# Create a branch
53
# Create a branch
54
my $branch = $builder->build({
54
my $branch = $builder->build( { source => 'Branch' } );
55
    source => 'Branch'
56
});
57
55
58
# Create a batch
56
# Create a batch
59
my $illbatch = $builder->build({
57
my $illbatch = $builder->build(
60
    source => 'Illbatch',
58
    {
61
    value => {
59
        source => 'Illbatch',
62
        name  => "My test batch",
60
        value  => {
63
        backend  => "Mock",
61
            name           => "My test batch",
64
        borrowernumber => $librarian->{borrowernumber},
62
            backend        => "Mock",
65
        branchcode => $branch->{branchcode}
63
            borrowernumber => $librarian->{borrowernumber},
64
            branchcode     => $branch->{branchcode}
65
        }
66
    }
66
    }
67
});
67
);
68
my $batch_obj = Koha::Illbatches->find($illbatch->{id});
68
my $batch_obj = Koha::Illbatches->find( $illbatch->{id} );
69
isa_ok( $batch_obj, 'Koha::Illbatch' );
69
isa_ok( $batch_obj, 'Koha::Illbatch' );
70
70
71
# Create an ILL request in the batch
71
# Create an ILL request in the batch
72
my $illrq = $builder->build({
72
my $illrq = $builder->build(
73
    source => 'Illrequest',
73
    {
74
    value => {
74
        source => 'Illrequest',
75
        borrowernumber => $patron->{borrowernumber},
75
        value  => {
76
        batch_id       => $illbatch->{id}
76
            borrowernumber => $patron->{borrowernumber},
77
            batch_id       => $illbatch->{id}
78
        }
77
    }
79
    }
78
});
80
);
79
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
81
my $illrq_obj = Koha::Illrequests->find( $illrq->{illrequest_id} );
80
82
81
# Check requests_count
83
# Check requests_count
82
my $requests_count = $batch_obj->requests_count;
84
my $requests_count = $batch_obj->requests_count;
(-)a/t/db_dependent/api/v1/ill_requests.t (-18 / +49 lines)
Lines 144-149 subtest 'list() tests' => sub { Link Here
144
            class => 'Koha::Illrequests',
144
            class => 'Koha::Illrequests',
145
            value => {
145
            value => {
146
                borrowernumber => $patron->borrowernumber,
146
                borrowernumber => $patron->borrowernumber,
147
                batch_id       => undef,
147
                status         => $request_status->{code},
148
                status         => $request_status->{code},
148
                backend        => $backend->name,
149
                backend        => $backend->name,
149
                notesstaff     => '1'
150
                notesstaff     => '1'
Lines 154-159 subtest 'list() tests' => sub { Link Here
154
        {
155
        {
155
            class => 'Koha::Illrequests',
156
            class => 'Koha::Illrequests',
156
            value => {
157
            value => {
158
                batch_id     => undef,
157
                status       => $request_status->{code},
159
                status       => $request_status->{code},
158
                backend      => $backend->name,
160
                backend      => $backend->name,
159
                status_alias => $av->authorised_value,
161
                status_alias => $av->authorised_value,
Lines 291-299 subtest 'add() tests' => sub { Link Here
291
    my $backend = Test::MockObject->new;
293
    my $backend = Test::MockObject->new;
292
    $backend->set_isa('Koha::Illbackends::Mock');
294
    $backend->set_isa('Koha::Illbackends::Mock');
293
    $backend->set_always('name', 'Mock');
295
    $backend->set_always('name', 'Mock');
294
    $backend->set_always('capabilities', sub {
296
295
        return $illrequest;
296
    } );
297
    $backend->mock(
297
    $backend->mock(
298
        'metadata',
298
        'metadata',
299
        sub {
299
        sub {
Lines 310-341 subtest 'add() tests' => sub { Link Here
310
310
311
    # Mock Koha::Illrequest::load_backend (to load Mocked Backend)
311
    # Mock Koha::Illrequest::load_backend (to load Mocked Backend)
312
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
312
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
313
    $illreqmodule->mock( 'load_backend',
313
    $illreqmodule->mock(
314
        'load_backend',
314
        sub { my $self = shift; $self->{_my_backend} = $backend; return $self }
315
        sub { my $self = shift; $self->{_my_backend} = $backend; return $self }
315
    );
316
    );
316
317
318
    $illreqmodule->mock(
319
        '_backend',
320
        sub {
321
            my $self = shift;
322
            $self->{_my_backend} = $backend if ($backend);
323
324
            return $self;
325
            }
326
    );
327
328
    $illreqmodule->mock(
329
        'capabilities',
330
        sub {
331
            my ( $self, $name ) = @_;
332
333
            my $capabilities = {
334
335
                create_api => sub {
336
                    my ($body, $request ) = @_;
337
338
                    my $api_req = $builder->build_object(
339
                        {
340
                            class => 'Koha::Illrequests',
341
                            value => {
342
                                borrowernumber => $patron->borrowernumber,
343
                                batch_id       => undef,
344
                                status         => 'NEW',
345
                                backend        => $backend->name,
346
                            }
347
                        }
348
                    );
349
350
                    return $api_req;
351
                }
352
            };
353
354
            return $capabilities->{$name};
355
        }
356
    );
357
317
    $schema->storage->txn_begin;
358
    $schema->storage->txn_begin;
318
359
319
    Koha::Illrequests->search->delete;
360
    Koha::Illrequests->search->delete;
320
361
321
    my $body = {
362
    my $body = {
322
        backend => 'Mock',
363
        ill_backend_id => 'Mock',
323
        borrowernumber => $patron->borrowernumber,
364
        patron_id => $patron->borrowernumber,
324
        branchcode => $library->branchcode,
365
        library_id => $library->branchcode
325
        metadata => {
326
            article_author => "Jessop, E. G.",
327
            article_title => "Sleep",
328
            issn => "0957-4832",
329
            issue => "2",
330
            pages => "89-90",
331
            publisher => "OXFORD UNIVERSITY PRESS",
332
            title => "Journal of public health medicine.",
333
            year => "2001"
334
        }
335
    };
366
    };
336
367
337
    ## Authorized user test
368
    ## Authorized user test
338
    $t->post_ok( "//$userid:$password@/api/v1/illrequests" => json => $body)
369
    $t->post_ok( "//$userid:$password@/api/v1/ill/requests" => json => $body)
339
      ->status_is(201);
370
      ->status_is(201);
340
371
341
    $schema->storage->txn_rollback;
372
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/api/v1/illbatches.t (-153 / +99 lines)
Lines 47-62 subtest 'list() tests' => sub { Link Here
47
        {
47
        {
48
            class => 'Koha::Patrons',
48
            class => 'Koha::Patrons',
49
            value => {
49
            value => {
50
                flags => 2 ** 22 # 22 => ill
50
                flags => 2**22    # 22 => ill
51
            }
51
            }
52
        }
52
        }
53
    );
53
    );
54
54
55
    my $branch = $builder->build_object(
55
    my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
56
        {
57
            class => 'Koha::Libraries'
58
        }
59
    );
60
56
61
    my $password = 'sheev_is_da_boss!';
57
    my $password = 'sheev_is_da_boss!';
62
    $librarian->set_password( { password => $password, skip_validation => 1 } );
58
    $librarian->set_password( { password => $password, skip_validation => 1 } );
Lines 64-122 subtest 'list() tests' => sub { Link Here
64
60
65
    ## Authorized user tests
61
    ## Authorized user tests
66
    # No batches, so empty array should be returned
62
    # No batches, so empty array should be returned
67
    $t->get_ok("//$userid:$password@/api/v1/illbatches")
63
    $t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_is( [] );
68
      ->status_is(200)
64
69
      ->json_is( [] );
65
    my $batch = $builder->build_object(
70
66
        {
71
    my $batch = $builder->build_object({
67
            class => 'Koha::Illbatches',
72
        class => 'Koha::Illbatches',
68
            value => {
73
        value => {
69
                name           => "PapaPalpatine",
74
            name           => "PapaPalpatine",
70
                backend        => "Mock",
75
            backend        => "Mock",
71
                borrowernumber => $librarian->borrowernumber,
76
            borrowernumber => $librarian->borrowernumber,
72
                branchcode     => $branch->branchcode
77
            branchcode => $branch->branchcode
73
            }
78
        }
74
        }
79
    });
75
    );
80
76
81
    my $illrq = $builder->build({
77
    my $illrq = $builder->build(
82
        source => 'Illrequest',
78
        {
83
        value => {
79
            source => 'Illrequest',
84
            borrowernumber => $librarian->borrowernumber,
80
            value  => {
85
            batch_id       => $batch->id
81
                borrowernumber => $librarian->borrowernumber,
82
                batch_id       => $batch->id
83
            }
86
        }
84
        }
87
    });
85
    );
88
86
89
    # One batch created, should get returned
87
    # One batch created, should get returned
90
    $t->get_ok("//$userid:$password@/api/v1/illbatches")
88
    $t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_has( '/0/batch_id', 'Batch ID' )
91
      ->status_is(200)
89
        ->json_has( '/0/name',           'Batch name' )->json_has( '/0/backend', 'Backend name' )
92
      ->json_has( '/0/id', 'Batch ID' )
90
        ->json_has( '/0/patron_id',      'Borrowernumber' )->json_has( '/0/library_id', 'Branchcode' )
93
      ->json_has( '/0/name', 'Batch name' )
91
        ->json_has( '/0/patron',         'patron embedded' )->json_has( '/0/branch', 'branch embedded' )
94
      ->json_has( '/0/backend', 'Backend name' )
92
        ->json_has( '/0/requests_count', 'request count' );
95
      ->json_has( '/0/borrowernumber', 'Borrowernumber' )
96
      ->json_has( '/0/branchcode', 'Branchcode' )
97
      ->json_has( '/0/patron', 'patron embedded' )
98
      ->json_has( '/0/branch', 'branch embedded' )
99
      ->json_has( '/0/requests_count', 'request count' );
100
93
101
    # Try to create a second batch with the same name, this should fail
94
    # Try to create a second batch with the same name, this should fail
102
    my $another_batch = $builder->build_object({ class => 'Koha::Illbatches', value => {
95
    my $another_batch = $builder->build_object( { class => 'Koha::Illbatches', value => { name => $batch->name } } );
103
        name => $batch->name
96
104
    } });
105
    # Create a second batch with a different name
97
    # Create a second batch with a different name
106
    my $batch_with_another_name = $builder->build_object({ class => 'Koha::Illbatches' });
98
    my $batch_with_another_name = $builder->build_object( { class => 'Koha::Illbatches' } );
107
99
108
    # Two batches created, they should both be returned
100
    # Two batches created, they should both be returned
109
    $t->get_ok("//$userid:$password@/api/v1/illbatches")
101
    $t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_has( '/0', 'has first batch' )
110
      ->status_is(200)
102
        ->json_has( '/1', 'has second batch' );
111
      ->json_has('/0', 'has first batch')
112
      ->json_has('/1', 'has second batch');
113
103
114
    my $patron = $builder->build_object(
104
    my $patron = $builder->build_object(
115
        {
105
        {
116
            class => 'Koha::Patrons',
106
            class => 'Koha::Patrons',
117
            value => {
107
            value => {
118
                cardnumber => 999,
108
                cardnumber => 999,
119
                flags => 0
109
                flags      => 0
120
            }
110
            }
121
        }
111
        }
122
    );
112
    );
Lines 125-132 subtest 'list() tests' => sub { Link Here
125
    my $unauth_userid = $patron->userid;
115
    my $unauth_userid = $patron->userid;
126
116
127
    # Unauthorized access
117
    # Unauthorized access
128
    $t->get_ok("//$unauth_userid:$password@/api/v1/illbatches")
118
    $t->get_ok("//$unauth_userid:$password@/api/v1/illbatches")->status_is(403);
129
      ->status_is(403);
130
119
131
    $schema->storage->txn_rollback;
120
    $schema->storage->txn_rollback;
132
};
121
};
Lines 154-207 subtest 'get() tests' => sub { Link Here
154
        }
143
        }
155
    );
144
    );
156
145
157
    my $branch = $builder->build_object(
146
    my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
147
148
    my $batch = $builder->build_object(
158
        {
149
        {
159
            class => 'Koha::Libraries'
150
            class => 'Koha::Illbatches',
151
            value => {
152
                name           => "LeiaOrgana",
153
                backend        => "Mock",
154
                borrowernumber => $librarian->borrowernumber,
155
                branchcode     => $branch->branchcode
156
            }
160
        }
157
        }
161
    );
158
    );
162
159
163
    my $batch = $builder->build_object({
164
        class => 'Koha::Illbatches',
165
        value => {
166
            name           => "LeiaOrgana",
167
            backend        => "Mock",
168
            borrowernumber => $librarian->borrowernumber,
169
            branchcode     => $branch->branchcode
170
        }
171
    });
172
173
174
    $patron->set_password( { password => $password, skip_validation => 1 } );
160
    $patron->set_password( { password => $password, skip_validation => 1 } );
175
    my $unauth_userid = $patron->userid;
161
    my $unauth_userid = $patron->userid;
176
162
177
    $t->get_ok( "//$userid:$password@/api/v1/illbatches/" . $batch->id )
163
    $t->get_ok( "//$userid:$password@/api/v1/illbatches/" . $batch->id )->status_is(200)
178
      ->status_is(200)
164
        ->json_has( '/batch_id',   'Batch ID' )->json_has( '/name', 'Batch name' )
179
      ->json_has( '/id', 'Batch ID' )
165
        ->json_has( '/backend',    'Backend name' )->json_has( '/patron_id', 'Borrowernumber' )
180
      ->json_has( '/name', 'Batch name' )
166
        ->json_has( '/library_id', 'Branchcode' )->json_has( '/patron', 'patron embedded' )
181
      ->json_has( '/backend', 'Backend name' )
167
        ->json_has( '/branch',     'branch embedded' )->json_has( '/requests_count', 'request count' );
182
      ->json_has( '/borrowernumber', 'Borrowernumber' )
168
183
      ->json_has( '/branchcode', 'Branchcode' )
169
    $t->get_ok( "//$unauth_userid:$password@/api/v1/illbatches/" . $batch->id )->status_is(403);
184
      ->json_has( '/patron', 'patron embedded' )
170
185
      ->json_has( '/branch', 'branch embedded' )
171
    my $batch_to_delete = $builder->build_object( { class => 'Koha::Illbatches' } );
186
      ->json_has( '/requests_count', 'request count' );
187
188
    $t->get_ok( "//$unauth_userid:$password@/api/v1/illbatches/" . $batch->id )
189
      ->status_is(403);
190
191
    my $batch_to_delete = $builder->build_object({ class => 'Koha::Illbatches' });
192
    my $non_existent_id = $batch_to_delete->id;
172
    my $non_existent_id = $batch_to_delete->id;
193
    $batch_to_delete->delete;
173
    $batch_to_delete->delete;
194
174
195
    $t->get_ok( "//$userid:$password@/api/v1/illbatches/$non_existent_id" )
175
    $t->get_ok("//$userid:$password@/api/v1/illbatches/$non_existent_id")->status_is(404)
196
      ->status_is(404)
176
        ->json_is( '/error' => 'ILL batch not found' );
197
      ->json_is( '/error' => 'ILL batch not found' );
198
177
199
    $schema->storage->txn_rollback;
178
    $schema->storage->txn_rollback;
200
};
179
};
201
180
202
subtest 'add() tests' => sub {
181
subtest 'add() tests' => sub {
203
182
204
    plan tests =>19;
183
    plan tests => 19;
205
184
206
    $schema->storage->txn_begin;
185
    $schema->storage->txn_begin;
207
186
Lines 225-253 subtest 'add() tests' => sub { Link Here
225
    $patron->set_password( { password => $password, skip_validation => 1 } );
204
    $patron->set_password( { password => $password, skip_validation => 1 } );
226
    my $unauth_userid = $patron->userid;
205
    my $unauth_userid = $patron->userid;
227
206
228
    my $branch = $builder->build_object(
207
    my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
229
        {
230
            class => 'Koha::Libraries'
231
        }
232
    );
233
208
234
    my $batch_status = $builder->build_object(
209
    my $batch_status = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
235
        {
236
            class => 'Koha::IllbatchStatuses'
237
        }
238
    );
239
210
240
    my $batch_metadata = {
211
    my $batch_metadata = {
241
        name           => "Anakin's requests",
212
        name       => "Anakin's requests",
242
        backend        => "Mock",
213
        backend    => "Mock",
243
        cardnumber     => $librarian->cardnumber,
214
        cardnumber => $librarian->cardnumber,
244
        branchcode     => $branch->branchcode,
215
        library_id => $branch->branchcode,
245
        statuscode     => $batch_status->code
216
        statuscode => $batch_status->code
246
    };
217
    };
247
218
248
    # Unauthorized attempt to write
219
    # Unauthorized attempt to write
249
    $t->post_ok("//$unauth_userid:$password@/api/v1/illbatches" => json => $batch_metadata)
220
    $t->post_ok( "//$unauth_userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(403);
250
      ->status_is(403);
251
221
252
    # Authorized attempt to write invalid data
222
    # Authorized attempt to write invalid data
253
    my $batch_with_invalid_field = {
223
    my $batch_with_invalid_field = {
Lines 255-290 subtest 'add() tests' => sub { Link Here
255
        doh => 1
225
        doh => 1
256
    };
226
    };
257
227
258
    $t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_with_invalid_field )
228
    $t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_with_invalid_field )->status_is(400)
259
      ->status_is(400)
229
        ->json_is(
260
      ->json_is(
261
        "/errors" => [
230
        "/errors" => [
262
            {
231
            {
263
                message => "Properties not allowed: doh.",
232
                message => "Properties not allowed: doh.",
264
                path    => "/body"
233
                path    => "/body"
265
            }
234
            }
266
        ]
235
        ]
267
      );
236
        );
268
237
269
    # Authorized attempt to write
238
    # Authorized attempt to write
270
    my $batch_id =
239
    my $batch_id =
271
      $t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )
240
        $t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(201)
272
        ->status_is( 201 )
241
        ->json_is( '/name'       => $batch_metadata->{name} )->json_is( '/backend' => $batch_metadata->{backend} )
273
        ->json_is( '/name'           => $batch_metadata->{name} )
242
        ->json_is( '/patron_id'  => $librarian->borrowernumber )
274
        ->json_is( '/backend'        => $batch_metadata->{backend} )
243
        ->json_is( '/library_id' => $batch_metadata->{library_id} )->json_is( '/statuscode' => $batch_status->code )
275
        ->json_is( '/borrowernumber' => $librarian->borrowernumber )
244
        ->json_has('/patron')->json_has('/status')->json_has('/requests_count')->json_has('/branch');
276
        ->json_is( '/branchcode'     => $batch_metadata->{branchcode} )
277
        ->json_is( '/statuscode'     => $batch_status->code )
278
        ->json_has( '/patron' )
279
        ->json_has( '/status' )
280
        ->json_has( '/requests_count' )
281
        ->json_has( '/branch' );
282
245
283
    # Authorized attempt to create with null id
246
    # Authorized attempt to create with null id
284
    $batch_metadata->{id} = undef;
247
    $batch_metadata->{id} = undef;
285
    $t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )
248
    $t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(400)
286
      ->status_is(400)
249
        ->json_has('/errors');
287
      ->json_has('/errors');
288
250
289
    $schema->storage->txn_rollback;
251
    $schema->storage->txn_rollback;
290
};
252
};
Lines 315-395 subtest 'update() tests' => sub { Link Here
315
    $patron->set_password( { password => $password, skip_validation => 1 } );
277
    $patron->set_password( { password => $password, skip_validation => 1 } );
316
    my $unauth_userid = $patron->userid;
278
    my $unauth_userid = $patron->userid;
317
279
318
    my $branch = $builder->build_object(
280
    my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
319
        {
320
            class => 'Koha::Libraries'
321
        }
322
    );
323
281
324
    my $batch_id = $builder->build_object({ class => 'Koha::Illbatches' } )->id;
282
    my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id;
325
283
326
    # Unauthorized attempt to update
284
    # Unauthorized attempt to update
327
    $t->put_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" => json => { name => 'These are not the droids you are looking for' } )
285
    $t->put_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" => json =>
328
      ->status_is(403);
286
            { name => 'These are not the droids you are looking for' } )->status_is(403);
329
287
330
    my $batch_status = $builder->build_object(
288
    my $batch_status = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
331
        {
332
            class => 'Koha::IllbatchStatuses'
333
        }
334
    );
335
289
336
    # Attempt partial update on a PUT
290
    # Attempt partial update on a PUT
337
    my $batch_with_missing_field = {
291
    my $batch_with_missing_field = {
338
        backend => "Mock",
292
        backend    => "Mock",
339
        borrowernumber => $librarian->borrowernumber,
293
        patron_id  => $librarian->borrowernumber,
340
        branchcode => $branch->branchcode,
294
        library_id => $branch->branchcode,
341
        statuscode => $batch_status->code
295
        statuscode => $batch_status->code
342
    };
296
    };
343
297
344
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_missing_field )
298
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_missing_field )
345
      ->status_is(400)
299
        ->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
346
      ->json_is( "/errors" =>
347
          [ { message => "Missing property.", path => "/body/name" } ]
348
      );
349
300
350
    # Full object update on PUT
301
    # Full object update on PUT
351
    my $batch_with_updated_field = {
302
    my $batch_with_updated_field = {
352
        name           => "Master Ploo Koon",
303
        name       => "Master Ploo Koon",
353
        backend        => "Mock",
304
        backend    => "Mock",
354
        borrowernumber => $librarian->borrowernumber,
305
        patron_id  => $librarian->borrowernumber,
355
        branchcode => $branch->branchcode,
306
        library_id => $branch->branchcode,
356
        statuscode => $batch_status->code
307
        statuscode => $batch_status->code
357
    };
308
    };
358
309
359
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
310
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
360
      ->status_is(200)
311
        ->status_is(200)->json_is( '/name' => 'Master Ploo Koon' );
361
      ->json_is( '/name' => 'Master Ploo Koon' );
362
312
363
    # Authorized attempt to write invalid data
313
    # Authorized attempt to write invalid data
364
    my $batch_with_invalid_field = {
314
    my $batch_with_invalid_field = {
365
        doh  => 1,
315
        doh     => 1,
366
        name => "Master Mace Windu",
316
        name    => "Master Mace Windu",
367
        backend => "Mock"
317
        backend => "Mock"
368
    };
318
    };
369
319
370
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_invalid_field )
320
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_invalid_field )
371
      ->status_is(400)
321
        ->status_is(400)->json_is(
372
      ->json_is(
373
        "/errors" => [
322
        "/errors" => [
374
            {
323
            {
375
                message => "Properties not allowed: doh.",
324
                message => "Properties not allowed: doh.",
376
                path    => "/body"
325
                path    => "/body"
377
            }
326
            }
378
        ]
327
        ]
379
    );
328
        );
380
329
381
    my $batch_to_delete = $builder->build_object({ class => 'Koha::Cities' });
330
    my $batch_to_delete = $builder->build_object( { class => 'Koha::Cities' } );
382
    my $non_existent_id = $batch_to_delete->id;
331
    my $non_existent_id = $batch_to_delete->id;
383
    $batch_to_delete->delete;
332
    $batch_to_delete->delete;
384
333
385
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$non_existent_id" => json => $batch_with_updated_field )
334
    $t->put_ok( "//$userid:$password@/api/v1/illbatches/$non_existent_id" => json => $batch_with_updated_field )
386
      ->status_is(404);
335
        ->status_is(404);
387
336
388
    # Wrong method (POST)
337
    # Wrong method (POST)
389
    $batch_with_updated_field->{id} = 2;
338
    $batch_with_updated_field->{id} = 2;
390
339
391
    $t->post_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
340
    $t->post_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
392
      ->status_is(404);
341
        ->status_is(404);
393
342
394
    $schema->storage->txn_rollback;
343
    $schema->storage->txn_rollback;
395
};
344
};
Lines 420-436 subtest 'delete() tests' => sub { Link Here
420
    $patron->set_password( { password => $password, skip_validation => 1 } );
369
    $patron->set_password( { password => $password, skip_validation => 1 } );
421
    my $unauth_userid = $patron->userid;
370
    my $unauth_userid = $patron->userid;
422
371
423
    my $batch_id = $builder->build_object({ class => 'Koha::Illbatches' })->id;
372
    my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id;
424
373
425
    # Unauthorized attempt to delete
374
    # Unauthorized attempt to delete
426
    $t->delete_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" )
375
    $t->delete_ok("//$unauth_userid:$password@/api/v1/illbatches/$batch_id")->status_is(403);
427
      ->status_is(403);
428
376
429
    $t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")
377
    $t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")->status_is(204);
430
      ->status_is(204);
431
378
432
    $t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")
379
    $t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")->status_is(404);
433
      ->status_is(404);
434
380
435
    $schema->storage->txn_rollback;
381
    $schema->storage->txn_rollback;
436
};
382
};
(-)a/t/db_dependent/api/v1/illbatchstatuses.t (-99 / +71 lines)
Lines 46-52 subtest 'list() tests' => sub { Link Here
46
        {
46
        {
47
            class => 'Koha::Patrons',
47
            class => 'Koha::Patrons',
48
            value => {
48
            value => {
49
                flags => 2 ** 22 # 22 => ill
49
                flags => 2**22    # 22 => ill
50
            }
50
            }
51
        }
51
        }
52
    );
52
    );
Lines 56-81 subtest 'list() tests' => sub { Link Here
56
56
57
    ## Authorized user tests
57
    ## Authorized user tests
58
    # No statuses, so empty array should be returned
58
    # No statuses, so empty array should be returned
59
    $t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")
59
    $t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")->status_is(200)->json_is( [] );
60
      ->status_is(200)
60
61
      ->json_is( [] );
61
    my $status = $builder->build_object(
62
62
        {
63
    my $status = $builder->build_object({
63
            class => 'Koha::IllbatchStatuses',
64
        class => 'Koha::IllbatchStatuses',
64
            value => {
65
        value => {
65
                name      => "Han Solo",
66
            name           => "Han Solo",
66
                code      => "SOLO",
67
            code           => "SOLO",
67
                is_system => 0
68
            is_system      => 0
68
            }
69
        }
69
        }
70
    });
70
    );
71
71
72
    # One batch created, should get returned
72
    # One batch created, should get returned
73
    $t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")
73
    $t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")->status_is(200)->json_has( '/0/id', 'ID' )
74
      ->status_is(200)
74
        ->json_has( '/0/name', 'Name' )->json_has( '/0/code', 'Code' )->json_has( '/0/is_system', 'is_system' );
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
75
80
    $schema->storage->txn_rollback;
76
    $schema->storage->txn_rollback;
81
};
77
};
Lines 96-109 subtest 'get() tests' => sub { Link Here
96
    $librarian->set_password( { password => $password, skip_validation => 1 } );
92
    $librarian->set_password( { password => $password, skip_validation => 1 } );
97
    my $userid = $librarian->userid;
93
    my $userid = $librarian->userid;
98
94
99
    my $status = $builder->build_object({
95
    my $status = $builder->build_object(
100
        class => 'Koha::IllbatchStatuses',
96
        {
101
        value => {
97
            class => 'Koha::IllbatchStatuses',
102
            name           => "Han Solo",
98
            value => {
103
            code           => "SOLO",
99
                name      => "Han Solo",
104
            is_system      => 0
100
                code      => "SOLO",
101
                is_system => 0
102
            }
105
        }
103
        }
106
    });
104
    );
107
105
108
    # Unauthorised user
106
    # Unauthorised user
109
    my $patron = $builder->build_object(
107
    my $patron = $builder->build_object(
Lines 115-144 subtest 'get() tests' => sub { Link Here
115
    $patron->set_password( { password => $password, skip_validation => 1 } );
113
    $patron->set_password( { password => $password, skip_validation => 1 } );
116
    my $unauth_userid = $patron->userid;
114
    my $unauth_userid = $patron->userid;
117
115
118
    $t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $status->code )
116
    $t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $status->code )->status_is(200)
119
      ->status_is(200)
117
        ->json_has( '/id',        'ID' )->json_has( '/name', 'Name' )->json_has( '/code', 'Code' )
120
      ->json_has( '/id', 'ID' )
118
        ->json_has( '/is_system', 'is_system' );
121
      ->json_has( '/name', 'Name' )
122
      ->json_has( '/code', 'Code' )
123
      ->json_has( '/is_system', 'is_system' );
124
119
125
    $t->get_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $status->id )
120
    $t->get_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $status->id )->status_is(403);
126
      ->status_is(403);
127
121
128
    my $status_to_delete = $builder->build_object({ class => 'Koha::IllbatchStatuses' });
122
    my $status_to_delete  = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
129
    my $non_existent_code = $status_to_delete->code;
123
    my $non_existent_code = $status_to_delete->code;
130
    $status_to_delete->delete;
124
    $status_to_delete->delete;
131
125
132
    $t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" )
126
    $t->get_ok("//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code")->status_is(404)
133
      ->status_is(404)
127
        ->json_is( '/error' => 'ILL batch status not found' );
134
      ->json_is( '/error' => 'ILL batch status not found' );
135
128
136
    $schema->storage->txn_rollback;
129
    $schema->storage->txn_rollback;
137
};
130
};
138
131
139
subtest 'add() tests' => sub {
132
subtest 'add() tests' => sub {
140
133
141
    plan tests =>14;
134
    plan tests => 14;
142
135
143
    $schema->storage->txn_begin;
136
    $schema->storage->txn_begin;
144
137
Lines 162-175 subtest 'add() tests' => sub { Link Here
162
    my $unauth_userid = $patron->userid;
155
    my $unauth_userid = $patron->userid;
163
156
164
    my $status_metadata = {
157
    my $status_metadata = {
165
        name           => "In a bacta tank",
158
        name      => "In a bacta tank",
166
        code           => "BACTA",
159
        code      => "BACTA",
167
        is_system      => 0
160
        is_system => 0
168
    };
161
    };
169
162
170
    # Unauthorized attempt to write
163
    # Unauthorized attempt to write
171
    $t->post_ok("//$unauth_userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata)
164
    $t->post_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )->status_is(403);
172
      ->status_is(403);
173
165
174
    # Authorized attempt to write invalid data
166
    # Authorized attempt to write invalid data
175
    my $status_with_invalid_field = {
167
    my $status_with_invalid_field = {
Lines 177-207 subtest 'add() tests' => sub { Link Here
177
        doh => 1
169
        doh => 1
178
    };
170
    };
179
171
180
    $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_with_invalid_field )
172
    $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_with_invalid_field )->status_is(400)
181
      ->status_is(400)
173
        ->json_is(
182
      ->json_is(
183
        "/errors" => [
174
        "/errors" => [
184
            {
175
            {
185
                message => "Properties not allowed: doh.",
176
                message => "Properties not allowed: doh.",
186
                path    => "/body"
177
                path    => "/body"
187
            }
178
            }
188
        ]
179
        ]
189
      );
180
        );
190
181
191
    # Authorized attempt to write
182
    # Authorized attempt to write
192
    my $status_id =
183
    my $status_id =
193
      $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )
184
        $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )->status_is(201)
194
        ->status_is( 201 )
185
        ->json_has( '/id',        'ID' )->json_has( '/name', 'Name' )->json_has( '/code', 'Code' )
195
        ->json_has( '/id', 'ID' )
196
        ->json_has( '/name', 'Name' )
197
        ->json_has( '/code', 'Code' )
198
        ->json_has( '/is_system', 'is_system' );
186
        ->json_has( '/is_system', 'is_system' );
199
187
200
    # Authorized attempt to create with null id
188
    # Authorized attempt to create with null id
201
    $status_metadata->{id} = undef;
189
    $status_metadata->{id} = undef;
202
    $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )
190
    $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )->status_is(400)
203
      ->status_is(400)
191
        ->json_has('/errors');
204
      ->json_has('/errors');
205
192
206
    $schema->storage->txn_rollback;
193
    $schema->storage->txn_rollback;
207
};
194
};
Lines 231-241 subtest 'update() tests' => sub { Link Here
231
    $patron->set_password( { password => $password, skip_validation => 1 } );
218
    $patron->set_password( { password => $password, skip_validation => 1 } );
232
    my $unauth_userid = $patron->userid;
219
    my $unauth_userid = $patron->userid;
233
220
234
    my $status_code = $builder->build_object({ class => 'Koha::IllbatchStatuses' } )->code;
221
    my $status_code = $builder->build_object( { class => 'Koha::IllbatchStatuses' } )->code;
235
222
236
    # Unauthorized attempt to update
223
    # 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' } )
224
    $t->put_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/$status_code" => json =>
238
      ->status_is(403);
225
            { name => 'These are not the droids you are looking for' } )->status_is(403);
239
226
240
    # Attempt partial update on a PUT
227
    # Attempt partial update on a PUT
241
    my $status_with_missing_field = {
228
    my $status_with_missing_field = {
Lines 244-264 subtest 'update() tests' => sub { Link Here
244
    };
231
    };
245
232
246
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_missing_field )
233
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_missing_field )
247
      ->status_is(400)
234
        ->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
248
      ->json_is( "/errors" =>
249
          [ { message => "Missing property.", path => "/body/name" } ]
250
      );
251
235
252
    # Full object update on PUT
236
    # Full object update on PUT
253
    my $status_with_updated_field = {
237
    my $status_with_updated_field = {
254
        name           => "Master Ploo Koon",
238
        name      => "Master Ploo Koon",
255
        code           => $status_code,
239
        code      => $status_code,
256
        is_system      => 0
240
        is_system => 0
257
    };
241
    };
258
242
259
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_updated_field )
243
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_updated_field )
260
      ->status_is(200)
244
        ->status_is(200)->json_is( '/name' => 'Master Ploo Koon' );
261
      ->json_is( '/name' => 'Master Ploo Koon' );
262
245
263
    # Authorized attempt to write invalid data
246
    # Authorized attempt to write invalid data
264
    my $status_with_invalid_field = {
247
    my $status_with_invalid_field = {
Lines 268-289 subtest 'update() tests' => sub { Link Here
268
    };
251
    };
269
252
270
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_invalid_field )
253
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_invalid_field )
271
      ->status_is(400)
254
        ->status_is(400)->json_is(
272
      ->json_is(
273
        "/errors" => [
255
        "/errors" => [
274
            {
256
            {
275
                message => "Properties not allowed: doh.",
257
                message => "Properties not allowed: doh.",
276
                path    => "/body"
258
                path    => "/body"
277
            }
259
            }
278
        ]
260
        ]
279
    );
261
        );
280
262
281
    my $status_to_delete = $builder->build_object({ class => 'Koha::IllbatchStatuses' });
263
    my $status_to_delete  = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
282
    my $non_existent_code = $status_to_delete->code;
264
    my $non_existent_code = $status_to_delete->code;
283
    $status_to_delete->delete;
265
    $status_to_delete->delete;
284
266
285
    $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" => json => $status_with_updated_field )
267
    $t->put_ok(
286
      ->status_is(404);
268
        "//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" => json => $status_with_updated_field )
269
        ->status_is(404);
287
270
288
    $schema->storage->txn_rollback;
271
    $schema->storage->txn_rollback;
289
};
272
};
Lines 314-352 subtest 'delete() tests' => sub { Link Here
314
    $patron->set_password( { password => $password, skip_validation => 1 } );
297
    $patron->set_password( { password => $password, skip_validation => 1 } );
315
    my $unauth_userid = $patron->userid;
298
    my $unauth_userid = $patron->userid;
316
299
317
    my $non_system_status = $builder->build_object({
300
    my $non_system_status = $builder->build_object(
318
        class => 'Koha::IllbatchStatuses',
301
        {
319
        value => {
302
            class => 'Koha::IllbatchStatuses',
320
            is_system => 0
303
            value => { is_system => 0 }
321
        }
304
        }
322
    });
305
    );
323
306
324
    my $system_status = $builder->build_object({
307
    my $system_status = $builder->build_object(
325
        class => 'Koha::IllbatchStatuses',
308
        {
326
        value => {
309
            class => 'Koha::IllbatchStatuses',
327
            is_system => 1
310
            value => { is_system => 1 }
328
        }
311
        }
329
    });
312
    );
330
313
331
    # Unauthorized attempt to delete
314
    # Unauthorized attempt to delete
332
    $t->delete_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )
315
    $t->delete_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )->status_is(403);
333
      ->status_is(403);
334
316
335
    $t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )
317
    $t->delete_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )->status_is(204);
336
      ->status_is(204);
337
318
338
    $t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )
319
    $t->delete_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )->status_is(404);
339
      ->status_is(404);
340
320
341
    $t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $system_status->code )
321
    $t->delete_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $system_status->code )->status_is(400)
342
      ->status_is(400)
322
        ->json_is( "/errors" => [ { message => "ILL batch status cannot be deleted" } ] );
343
      ->json_is(
344
        "/errors" => [
345
            {
346
                message => "ILL batch status cannot be deleted"
347
            }
348
        ]
349
      );
350
323
351
    $schema->storage->txn_rollback;
324
    $schema->storage->txn_rollback;
352
};
325
};
353
- 

Return to bug 30719