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

(-)a/Koha/Exceptions.pm (-21 lines)
Lines 55-81 use Exception::Class ( Link Here
55
        isa => 'Koha::Exception',
55
        isa => 'Koha::Exception',
56
        description => 'Koha is under maintenance.'
56
        description => 'Koha is under maintenance.'
57
    },
57
    },
58
    # Virtualshelves exceptions
59
    'Koha::Exceptions::Virtualshelves::DuplicateObject' => {
60
        isa => 'Koha::Exceptions::DuplicateObject',
61
        description => "Duplicate shelf object",
62
    },
63
    'Koha::Exceptions::Virtualshelves::InvalidInviteKey' => {
64
        isa => 'Koha::Exception',
65
        description => 'Invalid key on accepting the share',
66
    },
67
    'Koha::Exceptions::Virtualshelves::InvalidKeyOnSharing' => {
68
        isa => 'Koha::Exception',
69
        description=> 'Invalid key on sharing a shelf',
70
    },
71
    'Koha::Exceptions::Virtualshelves::ShareHasExpired' => {
72
        isa => 'Koha::Exception',
73
        description=> 'Cannot share this shelf, the share has expired',
74
    },
75
    'Koha::Exceptions::Virtualshelves::UseDbAdminAccount' => {
76
        isa => 'Koha::Exception',
77
        description => "Invalid use of database administrator account",
78
    }
