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

(-)a/Koha/REST/V1/Biblios.pm (+71 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::Biblios;
22
use Koha::Biblios;
23
use Koha::Ratings;
23
use Koha::RecordProcessor;
24
use Koha::RecordProcessor;
24
use C4::Biblio qw( DelBiblio );
25
use C4::Biblio qw( DelBiblio );
25
26
Lines 409-412 sub get_items_public { Link Here
409
    };
410
    };
410
}
411
}
411
412
413
=head3 set_rating
414
415
Set rating for the logged in user
416
417
=cut
418
419
420
sub set_rating {
421
    my $c = shift->openapi->valid_input or return;
422
423
    my $biblio = Koha::Biblios->find( $c->validation->param('biblio_id') );
424
425
    unless ($biblio) {
426
        return $c->render(
427
            status  => 404,
428
            openapi => {
429
                error => "Object not found."
430
            }
431
        );
432
    }
433
434
    my $patron = $c->stash('koha.user');
435
    unless ($patron) {
436
        return $c->render(
437
            status => 403,
438
            openapi =>
439
                { error => "Cannot rate. Reason: must be logged-in" }
440
        );
441
    }
442
443
    my $body   = $c->validation->param('body');
444
    my $rating_value = $body->{rating};
445
446
    return try {
447
448
        my $rating = Koha::Ratings->find(
449
            {
450
                biblionumber   => $biblio->biblionumber,
451
                borrowernumber => $patron->borrowernumber,
452
            }
453
        );
454
        $rating->delete if $rating;
455
456
        if ( $rating_value ) { # Cannot set to 0 from the UI
457
            $rating = Koha::Rating->new(
458
                {
459
                    biblionumber   => $biblio->biblionumber,
460
                    borrowernumber => $patron->borrowernumber,
461
                    rating_value   => $rating_value,
462
                }
463
            )->store;
464
        };
465
        my $ratings =
466
          Koha::Ratings->search( { biblionumber => $biblio->biblionumber } );
467
        my $average = $ratings->get_avg_rating;
468
469
        return $c->render(
470
            status  => 200,
471
            openapi => {
472
                rating  => $rating && $rating->in_storage ? $rating->rating_value : undef,
473
                average => $average,
474
                count   => $ratings->count
475
            },
476
        );
477
    }
478
    catch {
479
        $c->unhandled_exception($_);
480
    };
481
}
482
412
1;
483
1;
(-)a/api/v1/swagger/paths/biblios.yaml (+66 lines)
Lines 383-385 Link Here
383
        description: Under maintenance
383
        description: Under maintenance
384
        schema:
384
        schema:
385
          $ref: "../swagger.yaml#/definitions/error"
385
          $ref: "../swagger.yaml#/definitions/error"
386
"/public/biblios/{biblio_id}/ratings":
387
  post:
388
    x-mojo-to: Biblios#set_rating
389
    operationId: setBiblioRating
390
    tags:
391
      - biblios
392
    summary: set biblio rating (public)
393
    parameters:
394
      - $ref: "../swagger.yaml#/parameters/biblio_id_pp"
395
      - name: body
396
        in: body
397
        description: A JSON object containing rating information
398
        schema:
399
          type: object
400
          properties:
401
            rating:
402
              description: the rating
403
              type:
404
                - integer
405
                - "null"
406
          required:
407
              - rating
408
          additionalProperties: false
409
    produces:
410
      - application/json
411
    responses:
412
      "200":
413
        description: Rating set
414
        schema:
415
          type: object
416
          properties:
417
            rating:
418
              description: user's rating
419
              type:
420
                - number
421
                - "null"
422
            average:
423
              description: average rating
424
              type: number
425
            count:
426
              description: number of ratings
427
              type: integer
428
          additionalProperties: false
429
      "401":
430
        description: Authentication required
431
        schema:
432
          $ref: "../swagger.yaml#/definitions/error"
433
      "403":
434
        description: Access forbidden
435
        schema:
436
          $ref: "../swagger.yaml#/definitions/error"
437
      "404":
438
        description: Biblio not found
