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

(-)a/C4/Reserves.pm (+30 lines)
Lines 118-123 BEGIN { Link Here
118
        &CheckReserves
118
        &CheckReserves
119
        &CanBookBeReserved
119
        &CanBookBeReserved
120
	&CanItemBeReserved
120
	&CanItemBeReserved
121
        &CanUserCancelReserve
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 CanUserCancelReserve
562
563
    $number = CanUserCancelReserve($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 CanUserCancelReserve {
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';
578
579
    if ( $reserve->{itemnumber} ){
580
        my ($transfertwhen, $transfertfrom, $transfertto) = C4::Circulation::GetTransfers( $reserve->{itemnumber} );
581
582
        return 0 if $transfertwhen; #item is in transfer
583
    }
584
585
    return 1;
586
587
}
588
559
#--------------------------------------------------------------------------------
589
#--------------------------------------------------------------------------------
560
=head2 GetReserveCount
590
=head2 GetReserveCount
561
591
(-)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 CanUserCancelReserve($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 CanUserCancelReserve($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 / +32 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
$dbh->do('DELETE FROM branchtransfers', undef, undef);
401
AddReserve('CPL',  $requesters{'CPL'}, $item_bibnum,
402
           $constraint, $bibitems,  1, undef, $expdate, $notes,
403
           $title,      $checkitem, '');
404
my (undef, $canres, undef) = CheckReserves($itemnumber);
405
406
my $cancancel = CanUserCancelReserve($canres->{reserve_id}, $requesters{'CPL'});
407
is($cancancel, 1, 'Can user cancel its own reserve');
408
409
$cancancel = CanUserCancelReserve($canres->{reserve_id}, $requesters{'FPL'});
410
is($cancancel, 0, 'Other user cant cancel reserve');
411
412
ModReserveAffect($itemnumber, $requesters{'CPL'}, 1);
413
ModItemTransfer($itemnumber, 'CPL', 'FPL' );
414
$cancancel = CanUserCancelReserve($canres->{reserve_id}, $requesters{'CPL'});
415
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
416
417
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
418
AddReserve('CPL',  $requesters{'CPL'}, $item_bibnum,
419
           $constraint, $bibitems,  1, undef, $expdate, $notes,
420
           $title,      $checkitem, '');
421
(undef, $canres, undef) = CheckReserves($itemnumber);
422
423
ModReserveAffect($itemnumber, $requesters{'CPL'}, 0);
424
$cancancel = CanUserCancelReserve($canres->{reserve_id}, $requesters{'CPL'});
425
is($cancancel, 0, 'Reserve in waiting status cant be canceled');
426
427
# End of tests for bug 12876
428
398
$dbh->rollback;
429
$dbh->rollback;
399
430
400
sub count_hold_print_messages {
431
sub count_hold_print_messages {
401
- 

Return to bug 12876