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

(-)a/Koha/Illcomment.pm (+58 lines)
Line 0 Link Here
1
package Koha::Illcomment;
2
3
# Copyright Magnus Enger Libriotech 2017
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15
# details.
16
#
17
# You should have received a copy of the GNU General Public License along with
18
# Koha; if not, write to the Free Software Foundation, Inc., 51 Franklin
19
# Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21
use Modern::Perl;
22
use Koha::Database;
23
use base qw(Koha::Object);
24
25
=head1 NAME
26
27
Koha::Illcomment - Koha Illcomment Object class
28
29
=head2 Class methods
30
31
=head3 patron
32
33
=cut
34
35
sub patron {
36
    my ( $self ) = @_;
37
    return Koha::Patron->_new_from_dbic(
38
        scalar $self->_result->borrowernumber
39
    );
40
}
41
42
=head2 Internal methods
43
44
=head3 _type
45
46
=cut
47
48
sub _type {
49
    return 'Illcomment';
50
}
51
52
=head1 AUTHOR
53
54
Magnus Enger <magnus@libriotech.no>
55
56
=cut
57
58
1;
(-)a/Koha/Illcomments.pm (+18 lines)
Line 0 Link Here
1
package Koha::Illcomments;
2
3
# TODO Add POD
4
5
use Modern::Perl;
6
use Koha::Database;
7
use Koha::Illcomment;
8
use base qw(Koha::Objects);
9
10
sub _type {
11
    return 'Illcomments';
12
}
13
14
sub object_class {
15
    return 'Koha::Illcomment';
16
}
17
18
1;
(-)a/Koha/Illrequest.pm (+16 lines)
Lines 29-34 use Try::Tiny; Link Here
29
use Koha::Database;
29
use Koha::Database;
30
use Koha::Email;
30
use Koha::Email;
31
use Koha::Exceptions::Ill;
31
use Koha::Exceptions::Ill;
32
use Koha::Illcomments;
32
use Koha::Illrequestattributes;
33
use Koha::Illrequestattributes;
33
use Koha::Patron;
34
use Koha::Patron;
34
35
Lines 119-124 sub illrequestattributes { Link Here
119
    );
120
    );
120
}
121
}
121
122
123
=head3 illcomments
124
125
=cut
126
127
sub illcomments {
128
    my ( $self ) = @_;
129
    return Koha::Illcomments->_new_from_dbic(
130
        scalar $self->_result->illcomments
131
    );
132
}
133
122
=head3 patron
134
=head3 patron
123
135
124
=cut
136
=cut
Lines 1023-1028 sub TO_JSON { Link Here
1023
                $self->branchcode
1035
                $self->branchcode
1024
            )->TO_JSON;
1036
            )->TO_JSON;
1025
        }
1037
        }
1038
        # Augment the request response with the number of comments if appropriate
1039
        if ( $embed->{comments} ) {
1040
            $object->{comments} = $self->illcomments->count;
1041
        }
1026
    }
1042
    }
1027
1043
1028
    return $object;
1044
    return $object;
(-)a/ill/ill-requests.pl (-1 / +24 lines)
Lines 24-31 use CGI; Link Here
24
use C4::Auth;
24
use C4::Auth;
25
use C4::Output;
25
use C4::Output;
26
use Koha::AuthorisedValues;
26
use Koha::AuthorisedValues;
27
use Koha::Illcomment;
27
use Koha::Illrequests;
28
use Koha::Illrequests;
28
use Koha::Libraries;
29
use Koha::Libraries;
30
use Koha::Token;
29
31
30
use Try::Tiny;
32
use Try::Tiny;
31
33
Lines 63-69 if ( $backends_available ) { Link Here
63
        my $request = Koha::Illrequests->find($params->{illrequest_id});
65
        my $request = Koha::Illrequests->find($params->{illrequest_id});
64
66
65
        $template->param(
67
        $template->param(
66
            request => $request
68
            request    => $request,
69
            csrf_token => Koha::Token->new->generate_csrf({
70
                session_id => scalar $cgi->cookie('CGISESSID'),
71
            }),
67
        );
72
        );
68
73
69
    } elsif ( $op eq 'create' ) {
74
    } elsif ( $op eq 'create' ) {
Lines 232-237 if ( $backends_available ) { Link Here
232
                prefilters => $active_filters
237
                prefilters => $active_filters
233
            );
238
            );