439
        schema:
440
          $ref: "../swagger.yaml#/definitions/error"
441
      "500":
442
        description: |
443
          Internal server error. Possible `error_code` attribute values:
444
445
          * `internal_server_error`
446
        schema:
447
          $ref: "../swagger.yaml#/definitions/error"
448
      "503":
449
        description: Under maintenance
450
        schema:
451
          $ref: "../swagger.yaml#/definitions/error"
(-)a/api/v1/swagger/swagger.yaml (+2 lines)
Lines 207-212 paths: Link Here
207
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
207
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
208
  "/public/biblios/{biblio_id}/items":
208
  "/public/biblios/{biblio_id}/items":
209
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}~1items"
209
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}~1items"
210
  "/public/biblios/{biblio_id}/ratings":
211
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}~1ratings"
210
  /public/libraries:
212
  /public/libraries:
211
    $ref: ./paths/libraries.yaml#/~1public~1libraries
213
    $ref: ./paths/libraries.yaml#/~1public~1libraries
212
  "/public/libraries/{library_id}":
214
  "/public/libraries/{library_id}":
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc (+1 lines)
Lines 63-68 Link Here
63
<script>
63
<script>
64
    var Koha = {};
64
    var Koha = {};
65
    function _(s) { return s } // dummy function for gettext
65
    function _(s) { return s } // dummy function for gettext
66
    const is_logged_in = [% IF logged_in_user %]true[% ELSE %]false[% END %]
66
</script>
67
</script>
67
[% IF lang && lang != 'en' %]
68
[% IF lang && lang != 'en' %]
68
    [% Asset.js(lang _ '/js/locale_data.js') | $raw %]
