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 74-80 sub search { Link Here
74
    push @args, $public;
74
    push @args, $public;
75
75
76
    if ( !$public ) {
76
    if ( !$public ) {
77
        push @where_strs, '(vs.owner = ? OR sh.borrowernumber = ?)';
77
        push @where_strs, '(vs.owner_id = ? OR sh.borrowernumber = ?)';
78
        push @args, $loggedinuser, $loggedinuser;
78
        push @args, $loggedinuser, $loggedinuser;
79
    }
79
    }
80
80
Lines 107-113 sub search { Link Here
107
        $limit = sprintf "LIMIT %s,%s", $start, $length;
107
        $limit = sprintf "LIMIT %s,%s", $start, $length;
108
    }
108
    }
109
109
110
    my $group_by = " GROUP BY vs.shelfnumber, vs.shelfname, vs.owner, vs.public,
110
    my $group_by = " GROUP BY vs.shelfnumber, vs.shelfname, vs.owner_id, vs.public,
111
        vs.created_on, vs.lastmodified, bo.surname, bo.firstname, vs.sortfield ";
111
        vs.created_on, vs.lastmodified, bo.surname, bo.firstname, vs.sortfield ";
112
112
113
    my $query = join(
113
    my $query = join(
Lines 127-133 sub search { Link Here
127
127
128
    # Get the recordsTotal DataTable variable
128
    # Get the recordsTotal DataTable variable
129
    $query = q|SELECT COUNT(vs.shelfnumber)| . $from_total . q| WHERE public = ?|;
129
    $query = q|SELECT COUNT(vs.shelfnumber)| . $from_total . q| WHERE public = ?|;
130
    $query .= q| AND (vs.owner = ? OR sh.borrowernumber = ?)| if !$public;
130
    $query .= q| AND (vs.owner_id = ? OR sh.borrowernumber = ?)| if !$public;
131
    @args = !$public ? ( $loggedinuser, $public, $loggedinuser, $loggedinuser ) : ( $public );
131
    @args = !$public ? ( $loggedinuser, $public, $loggedinuser, $loggedinuser ) : ( $public );
132
    ( $recordsTotal ) = $dbh->selectrow_array( $query, undef, @args );
132
    ( $recordsTotal ) = $dbh->selectrow_array( $query, undef, @args );
133
133
(-)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 97-103 our $RESULTSET_PATRON_ID_MAPPING = { Link Here
97
    TagAll               => 'borrowernumber',
97
    TagAll               => 'borrowernumber',
98
    Virtualshelfcontent  => 'borrowernumber',
98
    Virtualshelfcontent  => 'borrowernumber',
99
    Virtualshelfshare    => 'borrowernumber',
99
    Virtualshelfshare    => 'borrowernumber',
100
    Virtualshelve        => 'owner',
100
    Virtualshelve        => 'owner_id',
101
};
101
};
102
102
103
=head1 NAME
103
=head1 NAME
(-)a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm (-2 / +2 lines)
Lines 242-248 sub import_from_list { Link Here
242
    my $list   = Koha::Virtualshelves->find($list_id);
242
    my $list   = Koha::Virtualshelves->find($list_id);
243
    my $patron = $c->stash('koha.user');
243
    my $patron = $c->stash('koha.user');
244
244
245
    unless ( $list && $list->owner == $c->stash('koha.user')->borrowernumber ) {
245
    unless ( $list && $list->owner_id == $c->stash('koha.user')->borrowernumber ) {
246
        return $c->render_resource_not_found("List");
246
        return $c->render_resource_not_found("List");
247
    }
247
    }
248
248
Lines 341-344 sub import_from_kbart_file { Link Here
341
    };
341
    };
342
}
342
}
343
343
344
1;
344
1;
(-)a/Koha/Schema/Result/Borrower.pm (-1 / +1 lines)
Lines 2142-2148 Related object: L<Koha::Schema::Result::Virtualshelve> Link Here
2142
__PACKAGE__->has_many(
2142
__PACKAGE__->has_many(
2143
  "virtualshelves",
2143
  "virtualshelves",
2144
  "Koha::Schema::Result::Virtualshelve",
2144
  "Koha::Schema::Result::Virtualshelve",
2145
  { "foreign.owner" => "self.borrowernumber" },
2145
  { "foreign.owner_id" => "self.borrowernumber" },
2146
  { cascade_copy => 0, cascade_delete => 0 },
2146
  { cascade_copy => 0, cascade_delete => 0 },
2147
);
2147
);
2148
2148
(-)a/Koha/Schema/Result/Virtualshelve.pm (-5 / +5 lines)
Lines 39-45 unique identifier assigned by Koha Link Here
39
39
40
name of the list
40
name of the list
41
41
42
=head2 owner
42
=head2 owner_id
43
43
44
  data_type: 'integer'
44
  data_type: 'integer'
45
  is_foreign_key: 1
45
  is_foreign_key: 1
