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

(-)a/C4/Reserves.pm (+24 lines)
Lines 118-123 BEGIN { Link Here
118
        &CheckReserves
118
        &CheckReserves
119
        &CanBookBeReserved
119
        &CanBookBeReserved
120
	&CanItemBeReserved
120
	&CanItemBeReserved
121
        &CanReserveBeCanceledFromOpac
121
        &CancelReserve
122
        &CancelReserve
122
        &CancelExpiredReserves
123
        &CancelExpiredReserves
123
124
Lines 556-561 sub CanItemBeReserved{ Link Here
556
557
557
    return 1;
558
    return 1;
558
}
559
}
560
561
=head2 CanReserveBeCanceledFromOpac
562
563
    $number = CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber);
564
565
    returns 1 if reserve can be cancelled by user from OPAC.
566
    First check if reserve belongs to user, next checks if reserve is not in
567
    transfer or waiting status
568
569
=cut
570
571
sub CanReserveBeCanceledFromOpac {
572
    my ($reserve_id, $borrowernumber) = @_;
573
574
    my $reserve = GetReserve($reserve_id);
575
576
    return 0 unless $reserve->{borrowernumber} == $borrowernumber;
577
    return 0 if ( $reserve->{found} eq 'W' ) or ( $reserve->{found} eq 'T' );
578
579
    return 1;
580
581
}
582
559
#--------------------------------------------------------------------------------
583
#--------------------------------------------------------------------------------
560
=head2 GetReserveCount
584
=head2 GetReserveCount
561
585
(-)a/opac/opac-modrequest-suspend.pl (-1 / +1 lines)
Lines 39-45 my $suspend_until = $query->param('suspend_until') || undef; Link Here
39
my $reserve_id    = $query->param('reserve_id');
39
my $reserve_id    = $query->param('reserve_id');
40
40
41
if ($reserve_id) {
41
if ($reserve_id) {
42
    ToggleSuspend( $reserve_id, $suspend_until );
42
    ToggleSuspend( $reserve_id, $suspend_until ) if CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber);
43
}
43
}
44
else {
44
else {
45
    SuspendAll(
45
    SuspendAll(
(-)a/opac/opac-modrequest.pl (-3 / +1 lines)
Lines 45-53 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
45
my $reserve_id = $query->param('reserve_id');
45
my $reserve_id = $query->param('reserve_id');
46
46
47
if ($reserve_id && $borrowernumber) {
47
if ($reserve_id && $borrowernumber) {
48
48
    CancelReserve({ reserve_id => $reserve_id }) if CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber);
49
    my $reserve = GetReserve($reserve_id);
50
    CancelReserve({ reserve_id => $reserve_id }) if $borrowernumber == $reserve->{borrowernumber} ;
51
}
49
}
52
50
53
print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
51
print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
(-)a/t/db_dependent/Reserves.t (-2 / +30 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 35;
5
use Test::More tests => 39;
6
6
7
use MARC::Record;
7
use MARC::Record;
8
use DateTime::Duration;
8
use DateTime::Duration;
Lines 395-400 $p = C4::Reserves::CalculatePriority($bibnum, $resdate); Link Here
395
is($p, 3, 'CalculatePriority should now return priority 3');
395
is($p, 3, 'CalculatePriority should now return priority 3');
396
# End of tests for bug 8918
396
# End of tests for bug 8918
397
397
398
# Tests for cancel reserves by users from OPAC.
399
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
400
AddReserve('CPL',  $requesters{'CPL'}, $item_bibnum,
401
           $constraint, $bibitems,  1, undef, $expdate, $notes,
402
           $title,      $checkitem, '');
403
my (undef, $canres, undef) = CheckReserves($itemnumber);
404
405
my $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'});
406
is($cancancel, 1, 'Can user cancel its own reserve');
407
408
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'FPL'});
409
is($cancancel, 0, 'Other user cant cancel reserve');
410
411
ModReserveAffect($itemnumber, $requesters{'CPL'}, 1);
412
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'});
413
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
414
415
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
416
AddReserve('CPL',  $requesters{'CPL'}, $item_bibnum,
417
           $constraint, $bibitems,  1, undef, $expdate, $notes,
418
           $title,      $checkitem, '');
419
(undef, $canres, undef) = CheckReserves($itemnumber);
420
421
ModReserveAffect($itemnumber, $requesters{'CPL'}, 0);
422
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'});
423
is($cancancel, 0, 'Reserve in waiting status cant be canceled');
424
425
# End of tests for bug 12876
426
398
$dbh->rollback;
427
$dbh->rollback;
399
428
400
sub count_hold_print_messages {
429
sub count_hold_print_messages {
401
- 

Return to bug 12876