69
    [% Asset.js(lang _ '/js/locale_data.js') | $raw %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (-56 / +14 lines)
Lines 299-313 Link Here
299
                    [% IF ( OpacStarRatings != 'disable' ) %]
299
                    [% IF ( OpacStarRatings != 'disable' ) %]
300
                        <form method="post" action="/cgi-bin/koha/opac-ratings.pl">
300
                        <form method="post" action="/cgi-bin/koha/opac-ratings.pl">
301
                            <legend class="sr-only">Star ratings</legend>
301
                            <legend class="sr-only">Star ratings</legend>
302
                            <div class="results_summary ratings">
302
                            <div class="results_summary ratings" id="rating-[% biblio.biblionumber | html %]">
303
303
304
                                [% SET rating_avg = ratings.get_avg_rating() %]
304
                                [% SET rating_avg = ratings.get_avg_rating() %]
305
                                [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %]
305
                                [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %]
306
306
307
                                [% IF ( borrowernumber ) %]
307
                                [% IF ( borrowernumber ) %]
308
                                    <select id="star_rating" name="rating" data-rating-enabled="1" autocomplete="off">
308
                                    <select id="star_rating" class="star_rating" name="rating" data-biblionumber="[% biblio.biblionumber | html %]" data-context="rating-[% biblio.biblionumber | html %]" autocomplete="off">
309
                                [% ELSE %]
309
                                [% ELSE %]
310
                                    <select id="star_rating" name="rating" data-rating-enabled="0" disabled="disabled" autocomplete="off">
310
                                    <select id="star_rating" class="star_rating" name="rating" disabled="disabled" autocomplete="off">
311
                                [% END %]
311
                                [% END %]
312
                                    [% IF ( rating_avg_int == 0 ) %]
312
                                    [% IF ( rating_avg_int == 0 ) %]
313
                                        <option value="" selected="selected"></option>
313
                                        <option value="" selected="selected"></option>
Lines 320-343 Link Here
320
                                        [% END %]
320
                                        [% END %]
321
                                    [% END %]
321
                                    [% END %]
322
                                </select>
322
                                </select>
323
                                <img id="rating-loading" style="display:none" src="[% interface | html %]/[% theme | html %]/images/spinner-small.gif" alt="" />
323
                                <img id="rating-loading" class="rating-loading" style="display:none" src="[% interface | html %]/[% theme | html %]/images/spinner-small.gif" alt="" />
324
324
325
                                <!-- define some hidden vars for ratings -->
325
                                <!-- define some hidden vars for ratings -->
326
326
327
                                <input  type="hidden" name='biblionumber'  value="[% biblio.biblionumber | html %]" />
327
                                <input  type="hidden" name='biblionumber'  value="[% biblio.biblionumber | html %]" />
328
                                <input  type="hidden" name='rating_value' id='rating_value' value="[% my_rating.rating_value | html %]" />
328
                                <input  type="hidden" name='rating_value' id='rating_value' class="rating_value" value="[% my_rating.rating_value | html %]" />
329
329
330
                                [% UNLESS ( rating_readonly ) %]&nbsp;  <input name="rate_button" type="submit" value="Rate me" />[% END %]&nbsp;
330
                                [% UNLESS ( rating_readonly ) %]&nbsp;  <input name="rate_button" type="submit" value="Rate me" />[% END %]&nbsp;
331
331
332
                                [% IF my_rating %]
332
                                [% IF my_rating %]
333
                                    <span id="rating_value_text">Your rating: [% my_rating.rating_value | html %].</span>
333
                                    <span id="rating_value_text" class="rating_value_text">Your rating: [% my_rating.rating_value | html %].</span>
334
                                    <span id="cancel_rating_text"><a href="#"><i class="fa fa-remove" aria-hidden="true"></i> Cancel rating</a>.</span>
334
                                    <span id="cancel_rating_text" class="cancel_rating_text"><a href="#" data-context="star_rating"><i class="fa fa-remove" aria-hidden="true"></i> Cancel rating.</a></span>
335
                                [% ELSE %]
335
                                [% ELSE %]
336
                                    <span id="rating_value_text"></span>
336
                                    <span id="rating_value_text" class="rating_value_text"></span>
337
                                    <span id="cancel_rating_text" style="display:none;"><a href="#"><i class="fa fa-remove" aria-hidden="true"></i> Cancel rating</a>.</span>
337
                                    <span id="cancel_rating_text" class="cancel_rating_text" style="display: none;"><a href="#" data-context="star_rating"><i class="fa fa-remove" aria-hidden="true"></i> Cancel rating.</a></span>
338
                                [% END %]
338
                                [% END %]
339
339
340
                                <span id="rating_text">Average rating: [% rating_avg | html %] ([% ratings.count | html %] votes)</span>
340
                                <span id="rating_text" class="rating_text">Average rating: [% rating_avg | html %] ([% ratings.count | html %] votes)</span>
341
                            </div>
341
                            </div>
342
                        </form>
342
                        </form>
343
                    [% END # / IF OpacStarRatings != 'disable' %]
343
                    [% END # / IF OpacStarRatings != 'disable' %]
Lines 1432-1438 Link Here
1432
    [% INCLUDE 'datatables.inc' %]
1432
    [% INCLUDE 'datatables.inc' %]
1433
    [% INCLUDE 'columns_settings.inc' %]
1433
    [% INCLUDE 'columns_settings.inc' %]
1434
    [% INCLUDE greybox.inc %]
1434
    [% INCLUDE greybox.inc %]
1435
    [% IF ( OpacStarRatings != 'disable' ) %][% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %][% END %]
1435
    [% IF ( OpacStarRatings != 'disable' ) %]
1436
        [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %]
1437
        [% Asset.js("js/ratings.js") | $raw %]
1438
    [% END %]
1436
1439
1437
    [% IF ( OpacHighlightedWords ) %][% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %][% END %]
1440
    [% IF ( OpacHighlightedWords ) %][% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %][% END %]
1438
    [% IF ( Koha.Preference('OPACDetailQRCode') ) %]
1441
    [% IF ( Koha.Preference('OPACDetailQRCode') ) %]
Lines 1883-1933 Link Here
1883
                    });
1886
                    });
1884
                }());
1887
                }());