234
        }
239
        }
240
241
    } elsif ( $op eq "save_comment" ) {
242
        die "Wrong CSRF token" unless Koha::Token->new->check_csrf({
243
           session_id => scalar $cgi->cookie('CGISESSID'),
244
           token      => scalar $cgi->param('csrf_token'),
245
        });
246
        my $comment = Koha::Illcomment->new({
247
            illrequest_id  => scalar $params->{illrequest_id},
248
            borrowernumber => $patronnumber,
249
            comment        => scalar $params->{comment},
250
        });
251
        $comment->store();
252
        # Redirect to view the whole request
253
        print $cgi->redirect("/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=".
254
            scalar $params->{illrequest_id}
255
        );
256
        exit;
257
235
    } else {
258
    } else {
236
        my $request = Koha::Illrequests->find($params->{illrequest_id});
259
        my $request = Koha::Illrequests->find($params->{illrequest_id});
237
        my $backend_result = $request->custom_capability($op, $params);
260
        my $backend_result = $request->custom_capability($op, $params);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (-2 / +51 lines)
Lines 49-55 Link Here
49
            'status',
49
            'status',
50
            'updated',
50
            'updated',
51
            'illrequest_id',
51
            'illrequest_id',
52
            'action'
52
            'comments',
53
            'action' // Action should always be last
53
        ];
54
        ];
54
55
55
        // Remove any fields we're ignoring
56
        // Remove any fields we're ignoring
Lines 198-203 Link Here
198
            $('#requestattributes').toggleClass('content_hidden');
199
            $('#requestattributes').toggleClass('content_hidden');
199
        });
200
        });
200
201
202
        // Toggle new comment form in Illview
203
        $('#toggle_addcomment').on('click', function(e) {
204
            e.preventDefault();
205
            $('#addcomment').toggleClass('content_hidden');
206
        });
207
201
        // Filter partner list
208
        // Filter partner list
