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

(-)a/C4/Utils/DataTables/VirtualShelves.pm (-5 / +5 lines)
Lines 27-33 sub search { Link Here
27
    # FIXME refactore the following queries
27
    # FIXME refactore the following queries
28
    # We should call Koha::Virtualshelves
28
    # We should call Koha::Virtualshelves
29
    my $select = q|
29
    my $select = q|
30
        SELECT vs.shelfnumber, vs.shelfname, vs.owner, vs.public AS public,
30
        SELECT vs.shelfnumber, vs.shelfname, vs.owner_id, vs.public AS public,
31
        vs.created_on, vs.lastmodified as modification_time,
31
        vs.created_on, vs.lastmodified as modification_time,
32
        bo.surname, bo.firstname, vs.sortfield as sortby,
32
        bo.surname, bo.firstname, vs.sortfield as sortby,
33
        count(vc.biblionumber) as count
33
        count(vc.biblionumber) as count
Lines 35-41 sub search { Link Here
35
35
36
    my $from_total = q|
36
    my $from_total = q|
37
        FROM virtualshelves vs
37
        FROM virtualshelves vs
38
        LEFT JOIN borrowers bo ON vs.owner=bo.borrowernumber
38
        LEFT JOIN borrowers bo ON vs.owner_id=bo.borrowernumber
39
    |;
39
    |;
40
40
41
    my $from = $from_total . q|
41
    my $from = $from_total . q|
Lines 86-92 sub search { Link Here
86
    push @args,       $public;
86
    push @args,       $public;
87
87
88
    if ( !$public ) {
88
    if ( !$public ) {
89
        push @where_strs, '(vs.owner = ? OR sh.borrowernumber = ?)';
89
        push @where_strs, '(vs.owner_id = ? OR sh.borrowernumber = ?)';
90
        push @args, $loggedinuser, $loggedinuser;
90
        push @args, $loggedinuser, $loggedinuser;
91
    }
91
    }
92
92
Lines 120-126 sub search { Link Here
120
        $limit = sprintf "LIMIT %s,%s", $start, $length;
120
        $limit = sprintf "LIMIT %s,%s", $start, $length;
121
    }
121
    }
122
122
123
    my $group_by = " GROUP BY vs.shelfnumber, vs.shelfname, vs.owner, vs.public,
123
    my $group_by = " GROUP BY vs.shelfnumber, vs.shelfname, vs.owner_id, vs.public,
124
        vs.created_on, vs.lastmodified, bo.surname, bo.firstname, vs.sortfield ";
124
        vs.created_on, vs.lastmodified, bo.surname, bo.firstname, vs.sortfield ";
125
125
126
    my $query = join(
126
    my $query = join(
Lines 140-146 sub search { Link Here
140
140
141
    # Get the recordsTotal DataTable variable
141
    # Get the recordsTotal DataTable variable
142
    $query = q|SELECT COUNT(vs.shelfnumber)| . $from_total . q| WHERE public = ?|;
142
    $query = q|SELECT COUNT(vs.shelfnumber)| . $from_total . q| WHERE public = ?|;
143
    $query .= q| AND (vs.owner = ? OR sh.borrowernumber = ?)| if !$public;
143
    $query .= q| AND (vs.owner_id = ? OR sh.borrowernumber = ?)| if !$public;
144
    @args = !$public ? ( $loggedinuser, $public, $loggedinuser, $loggedinuser ) : ($public);
144
    @args = !$public ? ( $loggedinuser, $public, $loggedinuser, $loggedinuser ) : ($public);
145
    ($recordsTotal) = $dbh->selectrow_array( $query, undef, @args );
145
    ($recordsTotal) = $dbh->selectrow_array( $query, undef, @args );
146
146
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-1 / +1 lines)
Lines 172-178 sub additional_report { Link Here
172
    return {
172
    return {
173
        lists => Koha::Virtualshelves->search(
173
        lists => Koha::Virtualshelves->search(
174
            [
174
            [
175
                { public => 0, owner => $loggedinuser },
175
                { public => 0, owner_id => $loggedinuser },
176
                { public => 1 }
176
                { public => 1 }
177
            ]
177
            ]
178
        ),
178
        ),
(-)a/Koha/Exceptions/Virtualshelf.pm (-1 / +1 lines)
Lines 74-80 Exception to be used when a share has expired. Link Here
74
74
75
=head2 Koha::Exceptions::Virtualshelf::UseDbAdminAccount
75
=head2 Koha::Exceptions::Virtualshelf::UseDbAdminAccount
76
76
77
Exception to be used when the owner is not set.
77
Exception to be used when the owner_id is not set.
78
78
79
=cut
79
=cut
80
80
(-)a/Koha/Patron.pm (-1 / +1 lines)
Lines 103-109 our $RESULTSET_PATRON_ID_MAPPING = { Link Here
103
    TagAll               => 'borrowernumber',
103
    TagAll               => 'borrowernumber',
104
    Virtualshelfcontent  => 'borrowernumber',
104
    Virtualshelfcontent  => 'borrowernumber',
105
    Virtualshelfshare    => 'borrowernumber',
105
    Virtualshelfshare    => 'borrowernumber',
106
    Virtualshelve        => 'owner',
106
    Virtualshelve        => 'owner_id',
107
};
107
};
108
108
109
=head1 NAME
109
=head1 NAME
(-)a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm (-1 / +1 lines)
Lines 227-233 sub import_from_list { Link Here
227
    my $list   = Koha::Virtualshelves->find($list_id);
227
    my $list   = Koha::Virtualshelves->find($list_id);
228
    my $patron = $c->stash('koha.user');
228
    my $patron = $c->stash('koha.user');
229
229
230
    unless ( $list && $list->owner == $c->stash('koha.user')->borrowernumber ) {
230
    unless ( $list && $list->owner_id == $c->stash('koha.user')->borrowernumber ) {
231
        return $c->render_resource_not_found("List");
231
        return $c->render_resource_not_found("List");
232
    }
232
    }
233
233
(-)a/Koha/REST/V1/Lists.pm (-1 / +1 lines)
Lines 56-62 sub list_public { Link Here
56
        my $lists_set = Koha::Virtualshelves->new;
56
        my $lists_set = Koha::Virtualshelves->new;
57
57
58
        if ($only_mine) {
58
        if ($only_mine) {
59
            $lists_set = $lists_set->search( { owner => $user->id } );
59
            $lists_set = $lists_set->search( { owner_id => $user->id } );
60
        }
60
        }
61
61
62
        if ( $only_public || !$user ) {
62
        if ( $only_public || !$user ) {
(-)a/Koha/Virtualshelf.pm (-16 / +32 lines)
Lines 50-56 Missing POD for store. Link Here
50
sub store {
50
sub store {
51
    my ($self) = @_;
51
    my ($self) = @_;
52
52
53
    unless ( $self->owner ) {
53
    unless ( $self->owner_id ) {
54
        Koha::Exceptions::Virtualshelf::UseDbAdminAccount->throw;
54
        Koha::Exceptions::Virtualshelf::UseDbAdminAccount->throw;
55
    }
55
    }
56
56
Lines 109-123 sub is_shelfname_valid { Link Here
109
        ( $self->shelfnumber ? ( "me.shelfnumber" => { '!=', $self->shelfnumber } ) : () ),
109
        ( $self->shelfnumber ? ( "me.shelfnumber" => { '!=', $self->shelfnumber } ) : () ),
110
    };
110
    };
111
111
112
    if ( $self->is_private and defined $self->owner ) {
112
    if ( $self->is_private and defined $self->owner_id ) {
113
        $conditions->{-or} = {
113
        $conditions->{-or} = {
114
            "virtualshelfshares.borrowernumber" => $self->owner,
114
            "virtualshelfshares.borrowernumber" => $self->owner_id,
115
            "me.owner"                          => $self->owner,
115
            "me.owner_id"                       => $self->owner_id,
116
        };
116
        };
117
        $conditions->{public} = 0;
117
        $conditions->{public} = 0;
118
    } elsif ( $self->is_private and not defined $self->owner ) {
118
    } elsif ( $self->is_private and not defined $self->owner_id ) {
119
        $conditions->{owner}  = undef;
119
        $conditions->{owner_id} = undef;
120
        $conditions->{public} = 0;
120
        $conditions->{public}   = 0;
121
    } else {
121
    } else {
122
        $conditions->{public} = 1;
122
        $conditions->{public} = 1;
123
    }
123
    }
Lines 247-253 sub add_biblio { Link Here
247
    # Check permissions
247
    # Check permissions
248
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
248
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
249
    return 0
249
    return 0
250
        unless ( $self->owner == $borrowernumber && $self->allow_change_from_owner )
250
        unless ( $self->owner_id == $borrowernumber && $self->allow_change_from_owner )
251
        || ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
251
        || ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
252
        || ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
252
        || ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
253
        || $self->allow_change_from_others;
253
        || $self->allow_change_from_others;
Lines 279-285 sub remove_biblios { Link Here
279
279
280
    my $number_removed = 0;
280
    my $number_removed = 0;
281
    my $patron         = Koha::Patrons->find($borrowernumber) or return 0;
281
    my $patron         = Koha::Patrons->find($borrowernumber) or return 0;
282
    if (   ( $self->owner == $borrowernumber && $self->allow_change_from_owner )
282
    if (   ( $self->owner_id == $borrowernumber && $self->allow_change_from_owner )
283
        || ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
283
        || ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
284
        || ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
284
        || ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
285
        || $self->allow_change_from_others )
285
        || $self->allow_change_from_others )
Lines 303-309 sub can_be_viewed { Link Here
303
    my ( $self, $borrowernumber ) = @_;
303
    my ( $self, $borrowernumber ) = @_;
304
    return 1 if $self->is_public;
304
    return 1 if $self->is_public;
305
    return 0 unless $borrowernumber;
305
    return 0 unless $borrowernumber;
306
    return 1 if $self->owner == $borrowernumber;
306
    return 1 if $self->owner_id == $borrowernumber;
307
    return $self->get_shares->search(
307
    return $self->get_shares->search(
308
        {
308
        {
309
            borrowernumber => $borrowernumber,
309
            borrowernumber => $borrowernumber,
Lines 321-327 sub can_be_deleted { Link Here
321
    my ( $self, $borrowernumber ) = @_;
321
    my ( $self, $borrowernumber ) = @_;
322
322
323
    return 0 unless $borrowernumber;
323
    return 0 unless $borrowernumber;
324
    return 1 if $self->owner == $borrowernumber;
324
    return 1 if $self->owner_id == $borrowernumber;
325
325
326
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
326
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
327
327
Lines 339-345 Missing POD for can_be_managed. Link Here
339
sub can_be_managed {
339
sub can_be_managed {
340
    my ( $self, $borrowernumber ) = @_;
340
    my ( $self, $borrowernumber ) = @_;
341
    return 1
341
    return 1
342
        if $borrowernumber and $self->owner == $borrowernumber;
342
        if $borrowernumber and $self->owner_id == $borrowernumber;
343
343
344
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
344
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
345
    return 1
345
    return 1
Lines 359-365 sub can_biblios_be_added { Link Here
359
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
359
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
360
    return 1
360
    return 1
361
        if $borrowernumber
361
        if $borrowernumber
362
        and ( ( $self->owner == $borrowernumber && $self->allow_change_from_owner )
362
        and ( ( $self->owner_id == $borrowernumber && $self->allow_change_from_owner )
363
        or ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
363
        or ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
364
        or ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
364
        or ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
365
        or $self->allow_change_from_others )
365
        or $self->allow_change_from_others )
Lines 461-466 sub cannot_be_transferred { Link Here
461
    return 0;    # serving as green light
461
    return 0;    # serving as green light
462
}
462
}
463
463
464
=head3 owner
465
466
my $patron = Koha::Virtualshelf->owner;
467
468
Return the Koha::Patron object representing the owner_id
469
470
=cut
471
472
sub owner {
473
    my ($self) = @_;
474
    my $patron_rs = $self->_result->owner_id;
475
    return unless $patron_rs;
476
477
    return Koha::Patrons->find($patron_rs);
478
}
479
464
=head3 transfer_ownership
480
=head3 transfer_ownership
465
481
466
    $list->transfer_ownership( $patron_id );
482
    $list->transfer_ownership( $patron_id );
Lines 476-489 sub transfer_ownership { Link Here
476
        unless $patron_id;
492
        unless $patron_id;
477
493
478
    ## before we change the owner, collect some details
494
    ## before we change the owner, collect some details
479
    my $old_owner  = Koha::Patrons->find( $self->owner );
495
    my $old_owner  = Koha::Patrons->find( $self->owner_id );
480
    my $new_owner  = Koha::Patrons->find($patron_id);
496
    my $new_owner  = Koha::Patrons->find($patron_id);
481
    my $userenv    = C4::Context->userenv;
497
    my $userenv    = C4::Context->userenv;
482
    my $branchcode = $userenv->{branch};
498
    my $branchcode = $userenv->{branch};
483
499
484
    ## first we change the owner
500
    ## first we change the owner
485
    $self->remove_share($patron_id) if $self->is_private;
501
    $self->remove_share($patron_id) if $self->is_private;
486
    $self->set( { owner => $patron_id } )->store;
502
    $self->set( { owner_id => $patron_id } )->store;
487
503
488
    ## now we message the new owner
504
    ## now we message the new owner
489
    my $letter = C4::Letters::GetPreparedLetter(
505
    my $letter = C4::Letters::GetPreparedLetter(
Lines 524-530 sub to_api_mapping { Link Here
524
    return {
540
    return {
525
        created_on   => 'creation_date',
541
        created_on   => 'creation_date',
526
        lastmodified => 'updated_on_date',
542
        lastmodified => 'updated_on_date',
527
        owner        => 'owner_id',
543
        owner_id     => 'owner_id',
528
        shelfname    => 'name',
544
        shelfname    => 'name',
529
        shelfnumber  => 'list_id',
545
        shelfnumber  => 'list_id',
530
        sortfield    => 'default_sort_field',
546
        sortfield    => 'default_sort_field',
(-)a/Koha/Virtualshelves.pm (-8 / +8 lines)
Lines 95-101 sub get_private_shelves { Link Here
95
            public => 0,
95
            public => 0,
96
            -or    => {
96
            -or    => {
97
                'virtualshelfshares.borrowernumber' => $borrowernumber,
97
                'virtualshelfshares.borrowernumber' => $borrowernumber,
98
                'me.owner'                          => $borrowernumber,
98
                'me.owner_id'                       => $borrowernumber,
99
            }
99
            }
100
        },
100
        },
101
        {
101
        {
Lines 180-186 sub get_some_shelves { Link Here
180
            push @conditions, {
180
            push @conditions, {
181
                -or => [
181
                -or => [
182
                    {
182
                    {
183
                        "me.owner"                   => $borrowernumber,
183
                        "me.owner_id"                => $borrowernumber,
184
                        "me.allow_change_from_owner" => 1,
184
                        "me.allow_change_from_owner" => 1,
185
                    },
185
                    },
186
                    "me.allow_change_from_others"          => 1,
186
                    "me.allow_change_from_others"          => 1,
Lines 192-198 sub get_some_shelves { Link Here
192
            push @conditions, {
192
            push @conditions, {
193
                -or => [
193
                -or => [
194
                    {
194
                    {
195
                        "me.owner"                   => $borrowernumber,
195
                        "me.owner_id"                => $borrowernumber,
196
                        "me.allow_change_from_owner" => 1,
196
                        "me.allow_change_from_owner" => 1,
197
                    },
197
                    },
198
                    "me.allow_change_from_others" => 1,
198
                    "me.allow_change_from_others" => 1,
Lines 203-209 sub get_some_shelves { Link Here
203
            push @conditions, {
203
            push @conditions, {
204
                -or => [
204
                -or => [
205
                    {
205
                    {
206
                        "me.owner"                   => $borrowernumber,
206
                        "me.owner_id"                => $borrowernumber,
207
                        "me.allow_change_from_owner" => 1,
207
                        "me.allow_change_from_owner" => 1,
208
                    },
208
                    },
209
                    "me.allow_change_from_others" => 1,
209
                    "me.allow_change_from_others" => 1,
Lines 215-221 sub get_some_shelves { Link Here
215
        push @conditions, {
215
        push @conditions, {
216
            -or => {
216
            -or => {
217
                "virtualshelfshares.borrowernumber" => $borrowernumber,
217
                "virtualshelfshares.borrowernumber" => $borrowernumber,
218
                "me.owner"                          => $borrowernumber,
218
                "me.owner_id"                       => $borrowernumber,
219
            }
219
            }
220
        };
220
        };
221
    }
221
    }
Lines 250-257 sub get_shelves_containing_record { Link Here
250
                {
250
                {
251
                    public => 0,
251
                    public => 0,
252
                    -or    => {
252
                    -or    => {
253
                        'me.owner' => $borrowernumber,
253
                        'me.owner_id' => $borrowernumber,
254
                        -or        => {
254
                        -or           => {
255
                            'virtualshelfshares.borrowernumber' => $borrowernumber,
255
                            'virtualshelfshares.borrowernumber' => $borrowernumber,
256
                        },
256
                        },
257
                    }
257
                    }
Lines 301-307 sub filter_by_readable { Link Here
301
    Koha::Exceptions::MissingParameter->throw("Mandatory patron_id parameter missing")
301
    Koha::Exceptions::MissingParameter->throw("Mandatory patron_id parameter missing")
302
        unless $params->{patron_id};
302
        unless $params->{patron_id};
303
303
304
    return $self->search( { '-or' => { public => 1, owner => $params->{patron_id} } } );
304
    return $self->search( { '-or' => { public => 1, owner_id => $params->{patron_id} } } );
305
}
305
}
306
306
307
=head2 Internal methods
307
=head2 Internal methods
(-)a/catalogue/detail.pl (-2 / +2 lines)
Lines 452-459 if ( C4::Context->preference("virtualshelves") ) { Link Here
452
        {
452
        {
453
            biblionumber => $biblionumber,
453
            biblionumber => $biblionumber,
454
            '-or'        => {
454
            '-or'        => {
455
                public => 1,
455
                public   => 1,
456
                owner  => $patron->borrowernumber
456
                owner_id => $patron->borrowernumber
457
            }
457
            }
458
        },
458
        },
459
        {
459
        {
(-)a/installer/data/mysql/kohastructure.sql (-3 / +3 lines)
Lines 7047-7053 DROP TABLE IF EXISTS `virtualshelves`; Link Here
7047
CREATE TABLE `virtualshelves` (
7047
CREATE TABLE `virtualshelves` (
7048
  `shelfnumber` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
7048
  `shelfnumber` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
7049
  `shelfname` varchar(255) DEFAULT NULL COMMENT 'name of the list',
7049
  `shelfname` varchar(255) DEFAULT NULL COMMENT 'name of the list',
7050
  `owner` int(11) DEFAULT NULL COMMENT 'foreign key linking to the borrowers table (using borrowernumber) for the creator of this list (changed from varchar(80) to int)',
7050
  `owner_id` int(11) DEFAULT NULL COMMENT 'foreign key linking to the borrowers table (using borrowernumber) for the creator of this list (changed from varchar(80) to int)',
7051
  `public` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'If the list is public',
7051
  `public` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'If the list is public',
7052
  `sortfield` varchar(16) DEFAULT 'title' COMMENT 'the field this list is sorted on',
7052
  `sortfield` varchar(16) DEFAULT 'title' COMMENT 'the field this list is sorted on',
7053
  `lastmodified` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'date and time the list was last modified',
7053
  `lastmodified` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'date and time the list was last modified',
Lines 7057-7064 CREATE TABLE `virtualshelves` ( Link Here
7057
  `allow_change_from_staff` tinyint(1) DEFAULT 0 COMMENT 'can staff change contents?',
7057
  `allow_change_from_staff` tinyint(1) DEFAULT 0 COMMENT 'can staff change contents?',
7058
  `allow_change_from_permitted_staff` tinyint(1) DEFAULT 0 COMMENT 'can staff with edit_public_list_contents permission change contents?',
7058
  `allow_change_from_permitted_staff` tinyint(1) DEFAULT 0 COMMENT 'can staff with edit_public_list_contents permission change contents?',
7059
  PRIMARY KEY (`shelfnumber`),
7059
  PRIMARY KEY (`shelfnumber`),
7060
  KEY `virtualshelves_ibfk_1` (`owner`),
7060
  KEY `virtualshelves_ibfk_1` (`owner_id`),
7061
  CONSTRAINT `virtualshelves_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL
7061
  CONSTRAINT `virtualshelves_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL
7062
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
7062
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
7063
/*!40101 SET character_set_client = @saved_cs_client */;
7063
/*!40101 SET character_set_client = @saved_cs_client */;
7064
7064
(-)a/opac/opac-addbybiblionumber.pl (-6 / +6 lines)
Lines 66-72 if ( $op && $op !~ /^cud-/ ) { Link Here
66
        )
66
        )
67
    {
67
    {
68
        my $shelf = eval {
68
        my $shelf = eval {
69
            Koha::Virtualshelf->new( { shelfname => $newvirtualshelf, public => $public, owner => $loggedinuser, } )
69
            Koha::Virtualshelf->new( { shelfname => $newvirtualshelf, public => $public, owner_id => $loggedinuser, } )
70
                ->store;
70
                ->store;
71
        };
71
        };
72
        if ( $@ or not $shelf ) {
72
        if ( $@ or not $shelf ) {
Lines 112-118 if ( $op && $op !~ /^cud-/ ) { Link Here
112
        my $private_shelves = Koha::Virtualshelves->search(
112
        my $private_shelves = Koha::Virtualshelves->search(
113
            {
113
            {
114
                public                  => 0,
114
                public                  => 0,
115
                owner                   => $loggedinuser,
115
                owner_id                => $loggedinuser,
116
                allow_change_from_owner => 1,
116
                allow_change_from_owner => 1,
117
            },
117
            },
118
            { order_by => 'shelfname' }
118
            { order_by => 'shelfname' }
Lines 134-140 if ( $op && $op !~ /^cud-/ ) { Link Here
134
                        -or    => [
134
                        -or    => [
135
                            -and => {
135
                            -and => {
136
                                allow_change_from_owner => 1,
136
                                allow_change_from_owner => 1,
137
                                owner                   => $loggedinuser,
137
                                owner_id                => $loggedinuser,
138
                            },
138
                            },
139
                            allow_change_from_others          => 1,
139
                            allow_change_from_others          => 1,
140
                            allow_change_from_staff           => 1,
140
                            allow_change_from_staff           => 1,
Lines 150-156 if ( $op && $op !~ /^cud-/ ) { Link Here
150
                        -or    => [
150
                        -or    => [
151
                            -and => {
151
                            -and => {
152
                                allow_change_from_owner => 1,
152
                                allow_change_from_owner => 1,
153
                                owner                   => $loggedinuser,
153
                                owner_id                => $loggedinuser,
154
                            },
154
                            },
155
                            allow_change_from_others => 1,
155
                            allow_change_from_others => 1,
156
                            allow_change_from_staff  => 1
156
                            allow_change_from_staff  => 1
Lines 165-171 if ( $op && $op !~ /^cud-/ ) { Link Here
165
                        -or    => [
165
                        -or    => [
166
                            -and => {
166
                            -and => {
167
                                allow_change_from_owner => 1,
167
                                allow_change_from_owner => 1,
168
                                owner                   => $loggedinuser,
168
                                owner_id                => $loggedinuser,
169
                            },
169
                            },
170
                            allow_change_from_others => 1,
170
                            allow_change_from_others => 1,
171
                        ],
171
                        ],
Lines 180-186 if ( $op && $op !~ /^cud-/ ) { Link Here
180
                    -or    => [
180
                    -or    => [
181
                        -and => {
181
                        -and => {
182
                            allow_change_from_owner => 1,
182
                            allow_change_from_owner => 1,
183
                            owner                   => $loggedinuser,
183
                            owner_id                => $loggedinuser,
184
                        },
184
                        },
185
                        allow_change_from_others => 1,
185
                        allow_change_from_others => 1,
186
                    ],
186
                    ],
(-)a/opac/opac-detail.pl (-2 / +2 lines)
Lines 953-960 if ( C4::Context->preference("virtualshelves") ) { Link Here
953
        {
953
        {
954
            biblionumber => $biblionumber,
954
            biblionumber => $biblionumber,
955
            '-or'        => {
955
            '-or'        => {
956
                public => 1,
956
                public   => 1,
957
                owner  => $borrowernumber
957
                owner_id => $borrowernumber
958
            }
958
            }
959
        },
959
        },
960
        {
960
        {
(-)a/opac/opac-shareshelf.pl (-2 / +2 lines)
Lines 88-94 sub _init { Link Here
88
    my $shelfnumber = $param->{shelfnumber};
88
    my $shelfnumber = $param->{shelfnumber};
89
    $shelf              = Koha::Virtualshelves->find($shelfnumber) unless $param->{errcode};
89
    $shelf              = Koha::Virtualshelves->find($shelfnumber) unless $param->{errcode};
90
    $param->{shelfname} = $shelf ? $shelf->shelfname : q||;
90
    $param->{shelfname} = $shelf ? $shelf->shelfname : q||;
91
    $param->{owner}     = $shelf ? $shelf->owner     : -1;
91
    $param->{owner}     = $shelf ? $shelf->owner_id  : -1;
92
    $param->{public}    = $shelf ? $shelf->public    : 0;
92
    $param->{public}    = $shelf ? $shelf->public    : 0;
93
93
94
    return $param;
94
    return $param;
Lines 154-160 sub handle_accept { Link Here
154
        $param->{errcode} = 2;
154
        $param->{errcode} = 2;
155
    } elsif ( $shelf->public ) {
155
    } elsif ( $shelf->public ) {
156
        $param->{errcode} = 5;
156
        $param->{errcode} = 5;
157
    } elsif ( $shelf->owner == $loggedinuser ) {
157
    } elsif ( $shelf->owner_id == $loggedinuser ) {
158
        $param->{errcode} = 8;
158
        $param->{errcode} = 8;
159
    }
159
    }
160
    return if $param->{errcode};
160
    return if $param->{errcode};
(-)a/opac/opac-shelves.pl (-3 / +3 lines)
Lines 108-114 if ( $op eq 'add_form' ) { Link Here
108
108
109
    if ($shelf) {
109
    if ($shelf) {
110
        $public = $shelf->public;
110
        $public = $shelf->public;
111
        my $patron = Koha::Patrons->find( $shelf->owner );
111
        my $patron = Koha::Patrons->find( $shelf->owner_id );
112
        $template->param( owner => $patron, );
112
        $template->param( owner => $patron, );
113
        unless ( $shelf->can_be_managed($loggedinuser) ) {
113
        unless ( $shelf->can_be_managed($loggedinuser) ) {
114
            push @messages, { type => 'error', code => 'unauthorized_on_update' };
114
            push @messages, { type => 'error', code => 'unauthorized_on_update' };
Lines 130-136 if ( $op eq 'add_form' ) { Link Here
130
                    allow_change_from_others          => $allow_changes_from == ANYONE,
130
                    allow_change_from_others          => $allow_changes_from == ANYONE,
131
                    allow_change_from_staff           => $allow_changes_from == STAFF,
131
                    allow_change_from_staff           => $allow_changes_from == STAFF,
132
                    allow_change_from_permitted_staff => $allow_changes_from == PERMITTED,
132
                    allow_change_from_permitted_staff => $allow_changes_from == PERMITTED,
133
                    owner                             => scalar $loggedinuser,
133
                    owner_id                          => scalar $loggedinuser,
134
                }
134
                }
135
            );
135
            );
136
            $shelf->store;
136
            $shelf->store;
Lines 303-309 if ( $op eq 'add_form' ) { Link Here
303
                Koha::Virtualshelfshare->new(
303
                Koha::Virtualshelfshare->new(
304
                    { shelfnumber => $shelfnumber, borrowernumber => $loggedinuser, sharedate => dt_from_string } )
304
                    { shelfnumber => $shelfnumber, borrowernumber => $loggedinuser, sharedate => dt_from_string } )
305
                    ->store;
305
                    ->store;
306
                $shelf->owner($new_owner)->store;
306
                $shelf->owner_id($new_owner)->store;
307
            }
307
            }
308
        );
308
        );
309
        $op = 'list';
309
        $op = 'list';
(-)a/t/db_dependent/Koha/Patrons.t (-14 / +14 lines)
Lines 590-610 subtest "delete" => sub { Link Here
590
    my $private_list = Koha::Virtualshelf->new(
590
    my $private_list = Koha::Virtualshelf->new(
591
        {
591
        {
592
            shelfname => "private",
592
            shelfname => "private",
593
            owner     => $patron->borrowernumber,
593
            owner_id  => $patron->borrowernumber,
594
            public    => 0,
594
            public    => 0,
595
        }
595
        }
596
    )->store;
596
    )->store;
597
    my $public_list = Koha::Virtualshelf->new(
597
    my $public_list = Koha::Virtualshelf->new(
598
        {
598
        {
599
            shelfname => "public",
599
            shelfname => "public",
600
            owner     => $patron->borrowernumber,
600
            owner_id  => $patron->borrowernumber,
601
            public    => 1,
601
            public    => 1,
602
        }
602
        }
603
    )->store;
603
    )->store;
604
    my $list_to_share = Koha::Virtualshelf->new(
604
    my $list_to_share = Koha::Virtualshelf->new(
605
        {
605
        {
606
            shelfname => "shared",
606
            shelfname => "shared",
607
            owner     => $patron->borrowernumber,
607
            owner_id  => $patron->borrowernumber,
608
            public    => 0,
608
            public    => 0,
609
        }
609
        }
610
    )->store;
610
    )->store;
Lines 631-637 subtest "delete" => sub { Link Here
631
        q|Koha::Patron->delete should have cancelled patron's holds 2|
631
        q|Koha::Patron->delete should have cancelled patron's holds 2|
632
    );
632
    );
633
633
634
    my $transferred_lists = Koha::Virtualshelves->search( { owner => $staff_patron->borrowernumber } )->count;
634
    my $transferred_lists = Koha::Virtualshelves->search( { owner_id => $staff_patron->borrowernumber } )->count;
635
    is(
635
    is(
636
        $transferred_lists, 2,
636
        $transferred_lists, 2,
637
        'Public and shared lists should stay in database under a different owner with a unique name, while private lists delete, with ListOwnershipPatronDeletion set to Transfer'
637
        'Public and shared lists should stay in database under a different owner with a unique name, while private lists delete, with ListOwnershipPatronDeletion set to Transfer'
Lines 645-651 subtest "delete" => sub { Link Here
645
        "But the other share is still there"
645
        "But the other share is still there"
646
    );
646
    );
647
    is(
647
    is(
648
        Koha::Virtualshelves->search( { owner => $patron->borrowernumber } )->count, 0,
648
        Koha::Virtualshelves->search( { owner_id => $patron->borrowernumber } )->count, 0,
649
        q|Koha::Patron->delete should have deleted patron's lists/removed their ownership|
649
        q|Koha::Patron->delete should have deleted patron's lists/removed their ownership|
650
    );
650
    );
651
651
Lines 664-677 subtest "delete" => sub { Link Here
664
    my $designated_owner = $builder->build_object( { class => 'Koha::Patrons' } );
664
    my $designated_owner = $builder->build_object( { class => 'Koha::Patrons' } );
665
    t::lib::Mocks::mock_preference( 'ListOwnerDesignated', $designated_owner->id );
665
    t::lib::Mocks::mock_preference( 'ListOwnerDesignated', $designated_owner->id );
666
    $patron        = $builder->build_object( { class => 'Koha::Patrons' } );
666
    $patron        = $builder->build_object( { class => 'Koha::Patrons' } );
667
    $private_list  = Koha::Virtualshelf->new( { shelfname => "PR1", owner  => $patron->id } )->store;
667
    $private_list  = Koha::Virtualshelf->new( { shelfname => "PR1", owner_id => $patron->id } )->store;
668
    $public_list   = Koha::Virtualshelf->new( { shelfname => "PU1", public => 1, owner => $patron->id } )->store;
668
    $public_list   = Koha::Virtualshelf->new( { shelfname => "PU1", public   => 1, owner_id => $patron->id } )->store;
669
    $list_to_share = Koha::Virtualshelf->new( { shelfname => "SH1", owner  => $patron->id } )->store;
669
    $list_to_share = Koha::Virtualshelf->new( { shelfname => "SH1", owner_id => $patron->id } )->store;
670
    $list_to_share->share("valid key")->accept( "valid key", $patron_for_sharing->id );
670
    $list_to_share->share("valid key")->accept( "valid key", $patron_for_sharing->id );
671
    $patron->delete;
671
    $patron->delete;
672
    is( Koha::Virtualshelves->find( $private_list->id ),      undef,                 'Private list gone' );
672
    is( Koha::Virtualshelves->find( $private_list->id ),         undef,                 'Private list gone' );
673
    is( $public_list->discard_changes->get_column('owner'),   $designated_owner->id, 'Public list transferred' );
673
    is( $public_list->discard_changes->get_column('owner_id'),   $designated_owner->id, 'Public list transferred' );
674
    is( $list_to_share->discard_changes->get_column('owner'), $designated_owner->id, 'Shared list transferred' );
674
    is( $list_to_share->discard_changes->get_column('owner_id'), $designated_owner->id, 'Shared list transferred' );
675
675
676
    # Finally test deleting lists
676
    # Finally test deleting lists
677
    t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' );
677
    t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' );
Lines 680-700 subtest "delete" => sub { Link Here
680
    my $private_list2 = Koha::Virtualshelf->new(
680
    my $private_list2 = Koha::Virtualshelf->new(
681
        {
681
        {
682
            shelfname => "private",
682
            shelfname => "private",
683
            owner     => $patron2->borrowernumber,
683
            owner_id  => $patron2->borrowernumber,
684
            public    => 0,
684
            public    => 0,
685
        }
685
        }
686
    )->store;
686
    )->store;
687
    my $public_list2 = Koha::Virtualshelf->new(
687
    my $public_list2 = Koha::Virtualshelf->new(
688
        {
688
        {
689
            shelfname => "public",
689
            shelfname => "public",
690
            owner     => $patron2->borrowernumber,
690
            owner_id  => $patron2->borrowernumber,
691
            public    => 1,
691
            public    => 1,
692
        }
692
        }
693
    )->store;
693
    )->store;
694
    my $list_to_share2 = Koha::Virtualshelf->new(
694
    my $list_to_share2 = Koha::Virtualshelf->new(
695
        {
695
        {
696
            shelfname => "shared",
696
            shelfname => "shared",
697
            owner     => $patron2->borrowernumber,
697
            owner_id  => $patron2->borrowernumber,
698
            public    => 0,
698
            public    => 0,
699
        }
699
        }
700
    )->store;
700
    )->store;
(-)a/t/db_dependent/Koha/Virtualshelf.t (-4 / +4 lines)
Lines 42-55 subtest 'transfer_ownership() tests' => sub { Link Here
42
    my $public_list = $builder->build_object(
42
    my $public_list = $builder->build_object(
43
        {
43
        {
44
            class => "Koha::Virtualshelves",
44
            class => "Koha::Virtualshelves",
45
            value => { owner => $patron_1->id, public => 1 }
45
            value => { owner_id => $patron_1->id, public => 1 }
46
        }
46
        }
47
    );
47
    );
48
48
49
    my $private_list = $builder->build_object(
49
    my $private_list = $builder->build_object(
50
        {
50
        {
51
            class => "Koha::Virtualshelves",
51
            class => "Koha::Virtualshelves",
52
            value => { owner => $patron_1->id, public => 0 }
52
            value => { owner_id => $patron_1->id, public => 0 }
53
        }
53
        }
54
    );
54
    );
55
55
Lines 82-88 subtest 'transfer_ownership() tests' => sub { Link Here
82
    $public_list->transfer_ownership( $patron_2->id );
82
    $public_list->transfer_ownership( $patron_2->id );
83
    $public_list->discard_changes;
83
    $public_list->discard_changes;
84
84
85
    is( $public_list->owner, $patron_2->id, 'Owner changed correctly' );
85
    is( $public_list->owner_id, $patron_2->id, 'Owner changed correctly' );
86
    my $public_list_shares = $public_list->get_shares;
86
    my $public_list_shares = $public_list->get_shares;
87
    is( $public_list_shares->count,                1,             'Count is correct' );
87
    is( $public_list_shares->count,                1,             'Count is correct' );
88
    is( $public_list_shares->next->borrowernumber, $patron_2->id, "Public lists don't get the share removed" );
88
    is( $public_list_shares->next->borrowernumber, $patron_2->id, "Public lists don't get the share removed" );
Lines 90-96 subtest 'transfer_ownership() tests' => sub { Link Here
90
    $private_list->transfer_ownership( $patron_2->id );
90
    $private_list->transfer_ownership( $patron_2->id );
91
    $private_list->discard_changes;
91
    $private_list->discard_changes;
92
92
93
    is( $private_list->owner, $patron_2->id );
93
    is( $private_list->owner_id, $patron_2->id );
94
    my $private_list_shares = $private_list->get_shares;
94
    my $private_list_shares = $private_list->get_shares;
95
    is( $private_list_shares->count, 1, 'Count is correct' );
95
    is( $private_list_shares->count, 1, 'Count is correct' );
96
    is(
96
    is(
(-)a/t/db_dependent/Koha/Virtualshelves.t (-20 / +20 lines)
Lines 46-66 subtest 'disown_or_delete() tests' => sub { Link Here
46
        my $public_list = $builder->build_object(
46
        my $public_list = $builder->build_object(
47
            {
47
            {
48
                class => "Koha::Virtualshelves",
48
                class => "Koha::Virtualshelves",
49
                value => { owner => $patron_1->id, public => 1 }
49
                value => { owner_id => $patron_1->id, public => 1 }
50
            }
50
            }
51
        );
51
        );
52
52
53
        my $private_list = $builder->build_object(
53
        my $private_list = $builder->build_object(
54
            {
54
            {
55
                class => "Koha::Virtualshelves",
55
                class => "Koha::Virtualshelves",
56
                value => { owner => $patron_1->id, public => 0 }
56
                value => { owner_id => $patron_1->id, public => 0 }
57
            }
57
            }
58
        );
58
        );
59
59
60
        my $private_list_shared = $builder->build_object(
60
        my $private_list_shared = $builder->build_object(
61
            {
61
            {
62
                class => "Koha::Virtualshelves",
62
                class => "Koha::Virtualshelves",
63
                value => { owner => $patron_1->id, public => 0 }
63
                value => { owner_id => $patron_1->id, public => 0 }
64
            }
64
            }
65
        );
65
        );
66
66
Lines 85-96 subtest 'disown_or_delete() tests' => sub { Link Here
85
85
86
        is( $rs->count, 2, 'The private/non-shared list was deleted' );
86
        is( $rs->count, 2, 'The private/non-shared list was deleted' );
87
        my $first = $rs->next;
87
        my $first = $rs->next;
88
        is( $first->id,    $public_list->id );
88
        is( $first->id,       $public_list->id );
89
        is( $first->owner, $patron_2->id );
89
        is( $first->owner_id, $patron_2->id );
90
90
91
        my $second = $rs->next;
91
        my $second = $rs->next;
92
        is( $second->id,    $private_list_shared->id );
92
        is( $second->id,       $private_list_shared->id );
93
        is( $second->owner, $patron_2->id );
93
        is( $second->owner_id, $patron_2->id );
94
94
95
        $schema->storage->txn_rollback;
95
        $schema->storage->txn_rollback;
96
    };
96
    };
Lines 108-128 subtest 'disown_or_delete() tests' => sub { Link Here
108
        my $public_list = $builder->build_object(
108
        my $public_list = $builder->build_object(
109
            {
109
            {
110
                class => "Koha::Virtualshelves",
110
                class => "Koha::Virtualshelves",
111
                value => { owner => $patron_1->id, public => 1 }
111
                value => { owner_id => $patron_1->id, public => 1 }
112
            }
112
            }
113
        );
113
        );
114
114
115
        my $private_list = $builder->build_object(
115
        my $private_list = $builder->build_object(
116
            {
116
            {
117
                class => "Koha::Virtualshelves",
117
                class => "Koha::Virtualshelves",
118
                value => { owner => $patron_1->id, public => 0 }
118
                value => { owner_id => $patron_1->id, public => 0 }
119
            }
119
            }
120
        );
120
        );
121
121
122
        my $private_list_shared = $builder->build_object(
122
        my $private_list_shared = $builder->build_object(
123
            {
123
            {
124
                class => "Koha::Virtualshelves",
124
                class => "Koha::Virtualshelves",
125
                value => { owner => $patron_1->id, public => 0 }
125
                value => { owner_id => $patron_1->id, public => 0 }
126
            }
126
            }
127
        );
127
        );
128
128
Lines 141-147 subtest 'disown_or_delete() tests' => sub { Link Here
141
        my $public_list_to_delete = $builder->build_object(
141
        my $public_list_to_delete = $builder->build_object(
142
            {
142
            {
143
                class => "Koha::Virtualshelves",
143
                class => "Koha::Virtualshelves",
144
                value => { owner => $patron_1->id, public => 1 }
144
                value => { owner_id => $patron_1->id, public => 1 }
145
            }
145
            }
146
        );
146
        );
147
147
Lines 162-173 subtest 'disown_or_delete() tests' => sub { Link Here
162
162
163
        is( $rs->count, 2, 'The private/non-shared list was deleted' );
163
        is( $rs->count, 2, 'The private/non-shared list was deleted' );
164
        my $first = $rs->next;
164
        my $first = $rs->next;
165
        is( $first->id,    $public_list->id );
165
        is( $first->id,       $public_list->id );
166
        is( $first->owner, $patron_3->id );
166
        is( $first->owner_id, $patron_3->id );
167
167
168
        my $second = $rs->next;
168
        my $second = $rs->next;
169
        is( $second->id,    $private_list_shared->id );
169
        is( $second->id,       $private_list_shared->id );
170
        is( $second->owner, $patron_3->id );
170
        is( $second->owner_id, $patron_3->id );
171
171
172
        $schema->storage->txn_rollback;
172
        $schema->storage->txn_rollback;
173
    };
173
    };
Lines 181-193 subtest 'disown_or_delete() tests' => sub { Link Here
181
        my $public_list = $builder->build_object(
181
        my $public_list = $builder->build_object(
182
            {
182
            {
183
                class => "Koha::Virtualshelves",
183
                class => "Koha::Virtualshelves",
184
                value => { owner => $patron_1->id, public => 1 }
184
                value => { owner_id => $patron_1->id, public => 1 }
185
            }
185
            }
186
        );
186
        );
187
        my $private_list_shared = $builder->build_object(
187
        my $private_list_shared = $builder->build_object(
188
            {
188
            {
189
                class => "Koha::Virtualshelves",
189
                class => "Koha::Virtualshelves",
190
                value => { owner => $patron_1->id, public => 0 }
190
                value => { owner_id => $patron_1->id, public => 0 }
191
            }
191
            }
192
        );
192
        );
193
        $builder->build_object(
193
        $builder->build_object(
Lines 225-245 subtest 'disown_or_delete() tests' => sub { Link Here
225
        my $public_list = $builder->build_object(
225
        my $public_list = $builder->build_object(
226
            {
226
            {
227
                class => "Koha::Virtualshelves",
227
                class => "Koha::Virtualshelves",
228
                value => { owner => $patron_1->id, public => 1 }
228
                value => { owner_id => $patron_1->id, public => 1 }
229
            }
229
            }
230
        );
230
        );
231
231
232
        my $private_list = $builder->build_object(
232
        my $private_list = $builder->build_object(
233
            {
233
            {
234
                class => "Koha::Virtualshelves",
234
                class => "Koha::Virtualshelves",
235
                value => { owner => $patron_1->id, public => 0 }
235
                value => { owner_id => $patron_1->id, public => 0 }
236
            }
236
            }
237
        );
237
        );
238
238
239
        my $private_list_shared = $builder->build_object(
239
        my $private_list_shared = $builder->build_object(
240
            {
240
            {
241
                class => "Koha::Virtualshelves",
241
                class => "Koha::Virtualshelves",
242
                value => { owner => $patron_1->id, public => 0 }
242
                value => { owner_id => $patron_1->id, public => 0 }
243
            }
243
            }
244
        );
244
        );
245
245
(-)a/t/db_dependent/Utils/Datatables_Virtualshelves.t (-7 / +6 lines)
Lines 90-96 my $shelf1 = Koha::Virtualshelf->new( Link Here
90
        shelfname => 'my first private list (empty)',
90
        shelfname => 'my first private list (empty)',
91
        public    => 0,
91
        public    => 0,
92
        sortfield => 'author',
92
        sortfield => 'author',
93
        owner     => $john_doe{borrowernumber},
93
        owner_id  => $john_doe{borrowernumber},
94
    }
94
    }
95
)->store;
95
)->store;
96
96
Lines 99-105 my $shelf2 = Koha::Virtualshelf->new( Link Here
99
        shelfname => 'my second private list',
99
        shelfname => 'my second private list',
100
        public    => 0,
100
        public    => 0,
101
        sortfield => 'title',
101
        sortfield => 'title',
102
        owner     => $john_doe{borrowernumber},
102
        owner_id  => $john_doe{borrowernumber},
103
    }
103
    }
104
)->store;
104
)->store;
105
my $biblionumber1 = _add_biblio('title 1');
105
my $biblionumber1 = _add_biblio('title 1');
Lines 118-124 my $shelf3 = Koha::Virtualshelf->new( Link Here
118
        shelfname => 'The first public list',
118
        shelfname => 'The first public list',
119
        public    => 1,
119
        public    => 1,
120
        sortfield => 'author',
120
        sortfield => 'author',
121
        owner     => $jane_doe{borrowernumber},
121
        owner_id  => $jane_doe{borrowernumber},
122
    }
122
    }
123
)->store;
123
)->store;
124
my $biblionumber6 = _add_biblio('title 6');
124
my $biblionumber6 = _add_biblio('title 6');
Lines 133-139 my $shelf4 = Koha::Virtualshelf->new( Link Here
133
        shelfname => 'my second public list',
133
        shelfname => 'my second public list',
134
        public    => 1,
134
        public    => 1,
135
        sortfield => 'title',
135
        sortfield => 'title',
136
        owner     => $jane_doe{borrowernumber},
136
        owner_id  => $jane_doe{borrowernumber},
137
    }
137
    }
138
)->store;
138
)->store;
139
my $biblionumber9  = _add_biblio('title 9');
139
my $biblionumber9  = _add_biblio('title 9');
Lines 150-156 my $shelf5 = Koha::Virtualshelf->new( Link Here
150
        shelfname => 'my third private list',
150
        shelfname => 'my third private list',
151
        public    => 0,
151
        public    => 0,
152
        sortfield => 'title',
152
        sortfield => 'title',
153
        owner     => $jane_doe{borrowernumber},
153
        owner_id  => $jane_doe{borrowernumber},
154
    }
154
    }
155
)->store;
155
)->store;
156
my $biblionumber13 = _add_biblio('title 13');
156
my $biblionumber13 = _add_biblio('title 13');
Lines 171-177 for my $i ( 6 .. 15 ) { Link Here
171
        {
171
        {
172
            shelfname => "another public list $i",
172
            shelfname => "another public list $i",
173
            public    => 1,
173
            public    => 1,
174
            owner     => $john_smith{borrowernumber},
174
            owner_id  => $john_smith{borrowernumber},
175
        }
175
        }
176
    )->store;
176
    )->store;
177
}
177
}
Lines 287-290 sub _add_biblio { Link Here
287
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
287
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
288
    return $biblionumber;
288
    return $biblionumber;
289
}
289
}
290
(-)a/t/db_dependent/Virtualshelves.t (-30 / +37 lines)
Lines 40-46 my $dbh = C4::Context->dbh; Link Here
40
teardown();
40
teardown();
41
41
42
subtest 'CRUD' => sub {
42
subtest 'CRUD' => sub {
43
    plan tests => 15;
43
    plan tests => 16;
44
    my $patron = $builder->build(
44
    my $patron = $builder->build(
45
        {
45
        {
46
            source => 'Borrower',
46
            source => 'Borrower',
Lines 54-60 subtest 'CRUD' => sub { Link Here
54
    my $shelf = Koha::Virtualshelf->new(
54
    my $shelf = Koha::Virtualshelf->new(
55
        {
55
        {
56
            shelfname => "my first shelf",
56
            shelfname => "my first shelf",
57
            owner     => $patron->{borrowernumber},
57
            owner_id  => $patron->{borrowernumber},
58
            public    => 0,
58
            public    => 0,
59
        }
59
        }
60
    )->store;
60
    )->store;
Lines 75-80 subtest 'CRUD' => sub { Link Here
75
        'The creation time should have been set to today'
75
        'The creation time should have been set to today'
76
    );
76
    );
77
77
78
    # Test owner accessor is working as expected
79
    my $owner = $shelf->owner;
80
    is(
81
        $owner->borrowernumber, $shelf->owner_id,
82
        'The owner accessor\'s borrowenumber should match the shelf\'s owner_id'
83
    );
84
78
    # Test if creation date will not be overwritten by store
85
    # Test if creation date will not be overwritten by store
79
    my $created = dt_from_string->subtract( hours => 1 );
86
    my $created = dt_from_string->subtract( hours => 1 );
80
    $shelf->created_on($created);
87
    $shelf->created_on($created);
Lines 93-99 subtest 'CRUD' => sub { Link Here
93
        $shelf = Koha::Virtualshelf->new(
100
        $shelf = Koha::Virtualshelf->new(
94
            {
101
            {
95
                shelfname => "my first shelf",
102
                shelfname => "my first shelf",
96
                owner     => $patron->{borrowernumber},
103
                owner_id  => $patron->{borrowernumber},
97
                public    => 0,
104
                public    => 0,
98
            }
105
            }
99
        )->store;
106
        )->store;
Lines 114-120 subtest 'CRUD' => sub { Link Here
114
    $shelf = Koha::Virtualshelf->new(
121
    $shelf = Koha::Virtualshelf->new(
115
        {
122
        {
116
            shelfname => "my first shelf",
123
            shelfname => "my first shelf",
117
            owner     => $another_patron->{borrowernumber},
124
            owner_id  => $another_patron->{borrowernumber},
118
            public    => 0,
125
            public    => 0,
119
        }
126
        }
120
    )->store;
127
    )->store;
Lines 218-224 subtest 'Sharing' => sub { Link Here
218
    my $shelf_to_share = Koha::Virtualshelf->new(
225
    my $shelf_to_share = Koha::Virtualshelf->new(
219
        {
226
        {
220
            shelfname => "my first shelf",
227
            shelfname => "my first shelf",
221
            owner     => $patron_wants_to_share->{borrowernumber},
228
            owner_id  => $patron_wants_to_share->{borrowernumber},
222
            public    => 0,
229
            public    => 0,
223
        }
230
        }
224
    )->store;
231
    )->store;
Lines 226-232 subtest 'Sharing' => sub { Link Here
226
    my $shelf_not_to_share = Koha::Virtualshelf->new(
233
    my $shelf_not_to_share = Koha::Virtualshelf->new(
227
        {
234
        {
228
            shelfname => "my second shelf",
235
            shelfname => "my second shelf",
229
            owner     => $patron_wants_to_share->{borrowernumber},
236
            owner_id  => $patron_wants_to_share->{borrowernumber},
230
            public    => 0,
237
            public    => 0,
231
        }
238
        }
232
    )->store;
239
    )->store;
Lines 331-337 subtest 'Shelf content' => sub { Link Here
331
    my $shelf        = Koha::Virtualshelf->new(
338
    my $shelf        = Koha::Virtualshelf->new(
332
        {
339
        {
333
            shelfname    => "my first shelf",
340
            shelfname    => "my first shelf",
334
            owner        => $patron1->{borrowernumber},
341
            owner_id     => $patron1->{borrowernumber},
335
            public       => 0,
342
            public       => 0,
336
            lastmodified => $dt_yesterday,
343
            lastmodified => $dt_yesterday,
337
        }
344
        }
Lines 473-479 subtest 'Shelf permissions' => sub { Link Here
473
    my $public_shelf = Koha::Virtualshelf->new(
480
    my $public_shelf = Koha::Virtualshelf->new(
474
        {
481
        {
475
            shelfname                         => "my first shelf",
482
            shelfname                         => "my first shelf",
476
            owner                             => $patron1->{borrowernumber},
483
            owner_id                          => $patron1->{borrowernumber},
477
            public                            => 1,
484
            public                            => 1,
478
            allow_change_from_owner           => 0,
485
            allow_change_from_owner           => 0,
479
            allow_change_from_others          => 0,
486
            allow_change_from_others          => 0,
Lines 905-911 subtest 'Shelf permissions' => sub { Link Here
905
    my $private_shelf = Koha::Virtualshelf->new(
912
    my $private_shelf = Koha::Virtualshelf->new(
906
        {
913
        {
907
            shelfname                         => "my first shelf",
914
            shelfname                         => "my first shelf",
908
            owner                             => $patron1->{borrowernumber},
915
            owner_id                          => $patron1->{borrowernumber},
909
            public                            => 0,
916
            public                            => 0,
910
            allow_change_from_owner           => 0,
917
            allow_change_from_owner           => 0,
911
            allow_change_from_others          => 0,
918
            allow_change_from_others          => 0,
Lines 1248-1289 subtest 'Get shelves' => sub { Link Here
1248
    my $private_shelf1_1 = Koha::Virtualshelf->new(
1255
    my $private_shelf1_1 = Koha::Virtualshelf->new(
1249
        {
1256
        {
1250
            shelfname => "private shelf 1 for patron 1",
1257
            shelfname => "private shelf 1 for patron 1",
1251
            owner     => $patron1->{borrowernumber},
1258
            owner_id  => $patron1->{borrowernumber},
1252
            public    => 0,
1259
            public    => 0,
1253
        }
1260
        }
1254
    )->store;
1261
    )->store;
1255
    my $private_shelf1_2 = Koha::Virtualshelf->new(
1262
    my $private_shelf1_2 = Koha::Virtualshelf->new(
1256
        {
1263
        {
1257
            shelfname => "private shelf 2 for patron 1",
1264
            shelfname => "private shelf 2 for patron 1",
1258
            owner     => $patron1->{borrowernumber},
1265
            owner_id  => $patron1->{borrowernumber},
1259
            public    => 0,
1266
            public    => 0,
1260
        }
1267
        }
1261
    )->store;
1268
    )->store;
1262
    my $private_shelf2_1 = Koha::Virtualshelf->new(
1269
    my $private_shelf2_1 = Koha::Virtualshelf->new(
1263
        {
1270
        {
1264
            shelfname => "private shelf 1 for patron 2",
1271
            shelfname => "private shelf 1 for patron 2",
1265
            owner     => $patron2->{borrowernumber},
1272
            owner_id  => $patron2->{borrowernumber},
1266
            public    => 0,
1273
            public    => 0,
1267
        }
1274
        }
1268
    )->store;
1275
    )->store;
1269
    my $public_shelf1_1 = Koha::Virtualshelf->new(
1276
    my $public_shelf1_1 = Koha::Virtualshelf->new(
1270
        {
1277
        {
1271
            shelfname => "public shelf 1 for patron 1",
1278
            shelfname => "public shelf 1 for patron 1",
1272
            owner     => $patron1->{borrowernumber},
1279
            owner_id  => $patron1->{borrowernumber},
1273
            public    => 1,
1280
            public    => 1,
1274
        }
1281
        }
1275
    )->store;
1282
    )->store;
1276
    my $public_shelf1_2 = Koha::Virtualshelf->new(
1283
    my $public_shelf1_2 = Koha::Virtualshelf->new(
1277
        {
1284
        {
1278
            shelfname => "public shelf 2 for patron 1",
1285
            shelfname => "public shelf 2 for patron 1",
1279
            owner     => $patron1->{borrowernumber},
1286
            owner_id  => $patron1->{borrowernumber},
1280
            public    => 1,
1287
            public    => 1,
1281
        }
1288
        }
1282
    )->store;
1289
    )->store;
1283
    my $shelf_to_share = Koha::Virtualshelf->new(
1290
    my $shelf_to_share = Koha::Virtualshelf->new(
1284
        {
1291
        {
1285
            shelfname => "shared shelf",
1292
            shelfname => "shared shelf",
1286
            owner     => $patron1->{borrowernumber},
1293
            owner_id  => $patron1->{borrowernumber},
1287
            public    => 0,
1294
            public    => 0,
1288
        }
1295
        }
1289
    )->store;
1296
    )->store;
Lines 1360-1380 subtest 'Get shelves containing biblios' => sub { Link Here
1360
    my $shelf1 = Koha::Virtualshelf->new(
1367
    my $shelf1 = Koha::Virtualshelf->new(
1361
        {
1368
        {
1362
            shelfname => "my first shelf",
1369
            shelfname => "my first shelf",
1363
            owner     => $patron1->{borrowernumber},
1370
            owner_id  => $patron1->{borrowernumber},
1364
            public    => 0,
1371
            public    => 0,
1365
        }
1372
        }
1366
    )->store;
1373
    )->store;
1367
    my $shelf2 = Koha::Virtualshelf->new(
1374
    my $shelf2 = Koha::Virtualshelf->new(
1368
        {
1375
        {
1369
            shelfname => "my x second shelf",          # 'x' to make it sorted after 'third'
1376
            shelfname => "my x second shelf",          # 'x' to make it sorted after 'third'
1370
            owner     => $patron2->{borrowernumber},
1377
            owner_id  => $patron2->{borrowernumber},
1371
            public    => 0,
1378
            public    => 0,
1372
        }
1379
        }
1373
    )->store;
1380
    )->store;
1374
    my $shelf3 = Koha::Virtualshelf->new(
1381
    my $shelf3 = Koha::Virtualshelf->new(
1375
        {
1382
        {
1376
            shelfname => "my third shelf",
1383
            shelfname => "my third shelf",
1377
            owner     => $patron1->{borrowernumber},
1384
            owner_id  => $patron1->{borrowernumber},
1378
            public    => 1,
1385
            public    => 1,
1379
        }
1386
        }
1380
    )->store;
1387
    )->store;
Lines 1467-1475 subtest 'cannot_be_transferred' => sub { Link Here
1467
    $removed_patron->delete;
1474
    $removed_patron->delete;
1468
1475
1469
    # Create three lists
1476
    # Create three lists
1470
    my $private_list = Koha::Virtualshelf->new( { shelfname => "A", owner  => $listowner->id } )->store;
1477
    my $private_list = Koha::Virtualshelf->new( { shelfname => "A", owner_id => $listowner->id } )->store;
1471
    my $public_list  = Koha::Virtualshelf->new( { shelfname => "B", public => 1, owner => $listowner->id } )->store;
1478
    my $public_list  = Koha::Virtualshelf->new( { shelfname => "B", public => 1, owner_id => $listowner->id } )->store;
1472
    my $shared_list  = Koha::Virtualshelf->new( { shelfname => "C", owner  => $listowner->id } )->store;
1479
    my $shared_list  = Koha::Virtualshelf->new( { shelfname => "C", owner_id => $listowner->id } )->store;
1473
    $shared_list->share("key")->accept( "key", $receiver->id );
1480
    $shared_list->share("key")->accept( "key", $receiver->id );
1474
1481
1475
    # Test on private list
1482
    # Test on private list
Lines 1606-1613 subtest 'filter_by_readable() tests' => sub { Link Here
1606
        {
1613
        {
1607
            class => 'Koha::Virtualshelves',
1614
            class => 'Koha::Virtualshelves',
1608
            value => {
1615
            value => {
1609
                public => 0,
1616
                public   => 0,
1610
                owner  => $patron_1->id,
1617
                owner_id => $patron_1->id,
1611
            }
1618
            }
1612
        }
1619
        }
1613
    );
1620
    );
Lines 1615-1622 subtest 'filter_by_readable() tests' => sub { Link Here
1615
        {
1622
        {
1616
            class => 'Koha::Virtualshelves',
1623
            class => 'Koha::Virtualshelves',
1617
            value => {
1624
            value => {
1618
                public => 1,
1625
                public   => 1,
1619
                owner  => $patron_1->id,
1626
                owner_id => $patron_1->id,
1620
            }
1627
            }
1621
        }
1628
        }
1622
    );
1629
    );
Lines 1624-1631 subtest 'filter_by_readable() tests' => sub { Link Here
1624
        {
1631
        {
1625
            class => 'Koha::Virtualshelves',
1632
            class => 'Koha::Virtualshelves',
1626
            value => {
1633
            value => {
1627
                public => 0,
1634
                public   => 0,
1628
                owner  => $patron_2->id,
1635
                owner_id => $patron_2->id,
1629
            }
1636
            }
1630
        }
1637
        }
1631
    );
1638
    );
Lines 1633-1640 subtest 'filter_by_readable() tests' => sub { Link Here
1633
        {
1640
        {
1634
            class => 'Koha::Virtualshelves',
1641
            class => 'Koha::Virtualshelves',
1635
            value => {
1642
            value => {
1636
                public => 1,
1643
                public   => 1,
1637
                owner  => $patron_2->id,
1644
                owner_id => $patron_2->id,
1638
            }
1645
            }
1639
        }
1646
        }
1640
    );
1647
    );
Lines 1653-1659 subtest 'filter_by_readable() tests' => sub { Link Here
1653
    is( $lists->count, 3, 'Three lists are returned' );
1660
    is( $lists->count, 3, 'Three lists are returned' );
1654
1661
1655
    while ( my $list = $lists->next ) {
1662
    while ( my $list = $lists->next ) {
1656
        ok( $list->owner == $patron_1->id || $list->public, 'Only public or self lists in the resultset' );
1663
        ok( $list->owner_id == $patron_1->id || $list->public, 'Only public or self lists in the resultset' );
1657
    }
1664
    }
1658
1665
1659
    $schema->storage->txn_rollback;
1666
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/api/v1/public/lists.t (-4 / +8 lines)
Lines 53-65 subtest 'list_public() tests' => sub { Link Here
53
    my $patron_2_userid = $patron_2->userid;
53
    my $patron_2_userid = $patron_2->userid;
54
54
55
    my $list_1 =
55
    my $list_1 =
56
        $builder->build_object( { class => 'Koha::Virtualshelves', value => { owner => $patron_1->id, public => 1 } } );
56
        $builder->build_object(
57
        { class => 'Koha::Virtualshelves', value => { owner_id => $patron_1->id, public => 1 } } );
57
    my $list_2 =
58
    my $list_2 =
58
        $builder->build_object( { class => 'Koha::Virtualshelves', value => { owner => $patron_1->id, public => 0 } } );
59
        $builder->build_object(
60
        { class => 'Koha::Virtualshelves', value => { owner_id => $patron_1->id, public => 0 } } );
59
    my $list_3 =
61
    my $list_3 =
60
        $builder->build_object( { class => 'Koha::Virtualshelves', value => { owner => $patron_2->id, public => 1 } } );
62
        $builder->build_object(
63
        { class => 'Koha::Virtualshelves', value => { owner_id => $patron_2->id, public => 1 } } );
61
    my $list_4 =
64
    my $list_4 =
62
        $builder->build_object( { class => 'Koha::Virtualshelves', value => { owner => $patron_2->id, public => 0 } } );
65
        $builder->build_object(
66
        { class => 'Koha::Virtualshelves', value => { owner_id => $patron_2->id, public => 0 } } );
63
67
64
    my $q = encode_json(
68
    my $q = encode_json(
65
        {
69
        {
(-)a/t/db_dependent/selenium/regressions.t (-1 / +1 lines)
Lines 267-273 subtest 'XSS vulnerabilities in pagination' => sub { Link Here
267
                    public                   => 1,
267
                    public                   => 1,
268
                    allow_change_from_owner  => 1,
268
                    allow_change_from_owner  => 1,
269
                    allow_change_from_others => 0,
269
                    allow_change_from_others => 0,
270
                    owner                    => $patron->borrowernumber
270
                    owner_id                 => $patron->borrowernumber
271
                }
271
                }
272
            }
272
            }
273
        );
273
        );
(-)a/tools/batch_delete_records.pl (-1 / +1 lines)
Lines 61-67 if ( $op eq 'form' ) { Link Here
61
        op    => 'form',
61
        op    => 'form',
62
        lists => Koha::Virtualshelves->search(
62
        lists => Koha::Virtualshelves->search(
63
            [
63
            [
64
                { public => 0, owner => $loggedinuser },
64
                { public => 0, owner_id => $loggedinuser },
65
                { public => 1 }
65
                { public => 1 }
66
            ]
66
            ]
67
        )
67
        )
(-)a/tools/batch_record_modification.pl (-1 / +1 lines)
Lines 87-93 if ( $op eq 'form' ) { Link Here
87
        view  => 'form',
87
        view  => 'form',
88
        lists => Koha::Virtualshelves->search(
88
        lists => Koha::Virtualshelves->search(
89
            [
89
            [
90
                { public => 0, owner => $loggedinuser },
90
                { public => 0, owner_id => $loggedinuser },
91
                { public => 1 }
91
                { public => 1 }
92
            ]
92
            ]
93
        )
93
        )
(-)a/virtualshelves/addbybiblionumber.pl (-3 / +3 lines)
Lines 100-106 if ( $op && $op !~ /^cud-/ ) { Link Here
100
                shelfname => $newvirtualshelf,
100
                shelfname => $newvirtualshelf,
101
                public    => $public,
101
                public    => $public,
102
                sortfield => $sortfield,
102
                sortfield => $sortfield,
103
                owner     => $loggedinuser,
103
                owner_id  => $loggedinuser,
104
            }
104
            }
105
        )->store;
105
        )->store;
106
    };
106
    };
Lines 155-161 if ( $op && $op !~ /^cud-/ ) { Link Here
155
    my $private_shelves = Koha::Virtualshelves->search(
155
    my $private_shelves = Koha::Virtualshelves->search(
156
        {
156
        {
157
            public                  => 0,
157
            public                  => 0,
158
            owner                   => $loggedinuser,
158
            owner_id                => $loggedinuser,
159
            allow_change_from_owner => 1,
159
            allow_change_from_owner => 1,
160
        },
160
        },
161
        { order_by => 'shelfname' }
161
        { order_by => 'shelfname' }
Lines 174-180 if ( $op && $op !~ /^cud-/ ) { Link Here
174
            -or    => [
174
            -or    => [
175
                -and => {
175
                -and => {
176
                    allow_change_from_owner => 1,
176
                    allow_change_from_owner => 1,
177
                    owner                   => $loggedinuser,
177
                    owner_id                => $loggedinuser,
178
                },
178
                },
179
                allow_change_from_others => 1,
179
                allow_change_from_others => 1,
180
                allow_change_from_staff  => 1,
180
                allow_change_from_staff  => 1,
(-)a/virtualshelves/shelves.pl (-3 / +2 lines)
Lines 78-84 if ( $op eq 'add_form' ) { Link Here
78
78
79
    if ($shelf) {
79
    if ($shelf) {
80
        $public = $shelf->public;
80
        $public = $shelf->public;
81
        my $patron = Koha::Patrons->find( $shelf->owner )->unblessed;
81
        my $patron = Koha::Patrons->find( $shelf->owner_id )->unblessed;
82
        $template->param( owner => $patron, );
82
        $template->param( owner => $patron, );
83
        unless ( $shelf->can_be_managed($loggedinuser) ) {
83
        unless ( $shelf->can_be_managed($loggedinuser) ) {
84
            push @messages, { type => 'alert', code => 'unauthorized_on_update' };
84
            push @messages, { type => 'alert', code => 'unauthorized_on_update' };
Lines 100-106 if ( $op eq 'add_form' ) { Link Here
100
                allow_change_from_others          => $allow_changes_from == ANYONE,
100
                allow_change_from_others          => $allow_changes_from == ANYONE,
101
                allow_change_from_staff           => $allow_changes_from == STAFF,
101
                allow_change_from_staff           => $allow_changes_from == STAFF,
102
                allow_change_from_permitted_staff => $allow_changes_from == PERMITTED,
102
                allow_change_from_permitted_staff => $allow_changes_from == PERMITTED,
103
                owner                             => scalar $query->param('owner'),
103
                owner_id                          => scalar $query->param('owner'),
104
            }
104
            }
105
        );
105
        );
106
        $shelf->store;
106
        $shelf->store;
107
- 

Return to bug 37346