1885
            [% END # /IF ( OPACShelfBrowser ) %]
1888
            [% END # /IF ( OPACShelfBrowser ) %]
1886
1887
            [% IF ( OpacStarRatings != 'disable' ) %]
1888
                // -----------------------------------------------------
1889
                // star-ratings code
1890
                // -----------------------------------------------------
1891
                // hide 'rate' button if javascript enabled
1892
1893
                $('input[name="rate_button"]').remove();
1894
1895
                var rating_enabled = ( $("#star_rating").data("rating-enabled") == "1" ) ? false : true;
1896
                $('#star_rating').barrating({
1897
                    theme: 'fontawesome-stars',
1898
                    showSelectedRating: false,
1899
                    allowEmpty: true,
1900
                    deselectable: false,
1901
                    readonly: rating_enabled,
1902
                    onSelect: function(value, text) {
1903
                        $("#rating-loading").show();
1904
                        $.post("/cgi-bin/koha/opac-ratings-ajax.pl", {
1905
                            rating_old_value: $("#rating_value").attr("value"),
1906
                            borrowernumber: "[% borrowernumber | html %]",
1907
                            biblionumber: "[% biblio.biblionumber | html %]",
1908
                            rating_value: value,
1909
                            auth_error: value
1910
                        }, function (data) {
1911
                                $("#rating_value").val(data.rating_value);
1912
                                if (data.rating_value) {
1913
                                    $("#rating_value_text").text(_("Your rating: %s, ").format(data.rating_value));
1914
                                    $("#cancel_rating_text").show();
1915
                                } else {
1916
                                    $("#rating_value_text").text('');
1917
                                    $("#cancel_rating_text").hide();
1918
                                }
1919
                                $("#rating_text").text(_("Average rating: %s (%s votes)").format(data.rating_avg, data.rating_total));
1920
                                $("#rating-loading").hide();
1921
                        }, "json");
1922
                    }
1923
                });
1924
1925
                $("#cancel_rating_text a").on("click", function(e){
1926
                    e.preventDefault();
1927
                    $("#star_rating").barrating("set", "");
1928
                });
1929
1930
            [% END # / IF ( OpacStarRatings != 'disable' )%]
1931
        });
1889
        });
1932
1890
1933
        $(document).ready(function() {
1891
        $(document).ready(function() {
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt (-3 lines)
Lines 228-236 Link Here
228
            }
228
            }
229
        });
229
        });
230
    });
230
    });
231
    var borrowernumber = "[% logged_in_user.borrowernumber | html %]";
232
    var MSG_YOUR_RATING = _("Your rating: %s, ");
233
    var MSG_AVERAGE_RATING = _("Average rating: %s (%s votes)");
234
</script>
231
</script>
235
    [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %]
232
    [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %]
236
        [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %]
233
        [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt (-2 lines)
Lines 1347-1354 Link Here
1347
        }
1347
        }
1348
1348
1349
        var borrowernumber = "[% borrowernumber | html %]";
1349
        var borrowernumber = "[% borrowernumber | html %]";
1350
        var MSG_YOUR_RATING = _("Your rating: %s, ");
1351
        var MSG_AVERAGE_RATING = _("Average rating: %s (%s votes)");
1352
    </script>
1350
    </script>
1353
    [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %]
1351
    [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %]
1354
        [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %]