Lines 120-126 __PACKAGE__->add_columns( Link Here
120
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
120
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
121
  "shelfname",
121
  "shelfname",
122
  { data_type => "varchar", is_nullable => 1, size => 255 },
122
  { data_type => "varchar", is_nullable => 1, size => 255 },
123
  "owner",
123
  "owner_id",
124
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
124
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
125
  "public",
125
  "public",
126
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
126
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
Lines 179-185 Related object: L<Koha::Schema::Result::Borrower> Link Here
179
__PACKAGE__->belongs_to(
179
__PACKAGE__->belongs_to(
180
  "owner",
180
  "owner",
181
  "Koha::Schema::Result::Borrower",
181
  "Koha::Schema::Result::Borrower",
182
  { borrowernumber => "owner" },
182
  { borrowernumber => "owner_id" },
183
  {
183
  {
184
    is_deferrable => 1,
184
    is_deferrable => 1,
185
    join_type     => "LEFT",
185
    join_type     => "LEFT",
Lines 219-226 __PACKAGE__->has_many( Link Here
219
);
219
);
220
220
221
221
222
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-08-17 19:59:33
222
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-08-19 14:51:55
223
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EKq7nDW2AeZ2NQce2BPMWA
223
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:4fO02fpsQwOOMqJKtNQ7Hg
224
224
225
sub koha_object_class {
225
sub koha_object_class {
226
    'Koha::Virtualshelf';
226
    'Koha::Virtualshelf';
(-)a/Koha/Virtualshelf.pm (-16 / +16 lines)
Lines 44-50 Koha::Virtualshelf - Koha Virtualshelf Object class Link Here
44
sub store {
44
sub store {
45
    my ($self) = @_;
45
    my ($self) = @_;
46
46
47
    unless ( $self->owner ) {
47
    unless ( $self->owner_id ) {
48
        Koha::Exceptions::Virtualshelf::UseDbAdminAccount->throw;
48
        Koha::Exceptions::Virtualshelf::UseDbAdminAccount->throw;
49
    }
49
    }
50
50
Lines 85-99 sub is_shelfname_valid { Link Here
85
        ( $self->shelfnumber ? ( "me.shelfnumber" => { '!=', $self->shelfnumber } ) : () ),
85
        ( $self->shelfnumber ? ( "me.shelfnumber" => { '!=', $self->shelfnumber } ) : () ),
86
    };
86
    };
87
87
88
    if ( $self->is_private and defined $self->owner ) {
88
    if ( $self->is_private and defined $self->owner_id ) {
89
        $conditions->{-or} = {
89
        $conditions->{-or} = {
90
            "virtualshelfshares.borrowernumber" => $self->owner,
90
            "virtualshelfshares.borrowernumber" => $self->owner_id,
91
            "me.owner"                          => $self->owner,
91
            "me.owner_id"                       => $self->owner_id,
92
        };
92
        };
93
        $conditions->{public} = 0;
93
        $conditions->{public} = 0;
94
    } elsif ( $self->is_private and not defined $self->owner ) {
94
    } elsif ( $self->is_private and not defined $self->owner_id ) {
95
        $conditions->{owner}  = undef;
95
        $conditions->{owner_id} = undef;
96
        $conditions->{public} = 0;
96
        $conditions->{public}   = 0;
97
    } else {
97
    } else {
98
        $conditions->{public} = 1;
98
        $conditions->{public} = 1;
99
    }
99
    }
Lines 181-187 sub add_biblio { Link Here
181
    # Check permissions
181
    # Check permissions
182
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
182
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
183
    return 0
183
    return 0
184
        unless ( $self->owner == $borrowernumber && $self->allow_change_from_owner )
184
        unless ( $self->owner_id == $borrowernumber && $self->allow_change_from_owner )
185
        || ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
185
        || ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
186
        || ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
186
        || ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
187
        || $self->allow_change_from_others;
187
        || $self->allow_change_from_others;
Lines 207-213 sub remove_biblios { Link Here
207
207
208
    my $number_removed = 0;
208
    my $number_removed = 0;
209
    my $patron         = Koha::Patrons->find($borrowernumber) or return 0;
209
    my $patron         = Koha::Patrons->find($borrowernumber) or return 0;
210
    if (   ( $self->owner == $borrowernumber && $self->allow_change_from_owner )
210
    if (   ( $self->owner_id == $borrowernumber && $self->allow_change_from_owner )
211
        || ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
211
        || ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
212
        || ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
212
        || ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
213
        || $self->allow_change_from_others )
213
        || $self->allow_change_from_others )
Lines 225-231 sub can_be_viewed { Link Here
225
    my ( $self, $borrowernumber ) = @_;
225
    my ( $self, $borrowernumber ) = @_;
226
    return 1 if $self->is_public;
226
    return 1 if $self->is_public;
227
    return 0 unless $borrowernumber;
227
    return 0 unless $borrowernumber;
228
    return 1 if $self->owner == $borrowernumber;
228
    return 1 if $self->owner_id == $borrowernumber;
229
    return $self->get_shares->search(
229
    return $self->get_shares->search(
230
        {
230
        {
231
            borrowernumber => $borrowernumber,
231
            borrowernumber => $borrowernumber,
Lines 237-243 sub can_be_deleted { Link Here
237
    my ( $self, $borrowernumber ) = @_;
237
    my ( $self, $borrowernumber ) = @_;
238
238
239
    return 0 unless $borrowernumber;
239
    return 0 unless $borrowernumber;
240
    return 1 if $self->owner == $borrowernumber;
240
    return 1 if $self->owner_id == $borrowernumber;
241
241
242
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
242
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
243
243
Lines 249-255 sub can_be_deleted { Link Here
249
sub can_be_managed {
249
sub can_be_managed {
250
    my ( $self, $borrowernumber ) = @_;
250
    my ( $self, $borrowernumber ) = @_;
251
    return 1
251
    return 1
252
        if $borrowernumber and $self->owner == $borrowernumber;
252
        if $borrowernumber and $self->owner_id == $borrowernumber;
253
253
254
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
254
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
255
    return 1
255
    return 1
Lines 263-269 sub can_biblios_be_added { Link Here
263
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
263
    my $patron = Koha::Patrons->find($borrowernumber) or return 0;
264
    return 1
264
    return 1
265
        if $borrowernumber
265
        if $borrowernumber
266
        and ( ( $self->owner == $borrowernumber && $self->allow_change_from_owner )
266
        and ( ( $self->owner_id == $borrowernumber && $self->allow_change_from_owner )
267
        or ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
267
        or ( $self->allow_change_from_staff           && $patron->can_patron_change_staff_only_lists )
268
        or ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
268
        or ( $self->allow_change_from_permitted_staff && $patron->can_patron_change_permitted_staff_lists )
269
        or $self->allow_change_from_others )
269
        or $self->allow_change_from_others )
Lines 361-374 sub transfer_ownership { Link Here
361
        unless $patron_id;
361
        unless $patron_id;
362
362
363
    ## before we change the owner, collect some details
363
    ## before we change the owner, collect some details
364
    my $old_owner  = Koha::Patrons->find( $self->owner );
364
    my $old_owner  = Koha::Patrons->find( $self->owner_id );
365
    my $new_owner  = Koha::Patrons->find($patron_id);
365
    my $new_owner  = Koha::Patrons->find($patron_id);
366
    my $userenv    = C4::Context->userenv;
366
    my $userenv    = C4::Context->userenv;
367
    my $branchcode = $userenv->{branch};
367
    my $branchcode = $userenv->{branch};
368
368
369
    ## first we change the owner
369
    ## first we change the owner
370
    $self->remove_share($patron_id) if $self->is_private;
370
    $self->remove_share($patron_id) if $self->is_private;
371
    $self->set( { owner => $patron_id } )->store;
371
    $self->set( { owner_id => $patron_id } )->store;
372
372
373
    ## now we message the new owner
373
    ## now we message the new owner
374
    my $letter = C4::Letters::GetPreparedLetter(
374
    my $letter = C4::Letters::GetPreparedLetter(
Lines 409-415 sub to_api_mapping { Link Here
409
    return {
409
    return {
410
        created_on   => 'creation_date',
410
        created_on   => 'creation_date',
411
        lastmodified => 'updated_on_date',
411
        lastmodified => 'updated_on_date',
412
        owner        => 'owner_id',
412
        owner_id     => 'owner_id',
413
        shelfname    => 'name',
413
        shelfname    => 'name',
414
        shelfnumber  => 'list_id',
414
        shelfnumber  => 'list_id',
415
        sortfield    => 'default_sort_field',
415
        sortfield    => 'default_sort_field',
(-)a/Koha/Virtualshelves.pm (-6 / +6 lines)
Lines 90-96 sub get_private_shelves { Link Here
90
            public => 0,
90
            public => 0,
91
            -or => {
91
            -or => {
92
                'virtualshelfshares.borrowernumber' => $borrowernumber,
92
                'virtualshelfshares.borrowernumber' => $borrowernumber,
93
                'me.owner' => $borrowernumber,
93
                'me.owner_id' => $borrowernumber,
94
            }
94
            }
95
        },
95
        },
96
        {
96
        {
Lines 148-154 sub get_some_shelves { Link Here
148
                -or =>
148
                -or =>
149
                [
149
                [
150
                    {
150
                    {
151
                        "me.owner" => $borrowernumber,
151
                        "me.owner_id" => $borrowernumber,
152
                        "me.allow_change_from_owner" => 1,
152
                        "me.allow_change_from_owner" => 1,
153
                    },
153
                    },
154
                    "me.allow_change_from_others"          => 1,
154
                    "me.allow_change_from_others"          => 1,
Lines 161-167 sub get_some_shelves { Link Here
161
                -or =>
161
                -or =>
162
                [
162
                [
163
                    {
163
                    {
164
                        "me.owner" => $borrowernumber,
164
                        "me.owner_id" => $borrowernumber,
165
                        "me.allow_change_from_owner" => 1,
165
                        "me.allow_change_from_owner" => 1,
166
                    },
166
                    },
167
                    "me.allow_change_from_others"          => 1,
167
                    "me.allow_change_from_others"          => 1,
Lines 173-179 sub get_some_shelves { Link Here
173
                -or =>
173
                -or =>
174
                [
174
                [
175
                    {
175
                    {
176
                        "me.owner" => $borrowernumber,
176
                        "me.owner_id" => $borrowernumber,
177
                        "me.allow_change_from_owner" => 1,
177
                        "me.allow_change_from_owner" => 1,
178
                    },
178
                    },
179
                    "me.allow_change_from_others" => 1,
179
                    "me.allow_change_from_others" => 1,
Lines 186-192 sub get_some_shelves { Link Here
186
            -or =>
186
            -or =>
187
            {
187
            {
188
                "virtualshelfshares.borrowernumber" => $borrowernumber,
188
                "virtualshelfshares.borrowernumber" => $borrowernumber,
189
                "me.owner" => $borrowernumber,
189
                "me.owner_id" => $borrowernumber,
190
            }
190
            }
191
        };
191
        };
192
    }
192
    }
Lines 221-227 sub get_shelves_containing_record { Link Here
221
                {
221
                {
222
                    public => 0,
222
                    public => 0,
223
                    -or      => {
223
                    -or      => {
224
                        'me.owner' => $borrowernumber,
224
                        'me.owner_id' => $borrowernumber,
225
                        -or        => {
225
                        -or        => {
226
                            'virtualshelfshares.borrowernumber' => $borrowernumber,
226
                            'virtualshelfshares.borrowernumber' => $borrowernumber,
227
                        },
227
                        },
(-)a/installer/data/mysql/atomicupdate/bug_37346-rename-owner-column-to-owner_id-in-virtualshelves.pl (+16 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => "37346",
6
    description => "The VirtualShelf object should have an 'owner' accessor to return the related owner Koha::Patron",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        if( !column_exists( 'virtualshelves', 'owner_id' ) ) {
12
            $dbh->do(q{ ALTER TABLE virtualshelves RENAME COLUMN owner TO owner_id; });
13
            say $out "Rename owner column to owner_id in virtualshelves";
14
        }
15
    },
16
};
(-)a/installer/data/mysql/kohastructure.sql (-3 / +3 lines)
Lines 6675-6681 DROP TABLE IF EXISTS `virtualshelves`; Link Here
6675
CREATE TABLE `virtualshelves` (
6675
CREATE TABLE `virtualshelves` (
6676
  `shelfnumber` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
6676
  `shelfnumber` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
6677
  `shelfname` varchar(255) DEFAULT NULL COMMENT 'name of the list',
6677
  `shelfname` varchar(255) DEFAULT NULL COMMENT 'name of the list',
6678
  `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)',
6678
  `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)',
6679
  `public` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'If the list is public',
6679
  `public` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'If the list is public',
6680
  `sortfield` varchar(16) DEFAULT 'title' COMMENT 'the field this list is sorted on',
6680
  `sortfield` varchar(16) DEFAULT 'title' COMMENT 'the field this list is sorted on',
6681
  `lastmodified` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'date and time the list was last modified',
6681
  `lastmodified` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'date and time the list was last modified',
Lines 6685-6692 CREATE TABLE `virtualshelves` ( Link Here
6685
  `allow_change_from_staff` tinyint(1) DEFAULT 0 COMMENT 'can staff change contents?',
6685
  `allow_change_from_staff` tinyint(1) DEFAULT 0 COMMENT 'can staff change contents?',
6686
  `allow_change_from_permitted_staff` tinyint(1) DEFAULT 0 COMMENT 'can staff with edit_public_list_contents permission change contents?',
6686
  `allow_change_from_permitted_staff` tinyint(1) DEFAULT 0 COMMENT 'can staff with edit_public_list_contents permission change contents?',
6687
  PRIMARY KEY (`shelfnumber`),
6687
  PRIMARY KEY (`shelfnumber`),
6688
  KEY `virtualshelves_ibfk_1` (`owner`),
6688
  KEY `virtualshelves_ibfk_1` (`owner_id`),
6689
  CONSTRAINT `virtualshelves_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL
6689
  CONSTRAINT `virtualshelves_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL
6690
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
6690
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
6691
/*!40101 SET character_set_client = @saved_cs_client */;
6691
/*!40101 SET character_set_client = @saved_cs_client */;
6692
6692
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-5 / +5 lines)
Lines 415-426 Link Here
415
                            <li>
415
                            <li>
416
                                <span class="label">Owner: </span>
416
                                <span class="label">Owner: </span>
417
                                [% IF op == 'add_form' %]
417
                                [% IF op == 'add_form' %]
418
                                    <input type="hidden" name="owner" id="owner" value="[% loggedinusernumber | html %]" />[% logged_in_user.userid | html %]
418
                                    <input type="hidden" name="owner_id" id="owner_id" value="[% loggedinusernumber | html %]" />[% logged_in_user.userid | html %]
419
                                [% ELSE %]
419
                                [% ELSE %]
420
                                    [% IF owner %]
420
                                    [% IF owner_id %]
421
                                        <input type="hidden" id="owner" name="owner" value="[% owner.borrowernumber | html %]" />[% owner.firstname _ ' ' _ owner.surname | html %]
421
                                        <input type="hidden" id="owner_id" name="owner_id" value="[% owner.borrowernumber | html %]" />[% owner_id.firstname _ ' ' _ owner_id.surname | html %]
422
                                    [% ELSE %]
422
                                    [% ELSE %]
423
                                        <input type="hidden" id="owner" name="owner" value="[% loggedinusernumber | html %]" />[% logged_in_user.userid | html %]
423
                                        <input type="hidden" id="owner_id" name="owner_id" value="[% loggedinusernumber | html %]" />[% logged_in_user.userid | html %]
424
                                    [% END %]
424
                                    [% END %]
425
                                [% END %]
425
                                [% END %]
426
                            </li>
426
                            </li>
Lines 633-639 Link Here
633
                            'vs.shelfname',
633
                            'vs.shelfname',
634
                            'count',
634
                            'count',
635
                            'vs.public',
635
                            'vs.public',
636
                            'vs.owner',
636
                            'vs.owner_id',
637
                            'vs.sortfield',
637
                            'vs.sortfield',
638
                            'vs.created_on',
638
                            'vs.created_on',
639
                            'vs.lastmodified',
639
                            'vs.lastmodified',
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt (-1 / +1 lines)
Lines 18-24 Link Here
18
                "dt_is_shared":
18
                "dt_is_shared":
19
                    "[% IF d.public %]<span>Public</span>[% ELSIF d.is_shared %]<span>Shared</span>[% ELSE %]<span>Private</span>[% END %]",
19
                    "[% IF d.public %]<span>Public</span>[% ELSIF d.is_shared %]<span>Shared</span>[% ELSE %]<span>Private</span>[% END %]",
20
                "dt_owner":
20
                "dt_owner":
21
                    "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=[% d.owner | html %]'>[% d.firstname | html | $To %] [% d.surname | html | $To %]</a>",
21
                    "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=[% d.owner_id | html %]'>[% d.firstname | html | $To %] [% d.surname | html | $To %]</a>",
22
                "dt_sortby":
22
                "dt_sortby":
23
                    [% IF d.sortby == "author" %]"<span>Author</span>"[% ELSIF d.sortby == "copyrightdate" %]"<span>Year</span>"[% ELSIF d.sortby == "itemcallnumber" %]"<span>Call number</span>"[% ELSIF d.sortby == "dateadded" %]"<span>Date added</span>"[% ELSE %]"<span>Title</span>"[% END %],
23
                    [% IF d.sortby == "author" %]"<span>Author</span>"[% ELSIF d.sortby == "copyrightdate" %]"<span>Year</span>"[% ELSIF d.sortby == "itemcallnumber" %]"<span>Call number</span>"[% ELSIF d.sortby == "dateadded" %]"<span>Date added</span>"[% ELSE %]"<span>Title</span>"[% END %],
24
                "dt_created_on":
24
                "dt_created_on":
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt (-1 / +1 lines)
Lines 572-578 Link Here
572
                                    <input type="hidden" name="referer" value="[% referer | html %]" />
572
                                    <input type="hidden" name="referer" value="[% referer | html %]" />
573
                                    <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
573
                                    <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
574
                                [% END %]
574
                                [% END %]
575
                                <input type="hidden" name="owner" id="owner" value="[% loggedinusernumber | html %]" />
575
                                <input type="hidden" name="owner_id" id="owner_id" value="[% loggedinusernumber | html %]" />
576
                                <ol>
576
                                <ol>
577
                                    <li>
577
                                    <li>
578
                                        <label class="required" for="shelfname">List name: </label>
578
                                        <label class="required" for="shelfname">List name: </label>
(-)a/opac/opac-addbybiblionumber.pl (-6 / +6 lines)
Lines 62-68 if( $op && $op !~ /^cud-/ ) { Link Here
62
        and (  !$public
62
        and (  !$public
63
            or $public and $loggedinuser > 0 && C4::Context->preference('OpacAllowPublicListCreation') )
63
            or $public and $loggedinuser > 0 && C4::Context->preference('OpacAllowPublicListCreation') )
64
      ) {
64
      ) {
65
        my $shelf = eval { Koha::Virtualshelf->new( { shelfname => $newvirtualshelf, public => $public, owner => $loggedinuser, } )->store; };
65
        my $shelf = eval { Koha::Virtualshelf->new( { shelfname => $newvirtualshelf, public => $public, owner_id => $loggedinuser, } )->store; };
66
        if ( $@ or not $shelf ) {
66
        if ( $@ or not $shelf ) {
67
            $errcode    = 1;
67
            $errcode    = 1;
68
            $authorized = 0;
68
            $authorized = 0;
Lines 105-111 if( $op && $op !~ /^cud-/ ) { Link Here
105
    if ( $loggedinuser > 0 ) {
105
    if ( $loggedinuser > 0 ) {
106
        my $private_shelves = Koha::Virtualshelves->search(
106
        my $private_shelves = Koha::Virtualshelves->search(
107
            {   public   => 0,
107
            {   public   => 0,
108
                owner    => $loggedinuser,
108
                owner_id => $loggedinuser,
109
                allow_change_from_owner => 1,
109
                allow_change_from_owner => 1,
110
            },
110
            },
111
            { order_by => 'shelfname' }
111
            { order_by => 'shelfname' }
Lines 125-131 if( $op && $op !~ /^cud-/ ) { Link Here
125
                        -or      => [
125
                        -or      => [
126
                            -and => {
126
                            -and => {
127
                                allow_change_from_owner => 1,
127
                                allow_change_from_owner => 1,
128
                                owner     => $loggedinuser,
128
                                owner_id  => $loggedinuser,
129
                            },
129
                            },
130
                            allow_change_from_others          => 1,
130
                            allow_change_from_others          => 1,
131
                            allow_change_from_staff           => 1,
131
                            allow_change_from_staff           => 1,
Lines 140-146 if( $op && $op !~ /^cud-/ ) { Link Here
140
                        -or      => [
140
                        -or      => [
141
                            -and => {
141
                            -and => {
142
                                allow_change_from_owner => 1,
142
                                allow_change_from_owner => 1,
143
                                owner     => $loggedinuser,
143
                                owner_id  => $loggedinuser,
144
                            },
144
                            },
145
                            allow_change_from_others          => 1,
145
                            allow_change_from_others          => 1,
146
                            allow_change_from_staff           => 1
146
                            allow_change_from_staff           => 1
Lines 154-160 if( $op && $op !~ /^cud-/ ) { Link Here
154
                        -or      => [
154
                        -or      => [
155
                            -and => {
155
                            -and => {
156
                                allow_change_from_owner => 1,
156
                                allow_change_from_owner => 1,
157
                                owner => $loggedinuser,
157
                                owner_id => $loggedinuser,
158
                            },
158
                            },
159
                            allow_change_from_others => 1,
159
                            allow_change_from_others => 1,
160
                        ],
160
                        ],
Lines 168-174 if( $op && $op !~ /^cud-/ ) { Link Here
168
                    -or      => [
168
                    -or      => [
169
                        -and => {
169
                        -and => {
170
                            allow_change_from_owner => 1,
170
                            allow_change_from_owner => 1,
171
                            owner => $loggedinuser,
171
                            owner_id => $loggedinuser,
172
                        },
172
                        },
173
                        allow_change_from_others => 1,
173
                        allow_change_from_others => 1,
174
                    ],
174
                    ],
(-)a/opac/opac-shelves.pl (-4 / +4 lines)
Lines 103-110 if ( $op eq 'add_form' ) { Link Here
103
103
104
    if ( $shelf ) {
104
    if ( $shelf ) {
105
        $public = $shelf->public;
105
        $public = $shelf->public;
106
        my $patron = Koha::Patrons->find( $shelf->owner );
106
        my $patron = Koha::Patrons->find( $shelf->owner_id );
107
        $template->param( owner => $patron, );
107
        $template->param( owner_id => $patron, );
108
        unless ( $shelf->can_be_managed( $loggedinuser ) ) {
108
        unless ( $shelf->can_be_managed( $loggedinuser ) ) {
109
            push @messages, { type => 'error', code => 'unauthorized_on_update' };
109
            push @messages, { type => 'error', code => 'unauthorized_on_update' };
110
            $op = 'list';
110
            $op = 'list';
Lines 124-130 if ( $op eq 'add_form' ) { Link Here
124
                    allow_change_from_others           => $allow_changes_from == ANYONE,
124
                    allow_change_from_others           => $allow_changes_from == ANYONE,
125
                    allow_change_from_staff            => $allow_changes_from == STAFF,
125
                    allow_change_from_staff            => $allow_changes_from == STAFF,
126
                    allow_change_from_permitted_staff => $allow_changes_from == PERMITTED,
126
                    allow_change_from_permitted_staff => $allow_changes_from == PERMITTED,
127
                    owner              => scalar $loggedinuser,
127
                    owner_id           => scalar $loggedinuser,
128
                }
128
                }
129
            );
129
            );
130
            $shelf->store;
130
            $shelf->store;
Lines 290-296 if ( $op eq 'add_form' ) { Link Here
290
        $shelf->_result->result_source->schema->txn_do( sub {
290
        $shelf->_result->result_source->schema->txn_do( sub {
291
            $shelf->get_shares->search({ borrowernumber => $new_owner })->delete;
291
            $shelf->get_shares->search({ borrowernumber => $new_owner })->delete;
292
            Koha::Virtualshelfshare->new({ shelfnumber => $shelfnumber, borrowernumber => $loggedinuser, sharedate => dt_from_string })->store;
292
            Koha::Virtualshelfshare->new({ shelfnumber => $shelfnumber, borrowernumber => $loggedinuser, sharedate => dt_from_string })->store;
293
            $shelf->owner($new_owner)->store;
293
            $shelf->owner_id($new_owner)->store;
294
        });
294
        });
295
        $op = 'list';
295
        $op = 'list';
296
    }
296
    }
(-)a/t/db_dependent/Koha/Patrons.t (-13 / +13 lines)
Lines 473-489 subtest "delete" => sub { Link Here
473
    my $modification = $builder->build_object({ class => 'Koha::Patron::Modifications', value => { borrowernumber => $patron->borrowernumber } });
473
    my $modification = $builder->build_object({ class => 'Koha::Patron::Modifications', value => { borrowernumber => $patron->borrowernumber } });
474
    my $private_list = Koha::Virtualshelf->new({
474
    my $private_list = Koha::Virtualshelf->new({
475
        shelfname => "private",
475
        shelfname => "private",
476
        owner => $patron->borrowernumber,
476
        owner_id => $patron->borrowernumber,
477
        public => 0,
477
        public => 0,
478
    })->store;
478
    })->store;
479
    my $public_list = Koha::Virtualshelf->new({
479
    my $public_list = Koha::Virtualshelf->new({
480
        shelfname => "public",
480
        shelfname => "public",
481
        owner => $patron->borrowernumber,
481
        owner_id => $patron->borrowernumber,
482
        public => 1,
482
        public => 1,
483
    })->store;
483
    })->store;
484
    my $list_to_share = Koha::Virtualshelf->new({
484
    my $list_to_share = Koha::Virtualshelf->new({
485
        shelfname => "shared",
485
        shelfname => "shared",
486
        owner => $patron->borrowernumber,
486
        owner_id => $patron->borrowernumber,
487
        public => 0,
487
        public => 0,
488
    })->store;
488
    })->store;
489
489
Lines 499-509 subtest "delete" => sub { Link Here
499
499
500
    is( Koha::Holds->search( { borrowernumber => $patron->borrowernumber } )->count, 0, q|Koha::Patron->delete should have cancelled patron's holds 2| );
500
    is( Koha::Holds->search( { borrowernumber => $patron->borrowernumber } )->count, 0, q|Koha::Patron->delete should have cancelled patron's holds 2| );
501
501
502
    my $transferred_lists = Koha::Virtualshelves->search({ owner => $staff_patron->borrowernumber })->count;
502
    my $transferred_lists = Koha::Virtualshelves->search({ owner_id => $staff_patron->borrowernumber })->count;
503
    is( $transferred_lists, 2, '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');
503
    is( $transferred_lists, 2, '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');
504
    is( Koha::Virtualshelfshares->search({ borrowernumber => $staff_patron->borrowernumber })->count, 0, "New owner of list should have shares removed" );
504
    is( Koha::Virtualshelfshares->search({ borrowernumber => $staff_patron->borrowernumber })->count, 0, "New owner of list should have shares removed" );
505
    is( Koha::Virtualshelfshares->search({ borrowernumber => $patron_for_sharing->borrowernumber })->count, 1, "But the other share is still there" );
505
    is( Koha::Virtualshelfshares->search({ borrowernumber => $patron_for_sharing->borrowernumber })->count, 1, "But the other share is still there" );
506
    is( Koha::Virtualshelves->search({ owner => $patron->borrowernumber })->count, 0, q|Koha::Patron->delete should have deleted patron's lists/removed their ownership| );
506
    is( Koha::Virtualshelves->search({ owner_id => $patron->borrowernumber })->count, 0, q|Koha::Patron->delete should have deleted patron's lists/removed their ownership| );
507
507
508
    is( Koha::Patron::Modifications->search( { borrowernumber => $patron->borrowernumber } )->count, 0, q|Koha::Patron->delete should have deleted patron's modifications| );
508
    is( Koha::Patron::Modifications->search( { borrowernumber => $patron->borrowernumber } )->count, 0, q|Koha::Patron->delete should have deleted patron's modifications| );
509
509
Lines 514-527 subtest "delete" => sub { Link Here
514
    my $designated_owner = $builder->build_object({ class => 'Koha::Patrons' });
514
    my $designated_owner = $builder->build_object({ class => 'Koha::Patrons' });
515
    t::lib::Mocks::mock_preference( 'ListOwnerDesignated', $designated_owner->id );
515
    t::lib::Mocks::mock_preference( 'ListOwnerDesignated', $designated_owner->id );
516
    $patron = $builder->build_object({ class => 'Koha::Patrons' });
516
    $patron = $builder->build_object({ class => 'Koha::Patrons' });
517
    $private_list = Koha::Virtualshelf->new({ shelfname => "PR1", owner => $patron->id })->store;
517
    $private_list = Koha::Virtualshelf->new({ shelfname => "PR1", owner_id => $patron->id })->store;
518
    $public_list = Koha::Virtualshelf->new({ shelfname => "PU1", public => 1, owner => $patron->id })->store;
518
    $public_list = Koha::Virtualshelf->new({ shelfname => "PU1", public => 1, owner_id => $patron->id })->store;
519
    $list_to_share = Koha::Virtualshelf->new({ shelfname => "SH1", owner => $patron->id })->store;
519
    $list_to_share = Koha::Virtualshelf->new({ shelfname => "SH1", owner_id => $patron->id })->store;
520
    $list_to_share->share("valid key")->accept( "valid key", $patron_for_sharing->id );
520
    $list_to_share->share("valid key")->accept( "valid key", $patron_for_sharing->id );
521
    $patron->delete;
521
    $patron->delete;
522
    is( Koha::Virtualshelves->find( $private_list->id ), undef, 'Private list gone' );
522
    is( Koha::Virtualshelves->find( $private_list->id ), undef, 'Private list gone' );
523
    is( $public_list->discard_changes->get_column('owner'), $designated_owner->id, 'Public list transferred' );
523
    is( $public_list->discard_changes->get_column('owner_id'), $designated_owner->id, 'Public list transferred' );
524
    is( $list_to_share->discard_changes->get_column('owner'), $designated_owner->id, 'Shared list transferred' );
524
    is( $list_to_share->discard_changes->get_column('owner_id'), $designated_owner->id, 'Shared list transferred' );
525
525
526
    # Finally test deleting lists
526
    # Finally test deleting lists
527
    t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' );
527
    t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' );
Lines 529-545 subtest "delete" => sub { Link Here
529
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
529
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
530
    my $private_list2 = Koha::Virtualshelf->new({
530
    my $private_list2 = Koha::Virtualshelf->new({
531
         shelfname => "private",
531
         shelfname => "private",
532
         owner => $patron2->borrowernumber,
532
         owner_id => $patron2->borrowernumber,
533
         public => 0,
533
         public => 0,
534
    })->store;
534
    })->store;
535
    my $public_list2 = Koha::Virtualshelf->new({
535
    my $public_list2 = Koha::Virtualshelf->new({
536
        shelfname => "public",
536
        shelfname => "public",
537
        owner => $patron2->borrowernumber,
537
        owner_id => $patron2->borrowernumber,
538
        public => 1,
538
        public => 1,
539
    })->store;
539
    })->store;
540
    my $list_to_share2 = Koha::Virtualshelf->new({
540
    my $list_to_share2 = Koha::Virtualshelf->new({
541
        shelfname => "shared",
541
        shelfname => "shared",
542
        owner => $patron2->borrowernumber,
542
        owner_id => $patron2->borrowernumber,
543
        public => 0,
543
        public => 0,
544
    })->store;
544
    })->store;
545
    $list_to_share2->share("valid key")->accept( "valid key", $patron_for_sharing->borrowernumber );
545
    $list_to_share2->share("valid key")->accept( "valid key", $patron_for_sharing->borrowernumber );
(-)a/t/db_dependent/Koha/Virtualshelf.t (-4 / +4 lines)
Lines 41-54 subtest 'transfer_ownership() tests' => sub { Link Here
41
    my $public_list = $builder->build_object(
41
    my $public_list = $builder->build_object(
42
        {
42
        {
43
            class => "Koha::Virtualshelves",
43
            class => "Koha::Virtualshelves",
44
            value => { owner => $patron_1->id, public => 1 }
44
            value => { owner_id => $patron_1->id, public => 1 }
45
        }
45
        }
46
    );
46
    );
47
47
48
    my $private_list = $builder->build_object(
48
    my $private_list = $builder->build_object(
49
        {
49
        {
50
            class => "Koha::Virtualshelves",
50
            class => "Koha::Virtualshelves",
51
            value => { owner => $patron_1->id, public => 0 }
51
            value => { owner_id => $patron_1->id, public => 0 }
52
        }
52
        }
53
    );
53
    );
54
54
Lines 81-87 subtest 'transfer_ownership() tests' => sub { Link Here
81
    $public_list->transfer_ownership( $patron_2->id );
81
    $public_list->transfer_ownership( $patron_2->id );
82
    $public_list->discard_changes;
82
    $public_list->discard_changes;
83
83
84
    is( $public_list->owner, $patron_2->id, 'Owner changed correctly' );
84
    is( $public_list->owner_id, $patron_2->id, 'Owner changed correctly' );
85
    my $public_list_shares = $public_list->get_shares;
85
    my $public_list_shares = $public_list->get_shares;
86
    is( $public_list_shares->count,                1,             'Count is correct' );
86
    is( $public_list_shares->count,                1,             'Count is correct' );
87
    is( $public_list_shares->next->borrowernumber, $patron_2->id, "Public lists don't get the share removed" );
87
    is( $public_list_shares->next->borrowernumber, $patron_2->id, "Public lists don't get the share removed" );
Lines 89-95 subtest 'transfer_ownership() tests' => sub { Link Here
89
    $private_list->transfer_ownership( $patron_2->id );
89
    $private_list->transfer_ownership( $patron_2->id );
90
    $private_list->discard_changes;
90
    $private_list->discard_changes;
91
91
92
    is( $private_list->owner, $patron_2->id );
92
    is( $private_list->owner_id, $patron_2->id );
93
    my $private_list_shares = $private_list->get_shares;
93
    my $private_list_shares = $private_list->get_shares;
94
    is( $private_list_shares->count, 1, 'Count is correct' );
94
    is( $private_list_shares->count, 1, 'Count is correct' );
95
    is(
95
    is(
(-)a/t/db_dependent/Koha/Virtualshelves.t (-14 / +14 lines)
Lines 45-65 subtest 'disown_or_delete() tests' => sub { Link Here
45
        my $public_list = $builder->build_object(
45
        my $public_list = $builder->build_object(
46
            {
46
            {
47
                class => "Koha::Virtualshelves",
47
                class => "Koha::Virtualshelves",
48
                value => { owner => $patron_1->id, public => 1 }
48
                value => { owner_id => $patron_1->id, public => 1 }
49
            }
49
            }
50
        );
50
        );
51
51
52
        my $private_list = $builder->build_object(
52
        my $private_list = $builder->build_object(
53
            {
53
            {
54
                class => "Koha::Virtualshelves",
54
                class => "Koha::Virtualshelves",
55
                value => { owner => $patron_1->id, public => 0 }
55
                value => { owner_id => $patron_1->id, public => 0 }
56
            }
56
            }
57
        );
57
        );
58
58
59
        my $private_list_shared = $builder->build_object(
59
        my $private_list_shared = $builder->build_object(
60
            {
60
            {
61
                class => "Koha::Virtualshelves",
61
                class => "Koha::Virtualshelves",
62
                value => { owner => $patron_1->id, public => 0 }
62
                value => { owner_id => $patron_1->id, public => 0 }
63
            }
63
            }
64
        );
64
        );
65
65
Lines 83-93 subtest 'disown_or_delete() tests' => sub { Link Here
83
        is( $rs->count, 2, 'The private/non-shared list was deleted' );
83
        is( $rs->count, 2, 'The private/non-shared list was deleted' );
84
        my $first = $rs->next;
84
        my $first = $rs->next;
85
        is( $first->id, $public_list->id );
85
        is( $first->id, $public_list->id );
86
        is( $first->owner, $patron_2->id );
86
        is( $first->owner_id, $patron_2->id );
87
87
88
        my $second = $rs->next;
88
        my $second = $rs->next;
89
        is( $second->id, $private_list_shared->id );
89
        is( $second->id, $private_list_shared->id );
90
        is( $second->owner, $patron_2->id );
90
        is( $second->owner_id, $patron_2->id );
91
91
92
        $schema->storage->txn_rollback;
92
        $schema->storage->txn_rollback;
93
    };
93
    };
Lines 105-125 subtest 'disown_or_delete() tests' => sub { Link Here
105
        my $public_list = $builder->build_object(
105
        my $public_list = $builder->build_object(
106
            {
106
            {
107
                class => "Koha::Virtualshelves",
107
                class => "Koha::Virtualshelves",
108
                value => { owner => $patron_1->id, public => 1 }
108
                value => { owner_id => $patron_1->id, public => 1 }
109
            }
109
            }
110
        );
110
        );
111
111
112
        my $private_list = $builder->build_object(
112
        my $private_list = $builder->build_object(
113
            {
113
            {
114
                class => "Koha::Virtualshelves",
114
                class => "Koha::Virtualshelves",
115
                value => { owner => $patron_1->id, public => 0 }
115
                value => { owner_id => $patron_1->id, public => 0 }
116
            }
116
            }
117
        );
117
        );
118
118
119
        my $private_list_shared = $builder->build_object(
119
        my $private_list_shared = $builder->build_object(
120
            {
120
            {
121
                class => "Koha::Virtualshelves",
121
                class => "Koha::Virtualshelves",
122
                value => { owner => $patron_1->id, public => 0 }
122
                value => { owner_id => $patron_1->id, public => 0 }
123
            }
123
            }
124
        );
124
        );
125
125
Lines 137-143 subtest 'disown_or_delete() tests' => sub { Link Here
137
        my $public_list_to_delete = $builder->build_object(
137
        my $public_list_to_delete = $builder->build_object(
138
            {
138
            {
139
                class => "Koha::Virtualshelves",
139
                class => "Koha::Virtualshelves",
140
                value => { owner => $patron_1->id, public => 1 }
140
                value => { owner_id => $patron_1->id, public => 1 }
141
            }
141
            }
142
        );
142
        );
143
143
Lines 158-168 subtest 'disown_or_delete() tests' => sub { Link Here
158
        is( $rs->count, 2, 'The private/non-shared list was deleted' );
158
        is( $rs->count, 2, 'The private/non-shared list was deleted' );
159
        my $first = $rs->next;
159
        my $first = $rs->next;
160
        is( $first->id, $public_list->id );
160
        is( $first->id, $public_list->id );
161
        is( $first->owner, $patron_3->id );
161
        is( $first->owner_id, $patron_3->id );
162
162
163
        my $second = $rs->next;
163
        my $second = $rs->next;
164
        is( $second->id, $private_list_shared->id );
164
        is( $second->id, $private_list_shared->id );
165
        is( $second->owner, $patron_3->id );
165
        is( $second->owner_id, $patron_3->id );
166
166
167
        $schema->storage->txn_rollback;
167
        $schema->storage->txn_rollback;
168
    };
168
    };
Lines 180-200 subtest 'disown_or_delete() tests' => sub { Link Here
180
        my $public_list = $builder->build_object(
180
        my $public_list = $builder->build_object(
181
            {
181
            {
182
                class => "Koha::Virtualshelves",
182
                class => "Koha::Virtualshelves",
183
                value => { owner => $patron_1->id, public => 1 }
183
                value => { owner_id => $patron_1->id, public => 1 }
184
            }
184
            }
185
        );
185
        );
186
186
187
        my $private_list = $builder->build_object(
187
        my $private_list = $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
193
194
        my $private_list_shared = $builder->build_object(
194
        my $private_list_shared = $builder->build_object(
195
            {
195
            {
196
                class => "Koha::Virtualshelves",
196
                class => "Koha::Virtualshelves",
197
                value => { owner => $patron_1->id, public => 0 }
197
                value => { owner_id => $patron_1->id, public => 0 }
198
            }
198
            }
199
        );
199
        );
200
200
(-)a/t/db_dependent/Utils/Datatables_Virtualshelves.t (-6 / +6 lines)
Lines 89-95 my $shelf1 = Koha::Virtualshelf->new( Link Here
89
        shelfname => 'my first private list (empty)',
89
        shelfname => 'my first private list (empty)',
90
        public    => 0,
90
        public    => 0,
91
        sortfield => 'author',
91
        sortfield => 'author',
92
        owner     => $john_doe{borrowernumber},
92
        owner_id  => $john_doe{borrowernumber},
93
    }
93
    }
94
)->store;
94
)->store;
95
95
Lines 98-104 my $shelf2 = Koha::Virtualshelf->new( Link Here
98
        shelfname => 'my second private list',
98
        shelfname => 'my second private list',
99
        public    => 0,
99
        public    => 0,
100
        sortfield => 'title',
100
        sortfield => 'title',
101
        owner     => $john_doe{borrowernumber},
101
        owner_id  => $john_doe{borrowernumber},
102
    }
102
    }
103
)->store;
103
)->store;
104
my $biblionumber1 = _add_biblio('title 1');
104
my $biblionumber1 = _add_biblio('title 1');
Lines 117-123 my $shelf3 = Koha::Virtualshelf->new( Link Here
117
        shelfname => 'The first public list',
117
        shelfname => 'The first public list',
118
        public    => 1,
118
        public    => 1,
119
        sortfield => 'author',
119
        sortfield => 'author',
120
        owner     => $jane_doe{borrowernumber},
120
        owner_id  => $jane_doe{borrowernumber},
121
    }
121
    }
122
)->store;
122
)->store;
123
my $biblionumber6 = _add_biblio('title 6');
123
my $biblionumber6 = _add_biblio('title 6');
Lines 132-138 my $shelf4 = Koha::Virtualshelf->new( Link Here
132
        shelfname => 'my second public list',
132
        shelfname => 'my second public list',
133
        public    => 1,
133
        public    => 1,
134
        sortfield => 'title',
134
        sortfield => 'title',
135
        owner     => $jane_doe{borrowernumber},
135
        owner_id  => $jane_doe{borrowernumber},
136
    }
136
    }
137
)->store;
137
)->store;
138
my $biblionumber9  = _add_biblio('title 9');
138
my $biblionumber9  = _add_biblio('title 9');
Lines 149-155 my $shelf5 = Koha::Virtualshelf->new( Link Here
149
        shelfname => 'my third private list',
149
        shelfname => 'my third private list',
150
        public    => 0,
150
        public    => 0,
151
        sortfield => 'title',
151
        sortfield => 'title',
152
        owner     => $jane_doe{borrowernumber},
152
        owner_id  => $jane_doe{borrowernumber},
153
    }
153
    }
154
)->store;
154
)->store;
155
my $biblionumber13 = _add_biblio('title 13');
155
my $biblionumber13 = _add_biblio('title 13');
Lines 170-176 for my $i ( 6 .. 15 ) { Link Here
170
        {
170
        {
171
            shelfname => "another public list $i",
171
            shelfname => "another public list $i",
172
            public    => 1,
172
            public    => 1,
173
            owner     => $john_smith{borrowernumber},
173
            owner_id  => $john_smith{borrowernumber},
174
        }
174
        }
175
    )->store;
175
    )->store;
176
}
176
}
(-)a/t/db_dependent/Virtualshelves.t (-20 / +20 lines)
Lines 50-56 subtest 'CRUD' => sub { Link Here
50
50
51
    my $shelf = Koha::Virtualshelf->new({
51
    my $shelf = Koha::Virtualshelf->new({
52
            shelfname => "my first shelf",
52
            shelfname => "my first shelf",
53
            owner => $patron->{borrowernumber},
53
            owner_id => $patron->{borrowernumber},
54
            public => 0,
54
            public => 0,
55
        }
55
        }
56
    )->store;
56
    )->store;
Lines 79-85 subtest 'CRUD' => sub { Link Here
79
    eval {
79
    eval {
80
        $shelf = Koha::Virtualshelf->new({
80
        $shelf = Koha::Virtualshelf->new({
81
                shelfname => "my first shelf",
81
                shelfname => "my first shelf",
82
                owner => $patron->{borrowernumber},
82
                owner_id => $patron->{borrowernumber},
83
                public => 0,
83
                public => 0,
84
            }
84
            }
85
        )->store;
85
        )->store;
Lines 95-101 subtest 'CRUD' => sub { Link Here
95
95
96
    $shelf = Koha::Virtualshelf->new({
96
    $shelf = Koha::Virtualshelf->new({
97
            shelfname => "my first shelf",
97
            shelfname => "my first shelf",
98
            owner => $another_patron->{borrowernumber},
98
            owner_id => $another_patron->{borrowernumber},
99
            public => 0,
99
            public => 0,
100
        }
100
        }
101
    )->store;
101
    )->store;
Lines 127-140 subtest 'Sharing' => sub { Link Here
127
127
128
    my $shelf_to_share = Koha::Virtualshelf->new({
128
    my $shelf_to_share = Koha::Virtualshelf->new({
129
            shelfname => "my first shelf",
129
            shelfname => "my first shelf",
130
            owner => $patron_wants_to_share->{borrowernumber},
130
            owner_id => $patron_wants_to_share->{borrowernumber},
131
            public => 0,
131
            public => 0,
132
        }
132
        }
133
    )->store;
133
    )->store;
134
134
135
    my $shelf_not_to_share = Koha::Virtualshelf->new({
135
    my $shelf_not_to_share = Koha::Virtualshelf->new({
136
            shelfname => "my second shelf",
136
            shelfname => "my second shelf",
137
            owner => $patron_wants_to_share->{borrowernumber},
137
            owner_id => $patron_wants_to_share->{borrowernumber},
138
            public => 0,
138
            public => 0,
139
        }
139
        }
140
    )->store;
140
    )->store;
Lines 216-222 subtest 'Shelf content' => sub { Link Here
216
    my $dt_yesterday = dt_from_string->subtract_duration( DateTime::Duration->new( days => 1 ) );
216
    my $dt_yesterday = dt_from_string->subtract_duration( DateTime::Duration->new( days => 1 ) );
217
    my $shelf = Koha::Virtualshelf->new(
217
    my $shelf = Koha::Virtualshelf->new(
218
        {   shelfname    => "my first shelf",
218
        {   shelfname    => "my first shelf",
219
            owner        => $patron1->{borrowernumber},
219
            owner_id     => $patron1->{borrowernumber},
220
            public       => 0,
220
            public       => 0,
221
            lastmodified => $dt_yesterday,
221
            lastmodified => $dt_yesterday,
222
        }
222
        }
Lines 333-339 subtest 'Shelf permissions' => sub { Link Here
333
333
334
    my $public_shelf = Koha::Virtualshelf->new(
334
    my $public_shelf = Koha::Virtualshelf->new(
335
        {   shelfname    => "my first shelf",
335
        {   shelfname    => "my first shelf",
336
            owner        => $patron1->{borrowernumber},
336
            owner_id      => $patron1->{borrowernumber},
337
            public       => 1,
337
            public       => 1,
338
            allow_change_from_owner           => 0,
338
            allow_change_from_owner           => 0,
339
            allow_change_from_others          => 0,
339
            allow_change_from_others          => 0,
Lines 473-479 subtest 'Shelf permissions' => sub { Link Here
473
473
474
    my $private_shelf = Koha::Virtualshelf->new(
474
    my $private_shelf = Koha::Virtualshelf->new(
475
        {   shelfname    => "my first shelf",
475
        {   shelfname    => "my first shelf",
476
            owner        => $patron1->{borrowernumber},
476
            owner_id     => $patron1->{borrowernumber},
477
            public       => 0,
477
            public       => 0,
478
            allow_change_from_owner => 0,
478
            allow_change_from_owner => 0,
479
            allow_change_from_others => 0,
479
            allow_change_from_others => 0,
Lines 595-631 subtest 'Get shelves' => sub { Link Here
595
595
596
    my $private_shelf1_1 = Koha::Virtualshelf->new({
596
    my $private_shelf1_1 = Koha::Virtualshelf->new({
597
            shelfname => "private shelf 1 for patron 1",
597
            shelfname => "private shelf 1 for patron 1",
598
            owner => $patron1->{borrowernumber},
598
            owner_id => $patron1->{borrowernumber},
599
            public => 0,
599
            public => 0,
600
        }
600
        }
601
    )->store;
601
    )->store;
602
    my $private_shelf1_2 = Koha::Virtualshelf->new({
602
    my $private_shelf1_2 = Koha::Virtualshelf->new({
603
            shelfname => "private shelf 2 for patron 1",
603
            shelfname => "private shelf 2 for patron 1",
604
            owner => $patron1->{borrowernumber},
604
            owner_id => $patron1->{borrowernumber},
605
            public => 0,
605
            public => 0,
606
        }
606
        }
607
    )->store;
607
    )->store;
608
    my $private_shelf2_1 = Koha::Virtualshelf->new({
608
    my $private_shelf2_1 = Koha::Virtualshelf->new({
609
            shelfname => "private shelf 1 for patron 2",
609
            shelfname => "private shelf 1 for patron 2",
610
            owner => $patron2->{borrowernumber},
610
            owner_id => $patron2->{borrowernumber},
611
            public => 0,
611
            public => 0,
612
        }
612
        }
613
    )->store;
613
    )->store;
614
    my $public_shelf1_1 = Koha::Virtualshelf->new({
614
    my $public_shelf1_1 = Koha::Virtualshelf->new({
615
            shelfname => "public shelf 1 for patron 1",
615
            shelfname => "public shelf 1 for patron 1",
616
            owner => $patron1->{borrowernumber},
616
            owner_id => $patron1->{borrowernumber},
617
            public => 1,
617
            public => 1,
618
        }
618
        }
619
    )->store;
619
    )->store;
620
    my $public_shelf1_2 = Koha::Virtualshelf->new({
620
    my $public_shelf1_2 = Koha::Virtualshelf->new({
621
            shelfname => "public shelf 2 for patron 1",
621
            shelfname => "public shelf 2 for patron 1",
622
            owner => $patron1->{borrowernumber},
622
            owner_id => $patron1->{borrowernumber},
623
            public => 1,
623
            public => 1,
624
        }
624
        }
625
    )->store;
625
    )->store;
626
    my $shelf_to_share = Koha::Virtualshelf->new({
626
    my $shelf_to_share = Koha::Virtualshelf->new({
627
            shelfname => "shared shelf",
627
            shelfname => "shared shelf",
628
            owner => $patron1->{borrowernumber},
628
            owner_id => $patron1->{borrowernumber},
629
            public => 0,
629
            public => 0,
630
        }
630
        }
631
    )->store;
631
    )->store;
Lines 661-679 subtest 'Get shelves containing biblios' => sub { Link Here
661
661
662
    my $shelf1 = Koha::Virtualshelf->new(
662
    my $shelf1 = Koha::Virtualshelf->new(
663
        {   shelfname    => "my first shelf",
663
        {   shelfname    => "my first shelf",
664
            owner        => $patron1->{borrowernumber},
664
            owner_id     => $patron1->{borrowernumber},
665
            public       => 0,
665
            public       => 0,
666
        }
666
        }
667
    )->store;
667
    )->store;
668
    my $shelf2 = Koha::Virtualshelf->new(
668
    my $shelf2 = Koha::Virtualshelf->new(
669
        {   shelfname    => "my x second shelf", # 'x' to make it sorted after 'third'
669
        {   shelfname    => "my x second shelf", # 'x' to make it sorted after 'third'
670
            owner        => $patron2->{borrowernumber},
670
            owner_id     => $patron2->{borrowernumber},
671
            public       => 0,
671
            public       => 0,
672
        }
672
        }
673
    )->store;
673
    )->store;
674
    my $shelf3 = Koha::Virtualshelf->new(
674
    my $shelf3 = Koha::Virtualshelf->new(
675
        {   shelfname    => "my third shelf",
675
        {   shelfname    => "my third shelf",
676
            owner        => $patron1->{borrowernumber},
676
            owner_id     => $patron1->{borrowernumber},
677
            public       => 1,
677
            public       => 1,
678
        }
678
        }
679
    )->store;
679
    )->store;
Lines 748-756 subtest 'cannot_be_transferred' => sub { Link Here
748
    $removed_patron->delete;
748
    $removed_patron->delete;
749
749
750
    # Create three lists
750
    # Create three lists
751
    my $private_list = Koha::Virtualshelf->new({ shelfname => "A", owner => $listowner->id })->store;
751
    my $private_list = Koha::Virtualshelf->new({ shelfname => "A", owner_id => $listowner->id })->store;
752
    my $public_list = Koha::Virtualshelf->new({ shelfname => "B", public => 1, owner => $listowner->id })->store;
752
    my $public_list = Koha::Virtualshelf->new({ shelfname => "B", public => 1, owner_id => $listowner->id })->store;
753
    my $shared_list = Koha::Virtualshelf->new({ shelfname => "C", owner => $listowner->id })->store;
753
    my $shared_list = Koha::Virtualshelf->new({ shelfname => "C", owner_id => $listowner->id })->store;
754
    $shared_list->share("key")->accept( "key", $receiver->id );
754
    $shared_list->share("key")->accept( "key", $receiver->id );
755
755
756
    # Test on private list
756
    # Test on private list
(-)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 153-159 if ( $op && $op !~ /^cud-/ ) { Link Here
153
} else {
153
} else {
154
    my $private_shelves = Koha::Virtualshelves->search(
154
    my $private_shelves = Koha::Virtualshelves->search(
155
        {   public                  => 0,
155
        {   public                  => 0,
156
            owner                   => $loggedinuser,
156
            owner_id                => $loggedinuser,
157
            allow_change_from_owner => 1,
157
            allow_change_from_owner => 1,
158
        },
158
        },
159
        { order_by => 'shelfname' }
159
        { order_by => 'shelfname' }
Lines 170-176 if ( $op && $op !~ /^cud-/ ) { Link Here
170
            -or      => [
170
            -or      => [
171
                -and => {
171
                -and => {
172
                    allow_change_from_owner => 1,
172
                    allow_change_from_owner => 1,
173
                    owner     => $loggedinuser,
173
                    owner_id  => $loggedinuser,
174
                },
174
                },
175
                allow_change_from_others => 1,
175
                allow_change_from_others => 1,
176
                allow_change_from_staff  => 1,
176
                allow_change_from_staff  => 1,
(-)a/virtualshelves/shelves.pl (-4 / +3 lines)
Lines 76-83 if ( $op eq 'add_form' ) { Link Here
76
76
77
    if ( $shelf ) {
77
    if ( $shelf ) {
78
        $public = $shelf->public;
78
        $public = $shelf->public;
79
        my $patron = Koha::Patrons->find( $shelf->owner )->unblessed;
79
        my $patron = Koha::Patrons->find( $shelf->owner_id )->unblessed;
80
        $template->param( owner => $patron, );
80
        $template->param( owner_id => $patron, );
81
        unless ( $shelf->can_be_managed( $loggedinuser ) ) {
81
        unless ( $shelf->can_be_managed( $loggedinuser ) ) {
82
            push @messages, { type => 'alert', code => 'unauthorized_on_update' };
82
            push @messages, { type => 'alert', code => 'unauthorized_on_update' };
83
            $op = 'list';
83
            $op = 'list';
Lines 97-103 if ( $op eq 'add_form' ) { Link Here
97
                allow_change_from_others          => $allow_changes_from == ANYONE,
97
                allow_change_from_others          => $allow_changes_from == ANYONE,
98
                allow_change_from_staff           => $allow_changes_from == STAFF,
98
                allow_change_from_staff           => $allow_changes_from == STAFF,
99
                allow_change_from_permitted_staff => $allow_changes_from == PERMITTED,
99
                allow_change_from_permitted_staff => $allow_changes_from == PERMITTED,
100
                owner              => scalar $query->param('owner'),
100
                owner_id           => scalar $query->param('owner_id'),
101
            }
101
            }
102
        );
102
        );
103
        $shelf->store;
103
        $shelf->store;
104
- 

Return to bug 37346