79
);
58
);
80
59
81
1;
60
1;
(-)a/Koha/Exceptions/Virtualshelf.pm (+81 lines)
Line 0 Link Here
1
package Koha::Exceptions::Virtualshelf;
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 Koha::Exception;
21
22
use Exception::Class (
23
24
    'Koha::Exceptions::Virtualshelf' => {
25
        isa => 'Koha::Exception',
26
    },
27
    'Koha::Exceptions::Virtualshelf::DuplicateObject' => {
28
        isa => 'Koha::Exceptions::Virtualshelf',
29
        description => "Duplicate shelf object",
30
    },
31
    'Koha::Exceptions::Virtualshelf::InvalidInviteKey' => {
32
        isa => 'Koha::Exceptions::Virtualshelf',
33
        description => 'Invalid key on accepting the share',
34
    },
35
    'Koha::Exceptions::Virtualshelf::InvalidKeyOnSharing' => {
36
        isa => 'Koha::Exceptions::Virtualshelf',
37
        description=> 'Invalid key on sharing a shelf',
38
    },
39
    'Koha::Exceptions::Virtualshelf::ShareHasExpired' => {
40
        isa => 'Koha::Exceptions::Virtualshelf',
41
        description=> 'Cannot share this shelf, the share has expired',
42
    },
43
    'Koha::Exceptions::Virtualshelf::UseDbAdminAccount' => {
44
        isa => 'Koha::Exceptions::Virtualshelf',
45
        description => "Invalid use of database administrator account",
46
    }
47
);
48
49
=head1 NAME
50
51
Koha::Exceptions::Virtualshelf - Base class for virtualshelf exceptions
52
53
=head1 Exceptions
54
55
=head2 Koha::Exceptions::Virtualshelf
56
57
Generic Virtualshelf exception
58
59
=head2 Koha::Exceptions::Virtualshelf::DuplicateObject
60
61
Exception to be used when a similar virtual shelf already exists.
62
63
=head2 Koha::Exceptions::Virtualshelf::InvalidInviteKey
64
65
Exception to be used when an invite key is invalid.
66
67
=head2 Koha::Exceptions::Virtualshelf::InvalidKeyOnSharing
68
69
Exception to be used when the supplied key is invalid on sharing.
70
71
=head2 Koha::Exceptions::Virtualshelf::ShareHasExpired
72
73
Exception to be used when a share has expired.
74
75
=head2 Koha::Exceptions::Virtualshelf::UseDbAdminAccount
76
77
Exception to be used when the owner is not set.
78
79
=cut
80
81
1;
(-)a/Koha/Virtualshelf.pm (-4 / +4 lines)
Lines 23-29 use C4::Auth qw( haspermission ); Link Here
23
use Koha::Patrons;
23
use Koha::Patrons;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Exceptions;
26
use Koha::Exceptions::Virtualshelf;
27
use Koha::Virtualshelfshare;
27
use Koha::Virtualshelfshare;
28
use Koha::Virtualshelfshares;
28
use Koha::Virtualshelfshares;
29
use Koha::Virtualshelfcontent;
29
use Koha::Virtualshelfcontent;
Lines 45-55 sub store { Link Here
45
    my ( $self ) = @_;
45
    my ( $self ) = @_;
46
46
47
    unless ( $self->owner ) {
47
    unless ( $self->owner ) {
48
        Koha::Exceptions::Virtualshelves::UseDbAdminAccount->throw;
48
        Koha::Exceptions::Virtualshelf::UseDbAdminAccount->throw;
49
    }
49
    }
50
50
51
    unless ( $self->is_shelfname_valid ) {
51
    unless ( $self->is_shelfname_valid ) {
52
        Koha::Exceptions::Virtualshelves::DuplicateObject->throw;
52
        Koha::Exceptions::Virtualshelf::DuplicateObject->throw;
53
    }
53
    }
54
54
55
    $self->allow_change_from_owner( 1 )
55
    $self->allow_change_from_owner( 1 )
Lines 124-130 sub get_contents { Link Here
124
sub share {
124
sub share {
125
    my ( $self, $key ) = @_;
125
    my ( $self, $key ) = @_;
126
    unless ( $key ) {
126
    unless ( $key ) {
127
        Koha::Exceptions::Virtualshelves::InvalidKeyOnSharing->throw;
127
        Koha::Exceptions::Virtualshelf::InvalidKeyOnSharing->throw;
128
    }
128
    }
129
    Koha::Virtualshelfshare->new(
129
    Koha::Virtualshelfshare->new(
130
        {
130
        {
(-)a/Koha/Virtualshelfshare.pm (-2 / +2 lines)
Lines 45-54 Koha::Virtualshelfshare - Koha Virtualshelfshare Object class Link Here
45
sub accept {
45
sub accept {
46
    my ( $self, $invitekey, $borrowernumber ) = @_;
46
    my ( $self, $invitekey, $borrowernumber ) = @_;
47
    if ( $self->has_expired ) {
47
    if ( $self->has_expired ) {
48
        Koha::Exceptions::Virtualshelves::ShareHasExpired->throw;
48
        Koha::Exceptions::Virtualshelf::ShareHasExpired->throw;
49
    }
49
    }
50
    if ( $self->invitekey ne $invitekey ) {
50
    if ( $self->invitekey ne $invitekey ) {
51
        Koha::Exceptions::Virtualshelves::InvalidInviteKey->throw;
51
        Koha::Exceptions::Virtualshelf::InvalidInviteKey->throw;
52
    }
52
    }
53
53
54
    # If this borrower already has a share, there is no need to accept twice
54
    # If this borrower already has a share, there is no need to accept twice
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-2 / +2 lines)
Lines 171-179 Link Here
171
            <span>You do not have permission to add a record to this list.</span>
171
            <span>You do not have permission to add a record to this list.</span>
172
        [% CASE 'no_biblio_removed' %]
172
        [% CASE 'no_biblio_removed' %]
173
            <span>No record was removed.</span>
173
            <span>No record was removed.</span>
174
        [% CASE 'Koha::Exceptions::Virtualshelves::DuplicateObject' %]
174
        [% CASE 'Koha::Exceptions::Virtualshelf::DuplicateObject' %]
175
            <span>An error occurred when creating this list. The name [% shelfname | html %] already exists.</span>
175
            <span>An error occurred when creating this list. The name [% shelfname | html %] already exists.</span>
176
        [% CASE 'Koha::Exceptions::Virtualshelves::UseDbAdminAccount' %]
176
        [% CASE 'Koha::Exceptions::Virtualshelf::UseDbAdminAccount' %]
177
            <span>List could not be created. (Do not use the database administrator account.)</span>
177
            <span>List could not be created. (Do not use the database administrator account.)</span>
178
        [% CASE 'DBIx::Class::Exception' %]
178
        [% CASE 'DBIx::Class::Exception' %]
179
            [% m.msg | html %]
179
            [% m.msg | html %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt (-1 / +1 lines)
Lines 184-190 Link Here
184
                            <span>You do not have permission to add a record to this list.</span>
184
                            <span>You do not have permission to add a record to this list.</span>
185
                        [% CASE 'no_biblio_removed' %]
185
                        [% CASE 'no_biblio_removed' %]
186
                            <span>No record was removed.</span>
186
                            <span>No record was removed.</span>
187
                        [% CASE 'Koha::Exceptions::Virtualshelves::DuplicateObject' %]
187
                        [% CASE 'Koha::Exceptions::Virtualshelf::DuplicateObject' %]
188
                            <span>An error occurred when creating the list. The name [% shelfname | html %] already exists.</span>
188
                            <span>An error occurred when creating the list. The name [% shelfname | html %] already exists.</span>
189
                        [% CASE 'DBIx::Class::Exception' %]
189
                        [% CASE 'DBIx::Class::Exception' %]
190
                            [% m.msg | html %]
190
                            [% m.msg | html %]
(-)a/t/db_dependent/Virtualshelves.t (-4 / +3 lines)
Lines 66-72 subtest 'CRUD' => sub { Link Here
66
            }
66
            }
67
        )->store;
67
        )->store;
68
    };
68
    };
69
    is( ref($@), 'Koha::Exceptions::Virtualshelves::DuplicateObject',
69
    is( ref($@), 'Koha::Exceptions::Virtualshelf::DuplicateObject',
70
        'Exception on duplicate name' );
70
        'Exception on duplicate name' );
71
    $number_of_shelves = Koha::Virtualshelves->search->count;
71
    $number_of_shelves = Koha::Virtualshelves->search->count;
72
    is( $number_of_shelves, 1, 'To be sure the number of shelves is still 1' );
72
    is( $number_of_shelves, 1, 'To be sure the number of shelves is still 1' );
Lines 122-128 subtest 'Sharing' => sub { Link Here
122
    )->store;
122
    )->store;
123
123
124
    my $shared_shelf = eval { $shelf_to_share->share };
124
    my $shared_shelf = eval { $shelf_to_share->share };
125
    is ( ref( $@ ), 'Koha::Exceptions::Virtualshelves::InvalidKeyOnSharing', 'Do not share if no key given' );
125
    is ( ref( $@ ), 'Koha::Exceptions::Virtualshelf::InvalidKeyOnSharing', 'Do not share if no key given' );
126
    $shared_shelf = eval { $shelf_to_share->share('valid key') };
126
    $shared_shelf = eval { $shelf_to_share->share('valid key') };
127
    is( ref( $shared_shelf ), 'Koha::Virtualshelfshare', 'On sharing, the method should return a valid Koha::Virtualshelfshare object' );
127
    is( ref( $shared_shelf ), 'Koha::Virtualshelfshare', 'On sharing, the method should return a valid Koha::Virtualshelfshare object' );
128
128
Lines 135-141 subtest 'Sharing' => sub { Link Here
135
        $shared_shelf->accept( 'invalid k', $share_with_me->{borrowernumber} );
135
        $shared_shelf->accept( 'invalid k', $share_with_me->{borrowernumber} );
136
    };
136
    };
137
    is( $is_accepted, undef, 'The share should have not been accepted if the key is invalid' );
137
    is( $is_accepted, undef, 'The share should have not been accepted if the key is invalid' );
138
    is( ref( $@ ), 'Koha::Exceptions::Virtualshelves::InvalidInviteKey', 'accept with an invalid key should raise an exception' );
138
    is( ref( $@ ), 'Koha::Exceptions::Virtualshelf::InvalidInviteKey', 'accept with an invalid key should raise an exception' );
139
139
140
    $is_accepted = $shared_shelf->accept( 'valid key', $share_with_me->{borrowernumber} );
140
    $is_accepted = $shared_shelf->accept( 'valid key', $share_with_me->{borrowernumber} );
141
    ok( defined($is_accepted), 'The share should have been accepted if the key valid' );
141
    ok( defined($is_accepted), 'The share should have been accepted if the key valid' );
142
- 

Return to bug 30057