1352
        [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/global.js (+12 lines)
Lines 117-122 function confirmModal(message, title, yes_label, no_label, callback) { Link Here
117
    $("#bootstrap-confirm-box-modal").modal('show');
117
    $("#bootstrap-confirm-box-modal").modal('show');
118
}
118
}
119
119
120
121
// Function to check errors from AJAX requests
122
const checkError = function(response) {
123
    if (response.status >= 200 && response.status <= 299) {
124
        return response.json();
125
    } else {
126
        console.log("Server returned an error:");
127
        console.log(response);
128
        alert("%s (%s)".format(response.statusText, response.status));
129
    }
130
};
131
120
//Add jQuery :focusable selector
132
//Add jQuery :focusable selector
121
(function($) {
133
(function($) {
122
    function visible(element) {
134
    function visible(element) {
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/ratings.js (-13 / +20 lines)
Lines 1-4 Link Here
1
/* global borrowernumber MSG_YOUR_RATING MSG_AVERAGE_RATING */
2
// -----------------------------------------------------
1
// -----------------------------------------------------
3
// star-ratings code
2
// star-ratings code
4
// -----------------------------------------------------
3
// -----------------------------------------------------
Lines 14-40 $(document).ready(function(){ Link Here
14
        showSelectedRating: false,
13
        showSelectedRating: false,
15
        allowEmpty: true,
14
        allowEmpty: true,
16
        deselectable: false,
15
        deselectable: false,
16
        readonly: !is_logged_in,
17
        onSelect: function( value ) {
17
        onSelect: function( value ) {
18
            var context = $("#" + this.$elem.data("context") );
18
            var context = $("#" + this.$elem.data("context") );
19
            $(".rating-loading", context ).show();
19
            $(".rating-loading", context ).show();
20
            $.post("/cgi-bin/koha/opac-ratings-ajax.pl", {
20
            let biblionumber = this.$elem.data('biblionumber');
21
                rating_old_value: $(".rating_value", context ).attr("value"),
21
            if ( value == "" ) value = null;
22
                borrowernumber: borrowernumber,
22
            fetch("/api/v1/public/biblios/"+biblionumber+"/ratings", {
23
                biblionumber: this.$elem.data('biblionumber'),
23
                method: 'POST',
24
                rating_value: value,
24
                body: JSON.stringify({ rating: value }),
25
                auth_error: value
25
                headers: {
26
            }, function (data) {
26
                    "Content-Type": "application/json;charset=utf-8",
27
                $(".rating_value", context ).val(data.rating_value);
27
                }
28
                if (data.rating_value) {
28
            }).then(checkError)
29
                    $(".rating_value_text", context ).text( MSG_YOUR_RATING.format(data.rating_value) );
29
              .then((data) => {
30
                $(".rating_value", context ).val(data.rating);
31
                console.log(data);
32
                  console.log($(".cancel_rating_text", context ));
33
                if (data.rating) {
34
                    console.log(data.rating);
35
                    $(".rating_value_text", context ).text( __("Your rating: %s.").format(data.rating) );
30
                    $(".cancel_rating_text", context ).show();
36
                    $(".cancel_rating_text", context ).show();
31
                } else {
37
                } else {
32
                    $(".rating_value_text", context ).text("");
38
                    $(".rating_value_text", context ).text("");
33
                    $(".cancel_rating_text", context ).hide();
39
                    $(".cancel_rating_text", context ).hide();
34
                }
40
                }
35
                $(".rating_text", context ).text( MSG_AVERAGE_RATING.format(data.rating_avg, data.rating_total) );
41
                  console.log($(".rating_text", context ));
42
                $(".rating_text", context ).text( __("Average rating: %s (%s votes)").format(data.average, data.count) );
36
                $(".rating-loading", context ).hide();
43
                $(".rating-loading", context ).hide();
37
            }, "json");
44
            });
38
        }
45
        }
39
    });
46
    });
40
47
(-)a/opac/opac-ratings-ajax.pl (-116 lines)
Lines 1-116 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 KohaAloha, NZ
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
=head1 DESCRIPTION
21
22
A script that takes an ajax json query, and then inserts or modifies a star-rating.
23
24
=cut
25
26
use Modern::Perl;
27
28
use CGI qw ( -utf8 );
29
use CGI::Cookie;  # need to check cookies before having CGI parse the POST request
30
31
use C4::Auth qw( get_template_and_user check_cookie_auth );
32
use C4::Context;
33
use C4::Output qw( is_ajax output_ajax_with_http_headers );
34
35
use Koha::Ratings;
36
37
use JSON;
38
39
my $is_ajax = is_ajax();
40
41
my ( $query, $auth_status );
42
if ($is_ajax) {
43
    ( $query, $auth_status ) = &ajax_auth_cgi( {} );
44
}
45
else {
46
    $query = CGI->new();
47
}
48
49
my $biblionumber     = $query->param('biblionumber');
50
my $rating_value     = $query->param('rating_value');
51
my $rating_old_value = $query->param('rating_old_value');
52
53
my ( $template, $loggedinuser, $cookie );
54
if ($is_ajax) {
55
    $loggedinuser = C4::Context->userenv->{'number'};
56
}
57
else {
58
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
59
        {
60
            template_name   => "opac-detail.tt",
61
            query           => $query,
62
            type            => "opac",
63
            authnotrequired => 0,                    # auth required to add tags
64
        }
65
    );
66
}
67
68
my $rating;
69
$rating_value //= '';
70
71
if ( $rating_value eq '' ) {
72
    my $rating = Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser } );
73
    $rating->delete if $rating;
74
}
75
76
elsif ( $rating_value and !$rating_old_value ) {
77
    Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $loggedinuser, rating_value => $rating_value, })->store;
