Bug 15839: [QA Follow-up] Error checking in opac-review.pl

[1] Adds a check on biblionumber. (Prevents a DBIx error.)
[2] If you have a reviewid, search on that and check results.
    Add an unauthorized error in template.
[3] If you add a new review, check that there is no review yet.
    If so, edit the existing one.
    This supports the added FIXME on a unique constraint.

Note: This script could receive further attention.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tested all crud ops with opac-review.pl (incl URL manipulation).

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Marcel de Rooy 2016-07-29 10:24:44 +02:00 committed by Kyle M Hall
parent b5c3b1c974
commit 177542bf52
2 changed files with 24 additions and 8 deletions

View file

@ -18,6 +18,12 @@
[% IF ( ERRORS ) %]
<div class="alert">
[% FOREACH ERROR IN ERRORS %]
[% IF ( ERROR.nobiblio ) %]
<p>Error: we cannot find this bibliographic record.</p>
[% END %]
[% IF ( ERROR.unauthorized ) %]
<p>Sorry, only the creator of this comment is allowed to change it.</p>
[% END %]
[% IF ( ERROR.scrubbed ) %]
<p>Note: your comment contained illegal markup code. It has been saved with the markup removed, as below. You can edit the comment further, or cancel to retain the comment as is.</p>
[% END %]

View file

@ -32,6 +32,7 @@ use Koha::Reviews;
my $query = new CGI;
my $biblionumber = $query->param('biblionumber');
my $review = $query->param('review');
my $reviewid = $query->param('reviewid');
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{
template_name => "opac-review.tt",
@ -43,11 +44,21 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
# FIXME: need to allow user to delete their own comment(s)
my ( $clean, @errors, $savedreview );
my $biblio = GetBiblioData($biblionumber);
# FIXME biblionumber, borrowernumber should be a unique key of reviews
my $savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next;
my ($clean, @errors);
if (defined $review) {
if( !$biblio ) {
push @errors, { nobiblio => 1 };
} elsif( $reviewid ) { # edit existing one, check on creator
$savedreview = Koha::Reviews->search({ reviewid => $reviewid, borrowernumber => $borrowernumber })->next;
push @errors, { unauthorized => 1 } if !$savedreview;
} else { # this check prevents adding multiple comments
# FIXME biblionumber, borrowernumber should be a unique key of reviews
$savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next;
$review = $savedreview? $savedreview->review: $review;
}
if( !@errors && defined $review ) {
if ($review !~ /\S/) {
push @errors, {empty=>1};
} else {
@ -70,12 +81,12 @@ if (defined $review) {
}
)->store;
} else {
Koha::Review->new(
$reviewid = Koha::Review->new(
{ biblionumber => $biblionumber,
borrowernumber => $borrowernumber,
review => $clean,
}
)->store;
)->store->reviewid;
}
unless (@errors){ $template->param(WINDOW_CLOSE=>1); }
}
@ -89,9 +100,8 @@ $template->param(
'biblionumber' => $biblionumber,
'borrowernumber' => $borrowernumber,
'review' => $review,
'reviewid' => scalar $query->param('reviewid') || 0,
'reviewid' => $reviewid || 0,
'title' => $biblio->{'title'},
);
output_html_with_http_headers $query, $cookie, $template->output;