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 234-239 if ( $backends_available ) { Link Here
234
                prefilters => $active_filters
239
                prefilters => $active_filters
235
            );
240
            );
236
        }
241
        }
242
243
    } elsif ( $op eq "save_comment" ) {
244
        die "Wrong CSRF token" unless Koha::Token->new->check_csrf({
245
           session_id => scalar $cgi->cookie('CGISESSID'),
246
           token      => scalar $cgi->param('csrf_token'),
247
        });
248
        my $comment = Koha::Illcomment->new({
249
            illrequest_id  => scalar $params->{illrequest_id},
250
            borrowernumber => $patronnumber,
251
            comment        => scalar $params->{comment},
252
        });
253
        $comment->store();
254
        # Redirect to view the whole request
255
        print $cgi->redirect("/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=".
256
            scalar $params->{illrequest_id}
257
        );
258
        exit;
259
237
    } else {
260
    } else {
238
        my $request = Koha::Illrequests->find($params->{illrequest_id});
261
        my $request = Koha::Illrequests->find($params->{illrequest_id});
239
        my $backend_result = $request->custom_capability($op, $params);
262
        my $backend_result = $request->custom_capability($op, $params);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (-2 / +57 lines)
Lines 51-57 Link Here
51
            'status',
51
            'status',
52
            'updated',
52
            'updated',
53
            'illrequest_id',
53
            'illrequest_id',
54
            'action'
54
            'comments',
55
            'action' // Action should always be last
55
        ];
56
        ];
56
57
57
        // Remove any fields we're ignoring
58
        // Remove any fields we're ignoring
Lines 194-199 Link Here
194
            }
195
            }
195
        };
196
        };
196
197
198
        // Toggle request attributes in Illview
199
        $('#toggle_requestattributes').on('click', function(e) {
200
            e.preventDefault();
201
            $('#requestattributes').toggleClass('content_hidden');
202
        });
203
204
        // Toggle new comment form in Illview
205
        $('#toggle_addcomment').on('click', function(e) {
206
            e.preventDefault();
207
            $('#addcomment').toggleClass('content_hidden');
208
        });
209
197
        // Filter partner list
210
        // Filter partner list
198
        $('#partner_filter').keyup(function() {
211
        $('#partner_filter').keyup(function() {
199
            var needle = $('#partner_filter').val();
212
            var needle = $('#partner_filter').val();
Lines 220-226 Link Here
220
        // Get our data from the API and process it prior to passing
233
        // Get our data from the API and process it prior to passing
221
        // it to datatables
234
        // it to datatables
222
        var ajax = $.ajax(
235
        var ajax = $.ajax(
223
            '/api/v1/illrequests?embed=metadata,patron,capabilities,library'
236
            '/api/v1/illrequests?embed=metadata,patron,capabilities,library,comments'
224
            ).done(function() {
237
            ).done(function() {
225
                var data = JSON.parse(ajax.responseText);
238
                var data = JSON.parse(ajax.responseText);
226
                // Make a copy, we'll be removing columns next and need
239
                // Make a copy, we'll be removing columns next and need
Lines 592-597 Link Here
592
                        </div>
605
                        </div>
593
                    </div>
606
                    </div>
594
607
608
                    <div id="ill-view-panel" class="panel panel-default">
609
                        <div class="panel-heading">
610
                            <h3>[% request.illcomments.count %] comments</h3>
611
                        </div>
612
                        <div class="panel-body">
613
                            [% IF request.illcomments.count && request.illcomments.count > 0 %]
614
                                [% FOREACH comment IN request.illcomments %]
615
                                    <div class="rows comment_[% comment.patron.categorycode %]">
616
                                    <h5>Comment by:
617
                                    <a href="[% borrowerlink %]" title="View borrower details">
618
                                    [% comment.patron.firstname _ " " _ comment.patron.surname _ " [" _ comment.patron.cardnumber _ "]" | html %]</a>
619
                                    [% comment.timestamp | $KohaDates with_hours => 1 %]</h5>
620
                                    <p>[% comment.comment | html %]</p>
621
                                    </div>
622
                                [% END %]
623
                            [% END %]
624
                                <div class="rows">
625
                                    <h3><a id="toggle_addcomment" href="#">Add comment</a></h3>
626
                                    <div id="addcomment" class="content_hidden">
627
                                        <form class="validated" method="post" action="/cgi-bin/koha/ill/ill-requests.pl">
628
                                            <input type="hidden" value="save_comment" name="method">
629
                                            <input type="hidden" value="[% csrf_token %]" name="csrf_token">
630
                                            <input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id">
631
                                            <fieldset class="rows">
632
                                                <ol>
633
                                                    <li>
634
                                                        <label class="required" for="comment">Comment: </label>
635
                                                        <textarea type="text" class="required" required="required" value="" cols="80" rows="10" id="comment" name="comment"></textarea>
636
                                                        <span class="required">Required</span>
637
                                                    </li>
638
                                                </ol>
639
                                            </fieldset>
640
                                            <fieldset class="action">
641
                                                <input type="submit" value="Submit">
642
                                            </fieldset>
643
                                        </form>
644
                                    </div>
645
                                </div>
646
                            </div>
647
                    </div>
648
595
                [% ELSIF query_type == 'illlist' %]
649
                [% ELSIF query_type == 'illlist' %]
596
                    <!-- illlist -->
650
                    <!-- illlist -->
597
                    <h1>View ILL requests</h1>
651
                    <h1>View ILL requests</h1>
Lines 609-614 Link Here
609
                                    <th>Status</th>
663
                                    <th>Status</th>
610
                                    <th>Updated on</th>
664
                                    <th>Updated on</th>
611
                                    <th>Request number</th>
665
                                    <th>Request number</th>
666
                                    <th>Comments</th>
612
                                    <th class="actions"></th>
667
                                    <th class="actions"></th>
613
                                </tr>
668
                                </tr>
614
                            </thead>
669
                            </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