78
}
79
80
elsif ( $rating_value ne $rating_old_value ) {
81
    my $rating = Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser });
82
    $rating->rating_value($rating_value)->store if $rating
83
}
84
85
my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber });
86
my $my_rating = $ratings->search({ borrowernumber => $loggedinuser })->next;
87
my $avg = $ratings->get_avg_rating;
88
89
my %js_reply = (
90
    rating_total   => $ratings->count,
91
    rating_avg     => $avg,
92
    rating_avg_int => sprintf("%.0f", $avg),
93
    rating_value   => $my_rating ? $my_rating->rating_value : undef,
94
    auth_status    => $auth_status,
95
96
);
97
98
my $json_reply = JSON->new->encode( \%js_reply );
99
100
#### $rating
101
#### %js_reply
102
#### $json_reply
103
104
output_ajax_with_http_headers( $query, $json_reply );
105
exit;
106
107
# a ratings specific ajax return sub, returns CGI object, and an 'auth_success' value
108
sub ajax_auth_cgi {
109
    my $needed_flags = shift;
110
    my %cookies      = CGI::Cookie->fetch;
111
    my $input        = CGI->new;
112
    my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
113
    my ( $auth_status ) =
114
      check_cookie_auth( $sessid, $needed_flags );
115
    return $input, $auth_status;
116
}
(-)a/t/db_dependent/api/v1/biblios.t (-2 / +38 lines)
Lines 20-26 use Modern::Perl; Link Here
20
use utf8;
20
use utf8;
21
use Encode;
21
use Encode;
22
22
23
use Test::More tests => 7;
23
use Test::More tests => 8;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Mojo;
25
use Test::Mojo;
26
use Test::Warn;
26
use Test::Warn;
Lines 676-678 subtest 'get_checkouts() tests' => sub { Link Here
676
676
677
    $schema->storage->txn_rollback;
677
    $schema->storage->txn_rollback;
678
};
678
};
679
- 
679
680
subtest 'set_rating() tests' => sub {
681
682
    plan tests => 12;
683
684
    $schema->storage->txn_begin;
685
686
    my $patron = $builder->build_object(
687
        {
688
            class => 'Koha::Patrons',
689
            value => { flags => 0 }
690
        }
691
    );
692
    my $password = 'thePassword123';
693
    $patron->set_password( { password => $password, skip_validation => 1 } );
694
    $patron->discard_changes;
695
    my $userid = $patron->userid;
696
697
    my $biblio = $builder->build_sample_biblio();
698
    $t->post_ok("/api/v1/public/biblios/" . $biblio->biblionumber . "/ratings" => json => { rating => 3 })
699
      ->status_is(403);
700
701
    $t->post_ok("//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/ratings" => json => { rating => 3 })
702
      ->status_is(200)
703
      ->json_is( '/rating', '3' )
704
      ->json_is( '/average', '3' )
705
      ->json_is( '/count', '1' );
706
707
    $t->post_ok("//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/ratings" => json => { rating => undef })
708
      ->status_is(200)
709
      ->json_is( '/rating', undef )
710
      ->json_is( '/average', '0' )
711
      ->json_is( '/count', '0' );
712
713
    $schema->storage->txn_rollback;
714
715
};

Return to bug 29939