202
        $('#partner_filter').keyup(function() {
209
        $('#partner_filter').keyup(function() {
203
            var needle = $('#partner_filter').val();
210
            var needle = $('#partner_filter').val();
Lines 218-224 Link Here
218
        // Get our data from the API and process it prior to passing
225
        // Get our data from the API and process it prior to passing
219
        // it to datatables
226
        // it to datatables
220
        var ajax = $.ajax(
227
        var ajax = $.ajax(
221
            '/api/v1/illrequests?embed=metadata,patron,capabilities,library'
228
            '/api/v1/illrequests?embed=metadata,patron,capabilities,library,comments'
222
            ).done(function() {
229
            ).done(function() {
223
                var data = JSON.parse(ajax.responseText);
230
                var data = JSON.parse(ajax.responseText);
224
                // Make a copy, we'll be removing columns next and need
231
                // Make a copy, we'll be removing columns next and need
Lines 576-581 Link Here
576
                        </div>
583
                        </div>
577
                    </div>
584
                    </div>
578
585
586
                    <div id="ill-view-panel" class="panel panel-default">
587
                        <div class="panel-heading">
588
                            <h3>[% request.illcomments.count %] comments</h3>
589
                        </div>
590
                        <div class="panel-body">
591
                            [% IF request.illcomments.count && request.illcomments.count > 0 %]
592
                                [% FOREACH comment IN request.illcomments %]
593
                                    <div class="rows comment_[% comment.patron.categorycode %]">
594
                                    <h5>Comment by:
595
                                    <a href="[% borrowerlink %]" title="View borrower details">
596
                                    [% comment.patron.firstname _ " " _ comment.patron.surname _ " [" _ comment.patron.cardnumber _ "]" | html %]</a>
597
                                    [% comment.timestamp | $KohaDates with_hours => 1 %]</h5>
598
                                    <p>[% comment.comment | html %]</p>
599
                                    </div>
600
                                [% END %]
601
                            [% END %]
602
                                <div class="rows">
603
                                    <h3><a id="toggle_addcomment" href="#">Add comment</a></h3>
604
                                    <div id="addcomment" class="content_hidden">
605
                                        <form class="validated" method="post" action="/cgi-bin/koha/ill/ill-requests.pl">
606
                                            <input type="hidden" value="save_comment" name="method">
607
                                            <input type="hidden" value="[% csrf_token %]" name="csrf_token">
608
                                            <input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id">
609
                                            <fieldset class="rows">
610
                                                <ol>
611
                                                    <li>
612
                                                        <label class="required" for="comment">Comment: </label>
613
                                                        <textarea type="text" class="required" required="required" value="" cols="80" rows="10" id="comment" name="comment"></textarea>
614
                                                        <span class="required">Required</span>
615
                                                    </li>
616
                                                </ol>
617
                                            </fieldset>
618
                                            <fieldset class="action">
619
                                                <input type="submit" value="Submit">
620
                                            </fieldset>
621
                                        </form>
622
                                    </div>
623
                                </div>
624
                            </div>
625
                    </div>
626
579
                [% ELSIF query_type == 'illlist' %]
627
                [% ELSIF query_type == 'illlist' %]
580
                    <!-- illlist -->
628
                    <!-- illlist -->
581
                    <h1>View ILL requests</h1>
629
                    <h1>View ILL requests</h1>
Lines 593-598 Link Here
593
                                    <th>Status</th>
641
                                    <th>Status</th>
594
                                    <th>Updated on</th>
642
                                    <th>Updated on</th>
595
                                    <th>Request number</th>
643
                                    <th>Request number</th>
644
                                    <th>Comments</th>
596
                                    <th class="actions"></th>
645
                                    <th class="actions"></th>
597
                                </tr>
646
                                </tr>
598
                            </thead>
647
                            </thead>
(-)a/t/db_dependent/Illcomments.t (-1 / +84 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use File::Basename qw/basename/;
21
use Koha::Database;
22
use Koha::Illrequests;
23
use Koha::Illrequestattributes;
24
use Koha::Illrequest::Config;
25
use Koha::Patrons;
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
use Test::MockObject;
29
use Test::MockModule;
30
31
use Test::More tests => 9;
32
33
my $schema = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
35
use_ok('Koha::Illcomment');
36
use_ok('Koha::Illcomments');
37
38
$schema->storage->txn_begin;
39
40
Koha::Illrequests->search->delete;
41
42
# Create a patron
43
my $patron = $builder->build({ source => 'Borrower' });
44
45
# Create an ILL request
46
my $illrq = $builder->build({
47
    source => 'Illrequest',
48
    value => { borrowernumber => $patron->{borrowernumber} }
49
});
50
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
51
isa_ok( $illrq_obj, 'Koha::Illrequest' );
52
53
# Create a librarian
54
my $librarian = $builder->build({ source => 'Borrower' });
55
56
# Create a comment and tie it to the request and the librarian
57
my $comment_text = 'xyz';
58
my $illcomment = $builder->build({
59
    source => 'Illcomment',
60
    value => {
61
        illrequest_id  => $illrq_obj->illrequest_id,
62
        borrowernumber => $librarian->{borrowernumber},
63
        comment        => $comment_text,
64
    }
65
});
66
67
# Get all the comments
68
my $comments = $illrq_obj->illcomments;
69
isa_ok( $comments, 'Koha::Illcomments', "Illcomments" );
70
my @comments_list = $comments->as_list();
71
is( scalar @comments_list, 1, "We have 1 comment" );
72
73
# Get the first (and only) comment
74
my $comment = $comments->next();
75
isa_ok( $comment, 'Koha::Illcomment', "Illcomment" );
76
77
# Check the different data in the comment
78
is( $comment->illrequest_id,  $illrq_obj->illrequest_id,    'illrequest_id getter works' );
79
is( $comment->borrowernumber, $librarian->{borrowernumber}, 'borrowernumber getter works');
80
is( $comment->comment,        $comment_text,                'comment getter works');
81
82
$illrq_obj->delete;
83
84
$schema->storage->txn_rollback;

Return to bug 18591