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

(-)a/Koha/Virtualshelf.pm (-44 / +30 lines)
Lines 60-77 sub store { Link Here
60
        Koha::Exceptions::Virtualshelves::DuplicateObject->throw;
60
        Koha::Exceptions::Virtualshelves::DuplicateObject->throw;
61
    }
61
    }
62
62
63
    $self->allow_add( 0 )
63
    $self->allow_change_from_owner( 1 )
64
        unless defined $self->allow_add;
64
        unless defined $self->allow_change_from_owner;
65
    $self->allow_delete_own( 1 )
65
    $self->allow_change_from_others( 0 )
66
        unless defined $self->allow_delete_own;
66
        unless defined $self->allow_change_from_others;
67
    $self->allow_delete_other( 0 )
68
        unless defined $self->allow_delete_other;
69
67
70
    $self->created_on( dt_from_string );
68
    $self->created_on( dt_from_string );
71
69
72
    return $self->SUPER::store( $self );
70
    return $self->SUPER::store( $self );
73
}
71
}
74
72
73
sub is_public {
74
    my ( $self ) = @_;
75
    return $self->category == $PUBLIC;
76
}
77
78
sub is_private {
79
    my ( $self ) = @_;
80
    return $self->category == $PRIVATE;
81
}
82
75
sub is_shelfname_valid {
83
sub is_shelfname_valid {
76
    my ( $self ) = @_;
84
    my ( $self ) = @_;
77
85
Lines 80-93 sub is_shelfname_valid { Link Here
80
        ( $self->shelfnumber ? ( "me.shelfnumber" => { '!=', $self->shelfnumber } ) : () ),
88
        ( $self->shelfnumber ? ( "me.shelfnumber" => { '!=', $self->shelfnumber } ) : () ),
81
    };
89
    };
82
90
83
    if ( $self->category == $PRIVATE and defined $self->owner ) {
91
    if ( $self->is_private and defined $self->owner ) {
84
        $conditions->{-or} = {
92
        $conditions->{-or} = {
85
            "virtualshelfshares.borrowernumber" => $self->owner,
93
            "virtualshelfshares.borrowernumber" => $self->owner,
86
            "me.owner" => $self->owner,
94
            "me.owner" => $self->owner,
87
        };
95
        };
88
        $conditions->{category} = $PRIVATE;
96
        $conditions->{category} = $PRIVATE;
89
    }
97
    }
90
    elsif ( $self->category == $PRIVATE and not defined $self->owner ) {
98
    elsif ( $self->is_private and not defined $self->owner ) {
91
        $conditions->{owner} = undef;
99
        $conditions->{owner} = undef;
92
        $conditions->{category} = $PRIVATE;
100
        $conditions->{category} = $PRIVATE;
93
    }
101
    }
Lines 174-179 sub add_biblio { Link Here
174
        }
182
        }
175
    )->count;
183
    )->count;
176
    return if $already_exists;
184
    return if $already_exists;
185
186
    # Check permissions
187
    return unless ( $self->owner == $borrowernumber && $self->allow_change_from_owner ) || $self->allow_change_from_others;
188
177
    my $content = Koha::Virtualshelfcontent->new(
189
    my $content = Koha::Virtualshelfcontent->new(
178
        {
190
        {
179
            shelfnumber => $self->shelfnumber,
191
            shelfnumber => $self->shelfnumber,
Lines 194-231 sub remove_biblios { Link Here
194
    return unless @$biblionumbers;
206
    return unless @$biblionumbers;
195
207
196
    my $number_removed = 0;
208
    my $number_removed = 0;
197
    for my $biblionumber ( @$biblionumbers ) {
209
    if( ( $self->owner == $borrowernumber && $self->allow_change_from_owner )
198
        if ( $self->owner == $borrowernumber or $self->allow_delete_own ) {
210
      || $self->allow_change_from_others ) {
199
            $number_removed += $self->get_contents->search(
211
        $number_removed += $self->get_contents->search({
200
                {
212
            biblionumber => $biblionumbers,
201
                    biblionumber => $biblionumber,
213
        })->delete;
202
                    borrowernumber => $borrowernumber,
203
                }
204
            )->delete;
205
        }
206
        if ( $self->allow_delete_other ) {
207
            $number_removed += $self->get_contents->search(
208
                {
209
                    biblionumber => $biblionumber,
210
                    # FIXME
211
                    # This does not make sense, but it's has been backported from DelFromShelf.
212
                    # Why shouldn't we allow to remove his own contribution if allow_delete_other is on?
213
                    borrowernumber => {
214
                        -or => {
215
                            '!=' => $borrowernumber,
216
                            '=' => undef
217
                        }
218
                    },
219
                }
220
            )->delete;
221
        }
222
    }
214
    }
223
    return $number_removed;
215
    return $number_removed;
224
}
216
}
225
217
226
sub can_be_viewed {
218
sub can_be_viewed {
227
    my ( $self, $borrowernumber ) = @_;
219
    my ( $self, $borrowernumber ) = @_;
228
    return 1 if $self->category == $PUBLIC;
220
    return 1 if $self->is_public;
229
    return 0 unless $borrowernumber;
221
    return 0 unless $borrowernumber;
230
    return 1 if $self->owner == $borrowernumber;
222
    return 1 if $self->owner == $borrowernumber;
231
    return $self->get_shares->search(
223
    return $self->get_shares->search(
Lines 243-249 sub can_be_deleted { Link Here
243
235
244
    my $patron = Koha::Patrons->find( $borrowernumber );
236
    my $patron = Koha::Patrons->find( $borrowernumber );
245
237
246
    return 1 if $self->category == $PUBLIC and C4::Auth::haspermission( $patron->userid, { lists => 'delete_public_lists' } );
238
    return 1 if $self->is_public and C4::Auth::haspermission( $patron->userid, { lists => 'delete_public_lists' } );
247
239
248
    return 0;
240
    return 0;
249
}
241
}
Lines 260-279 sub can_biblios_be_added { Link Here
260
252
261
    return 1
253
    return 1
262
      if $borrowernumber
254
      if $borrowernumber
263
      and ( $self->owner == $borrowernumber
255
      and ( ( $self->owner == $borrowernumber && $self->allow_change_from_owner ) or $self->allow_change_from_others );
264
         or $self->allow_add );
265
    return 0;
256
    return 0;
266
}
257
}
267
258
268
sub can_biblios_be_removed {
259
sub can_biblios_be_removed {
269
    my ( $self, $borrowernumber ) = @_;
260
    my ( $self, $borrowernumber ) = @_;
270
261
    return $self->can_biblios_be_added( $borrowernumber );
271
    return 1
262
    # Same answer since bug 18228
272
      if $borrowernumber
273
      and (  $self->owner == $borrowernumber
274
          or $self->allow_delete_own
275
          or $self->allow_delete_other );
276
    return 0;
277
}
263
}
278
264
279
sub _type {
265
sub _type {
(-)a/Koha/Virtualshelves.pm (-5 / +7 lines)
Lines 90-99 sub get_some_shelves { Link Here
90
    if ( $add_allowed ) {
90
    if ( $add_allowed ) {
91
        push @conditions, {
91
        push @conditions, {
92
            -or =>
92
            -or =>
93
            {
93
            [
94
                "me.allow_add" => 1,
94
                {
95
                "me.owner" => $borrowernumber,
95
                    "me.owner" => $borrowernumber,
96
            }
96
                    "me.allow_change_from_owner" => 1,
97
                },
98
                "me.allow_change_from_others" => 1,
99
            ]
97
        };
100
        };
98
    }
101
    }
99
    if ( $category == 1 ) {
102
    if ( $category == 1 ) {
Lines 135-141 sub get_shelves_containing_record { Link Here
135
                        'me.owner' => $borrowernumber,
138
                        'me.owner' => $borrowernumber,
136
                        -or        => {
139
                        -or        => {
137
                            'virtualshelfshares.borrowernumber' => $borrowernumber,
140
                            'virtualshelfshares.borrowernumber' => $borrowernumber,
138
                            "me.allow_add"                      => 1,
139
                        },
141
                        },
140
                    }
142
                    }
141
                },
143
                },
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-25 / +10 lines)
Lines 299-311 function placeHold () { Link Here
299
    [% ELSE %]
299
    [% ELSE %]
300
        Lists
300
        Lists
301
    [% END %]
301
    [% END %]
302
    [% IF shelf AND shelf.category == PRIVATE %] ›
302
    [% IF shelf AND shelf.is_private %] ›
303
        [% IF op == 'view' OR op == 'edit_form' %]
303
        [% IF op == 'view' OR op == 'edit_form' %]
304
            <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PRIVATE %]">Your lists</a>
304
            <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PRIVATE %]">Your lists</a>
305
        [% ELSE %]
305
        [% ELSE %]
306
            Your lists
306
            Your lists
307
        [% END %]
307
        [% END %]
308
    [% ELSIF shelf AND shelf.category == PUBLIC %] &rsaquo;
308
    [% ELSIF shelf AND shelf.is_public %] &rsaquo;
309
        [% IF op == 'view' %]
309
        [% IF op == 'view' %]
310
            <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PUBLIC %]">Public lists</a>
310
            <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PUBLIC %]">Public lists</a>
311
        [% ELSE %]
311
        [% ELSE %]
Lines 537-548 function placeHold () { Link Here
537
            </select></li>
537
            </select></li>
538
            <li><label for="category">Category: </label>
538
            <li><label for="category">Category: </label>
539
                <select id="category" name="category">
539
                <select id="category" name="category">
540
                [% IF shelf.category == PRIVATE %]
540
                [% IF shelf.is_private %]
541
                    <option value="1" selected="selected">Private</option>
541
                    <option value="1" selected="selected">Private</option>
542
                [% ELSE %]
542
                [% ELSE %]
543
                    <option value="1">Private</option>
543
                    <option value="1">Private</option>
544
                [% END %]
544
                [% END %]
545
                [% IF shelf.category == PUBLIC %]
545
                [% IF shelf.is_public %]
546
                    <option value="2" selected="selected">Public</option>
546
                    <option value="2" selected="selected">Public</option>
547
                [% ELSE %]
547
                [% ELSE %]
548
                    <option value="2">Public</option>
548
                    <option value="2">Public</option>
Lines 550-578 function placeHold () { Link Here
550
                           </select></li>
550
                           </select></li>
551
551
552
            <li>
552
            <li>
553
                <label for="allow_add">Permissions: </label>
553
                <label for="allow_changes_from">Allow changes to contents from: </label>
554
                <select name="allow_add" id="allow_add">
554
                <select name="allow_changes_from" id="allow_changes_from">
555
                    [% IF shelf.allow_add %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
555
                    [% IF !shelf.allow_change_from_owner %]<option value="0">Nobody</option>[% ELSE %]<option value="0" selected="selected">Nobody</option>[% END %]
556
                    [% IF shelf.allow_add %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
556
                    [% IF shelf.allow_change_from_owner && !shelf.allow_change_from_others %]<option value="1" selected="selected">Owner only</option>[% ELSE %]<option value="1">Owner only</option>[% END %]
557
                    [% IF shelf.allow_change_from_owner && shelf.allow_change_from_others %]<option value="2" selected="selected">Anyone seeing this list</option>[% ELSE %]<option value="2">Anyone seeing this list</option>[% END %]
557
                </select>
558
                </select>
558
                &nbsp;<span>anyone else to add entries.</span>
559
            </li>
560
            <li>
561
                <label>&nbsp;</label>
562
                <select name="allow_delete_own" id="allow_delete_own">
563
                    [% IF shelf and not shelf.allow_delete_own %]<option value="0" selected="selected">Do not allow</option>[% ELSE %]<option value="0">Do not allow</option>[% END %]
564
                    [% IF not shelf or shelf.allow_delete_own %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
565
                </select>
566
                &nbsp;<span>anyone to remove their own contributed entries.</span>
567
            </li>
568
            <li>
569
                <label>&nbsp;</label>
570
                <select name="allow_delete_other" id="allow_delete_other">
571
                    [% IF shelf.allow_delete_other %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
572
                    [% IF shelf.allow_delete_other %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
573
                </select>
574
                &nbsp;<span>anyone to remove other contributed entries.</span>
575
            </li>
559
            </li>
560
576
        </ol>
561
        </ol>
577
    </fieldset>
562
    </fieldset>
578
563
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt (-31 / +13 lines)
Lines 12-39 Link Here
12
12
13
[% BLOCK list_permissions %]
13
[% BLOCK list_permissions %]
14
    <li>
14
    <li>
15
        <label for="allow_add">Permissions: </label>
15
        <label for="allow_changes_from">Allow changes to contents from: </label>
16
        <select name="allow_add" id="allow_add">
16
        <select name="allow_changes_from" id="allow_changes_from">
17
            [% IF shelf.allow_add %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
17
            [% IF !shelf.allow_change_from_owner %]<option value="0">Nobody</option>[% ELSE %]<option value="0" selected="selected">Nobody</option>[% END %]
18
            [% IF shelf.allow_add %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
18
            [% IF shelf.allow_change_from_owner && !shelf.allow_change_from_others %]<option value="1" selected="selected">Owner only</option>[% ELSE %]<option value="1">Owner only</option>[% END %]
19
            [% IF shelf.allow_change_from_owner && shelf.allow_change_from_others %]<option value="2" selected="selected">Anyone seeing this list</option>[% ELSE %]<option value="2">Anyone seeing this list</option>[% END %]
19
        </select>
20
        </select>
20
        &nbsp;<span>anyone else to add entries.</span>
21
    </li>
22
    <li>
23
        <label>&nbsp;</label>
24
        <select name="allow_delete_own" id="allow_delete_own">
25
            [% IF shelf and not shelf.allow_delete_own %]<option value="0" selected="selected">Do not allow</option>[% ELSE %]<option value="0">Do not allow</option>[% END %]
26
            [% IF not shelf or shelf.allow_delete_own %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
27
        </select>
28
        &nbsp;<span>anyone to remove their own contributed entries.</span>
29
    </li>
30
    <li>
31
        <label>&nbsp;</label>
32
        <select name="allow_delete_other" id="allow_delete_other">
33
            [% IF shelf.allow_delete_other %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
34
            [% IF shelf.allow_delete_other %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
35
        </select>
36
        &nbsp;<span>anyone to remove other contributed entries.</span>
37
    </li>
21
    </li>
38
[% END %]
22
[% END %]
39
23
Lines 51-63 Link Here
51
            <li>Lists</li>
35
            <li>Lists</li>
52
        [% END %]
36
        [% END %]
53
37
54
        [% IF shelf and shelf.category == PRIVATE %]
38
        [% IF shelf and shelf.is_private %]
55
            [% IF op == 'view' OR op == 'edit_form' %]
39
            [% IF op == 'view' OR op == 'edit_form' %]
56
                <li><span class="divider">&rsaquo;</span> <a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=[% PRIVATE %]">Your lists</a></li>
40
                <li><span class="divider">&rsaquo;</span> <a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=[% PRIVATE %]">Your lists</a></li>
57
            [% ELSE %]
41
            [% ELSE %]
58
                <li><span class="divider">&rsaquo;</span> Your lists</li>
42
                <li><span class="divider">&rsaquo;</span> Your lists</li>
59
            [% END %]
43
            [% END %]
60
        [% ELSIF shelf AND shelf.category == PUBLIC %]
44
        [% ELSIF shelf AND shelf.is_public %]
61
            [% IF op == 'view' %]
45
            [% IF op == 'view' %]
62
                <li><span class="divider">&rsaquo;</span> <a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=[% PUBLIC %]">Public lists</a></li>
46
                <li><span class="divider">&rsaquo;</span> <a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=[% PUBLIC %]">Public lists</a></li>
63
            [% ELSE %]
47
            [% ELSE %]
Lines 586-610 Link Here
586
                                        <li>
570
                                        <li>
587
                                            <label for="category">Category:</label>
571
                                            <label for="category">Category:</label>
588
                                            <select name="category" id="category">
572
                                            <select name="category" id="category">
589
                                                [% IF shelf.category == PRIVATE %]
573
                                                [% IF shelf.is_private %]
590
                                                        <option value="1" selected="selected">Private</option>
574
                                                        <option value="1" selected="selected">Private</option>
591
                                                    [% ELSE %]
575
                                                    [% ELSE %]
592
                                                        <option value="1">Private</option>
576
                                                        <option value="1">Private</option>
593
                                                    [% END %]
577
                                                    [% END %]
594
                                                [% IF shelf.category == PUBLIC %]
578
                                                [% IF shelf.is_public %]
595
                                                    <option value="2" selected="selected">Public</option>
579
                                                    <option value="2" selected="selected">Public</option>
596
                                                [% ELSE %]
580
                                                [% ELSE %]
597
                                                    <option value="2">Public</option>
581
                                                    <option value="2">Public</option>
598
                                                [% END %]
582
                                                [% END %]
599
                                            </select>
583
                                            </select>
600
                                            [% IF shelf.category == PUBLIC AND NOT Koha.Preference('OpacAllowPublicListCreation') %]
584
                                            [% IF shelf.is_public AND NOT Koha.Preference('OpacAllowPublicListCreation') %]
601
                                                <span class="hint alert alert-info">The library has disabled the ability for patrons to create new public lists.  If you make your list private, you will not be able to make it public again.</span>
585
                                                <span class="hint alert alert-info">The library has disabled the ability for patrons to create new public lists.  If you make your list private, you will not be able to make it public again.</span>
602
                                            [% END %]
586
                                            [% END %]
603
                                        </li>
587
                                        </li>
604
                                    [% END %]
588
                                    [% END %]
605
                                    [% IF shelf.category == PUBLIC OR shelf.is_shared %]
589
                                    [% INCLUDE list_permissions %]
606
                                        [% INCLUDE list_permissions %]
607
                                    [% END %]
608
                                </ol>
590
                                </ol>
609
                                [% UNLESS Koha.Preference('OpacAllowPublicListCreation') OR category == PUBLIC %]
591
                                [% UNLESS Koha.Preference('OpacAllowPublicListCreation') OR category == PUBLIC %]
610
                                    <input type="hidden" name="category" value="[% PRIVATE %]" />
592
                                    <input type="hidden" name="category" value="[% PRIVATE %]" />
Lines 671-677 Link Here
671
                                                <td><a href="/cgi-bin/koha/opac-shelves.pl?op=view&amp;shelfnumber=[% s.shelfnumber %]">[% s.shelfname |html %]</a></td>
653
                                                <td><a href="/cgi-bin/koha/opac-shelves.pl?op=view&amp;shelfnumber=[% s.shelfnumber %]">[% s.shelfname |html %]</a></td>
672
                                                <td>[% IF contents.count %][% contents.count %] [% IF contents.count == 1 %]item[% ELSE %]items[% END %][% ELSE %]Empty[% END %]</td>
654
                                                <td>[% IF contents.count %][% contents.count %] [% IF contents.count == 1 %]item[% ELSE %]items[% END %][% ELSE %]Empty[% END %]</td>
673
                                                <td>
655
                                                <td>
674
                                                    [% IF s.category == PRIVATE %]
656
                                                    [% IF s.is_private %]
675
                                                        [% IF s.is_shared %]Shared[% ELSE %]Private[% END %]
657
                                                        [% IF s.is_shared %]Shared[% ELSE %]Private[% END %]
676
                                                    [% ELSE %]
658
                                                    [% ELSE %]
677
                                                        Public
659
                                                        Public
Lines 696-702 Link Here
696
                                                            <input type="submit" class="deleteshelf" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST);" value="Delete" />
678
                                                            <input type="submit" class="deleteshelf" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST);" value="Delete" />
697
                                                        </form>
679
                                                        </form>
698
                                                    [% END %]
680
                                                    [% END %]
699
                                                    [% IF s.category == PRIVATE AND s.can_be_managed( loggedinusernumber ) AND Koha.Preference('OpacAllowSharingPrivateLists') %]
681
                                                    [% IF s.is_private AND s.can_be_managed( loggedinusernumber ) AND Koha.Preference('OpacAllowSharingPrivateLists') %]
700
                                                        <a href="/cgi-bin/koha/opac-shareshelf.pl?op=invite&shelfnumber=[% s.shelfnumber |html %]" class="">Share</a>
682
                                                        <a href="/cgi-bin/koha/opac-shareshelf.pl?op=invite&shelfnumber=[% s.shelfnumber |html %]" class="">Share</a>
701
                                                    [% END %]
683
                                                    [% END %]
702
                                                    [% IF s.is_shared_with( loggedinusernumber ) %]
684
                                                    [% IF s.is_shared_with( loggedinusernumber ) %]
(-)a/opac/opac-addbybiblionumber.pl (-8 / +9 lines)
Lines 107-131 if ($newvirtualshelf) { Link Here
107
        my $private_shelves = Koha::Virtualshelves->search(
107
        my $private_shelves = Koha::Virtualshelves->search(
108
            {   category => 1,
108
            {   category => 1,
109
                owner    => $loggedinuser,
109
                owner    => $loggedinuser,
110
                allow_change_from_owner => 1,
110
            },
111
            },
111
            { order_by => 'shelfname' }
112
            { order_by => 'shelfname' }
112
        );
113
        );
113
        my $shelves_shared_with_me = Koha::Virtualshelves->search(
114
        my $shelves_shared_with_me = Koha::Virtualshelves->search(
114
            {   category                            => 1,
115
            {   category                            => 1,
115
                'virtualshelfshares.borrowernumber' => $loggedinuser,
116
                'virtualshelfshares.borrowernumber' => $loggedinuser,
116
                -or                                 => {
117
                allow_change_from_others            => 1,
117
                    allow_add => 1,
118
                    owner     => $loggedinuser,
119
                }
120
            },
118
            },
121
            { join => 'virtualshelfshares', }
119
            { join => 'virtualshelfshares', }
122
        );
120
        );
123
        my $public_shelves = Koha::Virtualshelves->search(
121
        my $public_shelves = Koha::Virtualshelves->search(
124
            {   category => 2,
122
            {   category => 2,
125
                -or      => {
123
                -or      => [
126
                    allow_add => 1,
124
                    -and => {
127
                    owner     => $loggedinuser,
125
                        allow_change_from_owner => 1,
128
                }
126
                        owner     => $loggedinuser,
127
                    },
128
                    allow_change_from_others => 1,
129
                ],
129
            },
130
            },
130
            { order_by => 'shelfname' }
131
            { order_by => 'shelfname' }
131
        );
132
        );
(-)a/opac/opac-shelves.pl (-7 / +10 lines)
Lines 33-38 use Koha::Biblioitems; Link Here
33
use Koha::Virtualshelves;
33
use Koha::Virtualshelves;
34
use Koha::RecordProcessor;
34
use Koha::RecordProcessor;
35
35
36
use constant ANYONE => 2;
37
36
my $query = new CGI;
38
my $query = new CGI;
37
39
38
my $template_name = $query->param('rss') ? "opac-shelves-rss.tt" : "opac-shelves.tt";
40
my $template_name = $query->param('rss') ? "opac-shelves-rss.tt" : "opac-shelves.tt";
Lines 56-62 my $category = $query->param('category') || 1; Link Here
56
my ( $shelf, $shelfnumber, @messages );
58
my ( $shelf, $shelfnumber, @messages );
57
59
58
if ( $op eq 'add_form' ) {
60
if ( $op eq 'add_form' ) {
59
    # Nothing to do
61
    # Only pass default
62
    $shelf = { allow_change_from_owner => 1 };
60
} elsif ( $op eq 'edit_form' ) {
63
} elsif ( $op eq 'edit_form' ) {
61
    $shelfnumber = $query->param('shelfnumber');
64
    $shelfnumber = $query->param('shelfnumber');
62
    $shelf       = Koha::Virtualshelves->find($shelfnumber);
65
    $shelf       = Koha::Virtualshelves->find($shelfnumber);
Lines 74-87 if ( $op eq 'add_form' ) { Link Here
74
    }
77
    }
75
} elsif ( $op eq 'add' ) {
78
} elsif ( $op eq 'add' ) {
76
    if ( $loggedinuser ) {
79
    if ( $loggedinuser ) {
80
        my $allow_changes_from = $query->param('allow_changes_from');
77
        eval {
81
        eval {
78
            $shelf = Koha::Virtualshelf->new(
82
            $shelf = Koha::Virtualshelf->new(
79
                {   shelfname          => scalar $query->param('shelfname'),
83
                {   shelfname          => scalar $query->param('shelfname'),
80
                    sortfield          => scalar $query->param('sortfield'),
84
                    sortfield          => scalar $query->param('sortfield'),
81
                    category           => scalar $query->param('category') || 1,
85
                    category           => scalar $query->param('category') || 1,
82
                    allow_add          => scalar $query->param('allow_add'),
86
                    allow_change_from_owner => $allow_changes_from > 0,
83
                    allow_delete_own   => scalar $query->param('allow_delete_own'),
87
                    allow_change_from_others => $allow_changes_from == ANYONE,
84
                    allow_delete_other => scalar $query->param('allow_delete_other'),
85
                    owner              => scalar $loggedinuser,
88
                    owner              => scalar $loggedinuser,
86
                }
89
                }
87
            );
90
            );
Lines 110-118 if ( $op eq 'add_form' ) { Link Here
110
        if ( $shelf->can_be_managed( $loggedinuser ) ) {
113
        if ( $shelf->can_be_managed( $loggedinuser ) ) {
111
            $shelf->shelfname( scalar $query->param('shelfname') );
114
            $shelf->shelfname( scalar $query->param('shelfname') );
112
            $shelf->sortfield( $sortfield );
115
            $shelf->sortfield( $sortfield );
113
            $shelf->allow_add( scalar $query->param('allow_add') );
116
            my $allow_changes_from = $query->param('allow_changes_from');
114
            $shelf->allow_delete_own( scalar $query->param('allow_delete_own') );
117
            $shelf->allow_change_from_owner( $allow_changes_from > 0 );
115
            $shelf->allow_delete_other( scalar $query->param('allow_delete_other') );
118
            $shelf->allow_change_from_others( $allow_changes_from == ANYONE );
116
            $shelf->category( scalar $query->param('category') );
119
            $shelf->category( scalar $query->param('category') );
117
            eval { $shelf->store };
120
            eval { $shelf->store };
118
121
(-)a/virtualshelves/addbybiblionumber.pl (-8 / +9 lines)
Lines 152-176 if ($newvirtualshelf) { Link Here
152
    my $private_shelves = Koha::Virtualshelves->search(
152
    my $private_shelves = Koha::Virtualshelves->search(
153
        {   category => 1,
153
        {   category => 1,
154
            owner    => $loggedinuser,
154
            owner    => $loggedinuser,
155
            allow_change_from_owner => 1,
155
        },
156
        },
156
        { order_by => 'shelfname' }
157
        { order_by => 'shelfname' }
157
    );
158
    );
158
    my $shelves_shared_with_me = Koha::Virtualshelves->search(
159
    my $shelves_shared_with_me = Koha::Virtualshelves->search(
159
        {   category                            => 1,
160
        {   category                            => 1,
160
            'virtualshelfshares.borrowernumber' => $loggedinuser,
161
            'virtualshelfshares.borrowernumber' => $loggedinuser,
161
            -or                                 => {
162
            allow_change_from_others            => 1,
162
                allow_add => 1,
163
                owner     => $loggedinuser,
164
            }
165
        },
163
        },
166
        { join => 'virtualshelfshares', }
164
        { join => 'virtualshelfshares', }
167
    );
165
    );
168
    my $public_shelves = Koha::Virtualshelves->search(
166
    my $public_shelves = Koha::Virtualshelves->search(
169
        {   category => 2,
167
        {   category => 2,
170
            -or      => {
168
            -or      => [
171
                allow_add => 1,
169
                -and => {
172
                owner     => $loggedinuser,
170
                    allow_change_from_owner => 1,
173
            }
171
                    owner     => $loggedinuser,
172
                },
173
                allow_change_from_others => 1,
174
            ],
174
        },
175
        },
175
        { order_by => 'shelfname' }
176
        { order_by => 'shelfname' }
176
    );
177
    );
(-)a/virtualshelves/shelves.pl (-8 / +10 lines)
Lines 32-37 use Koha::Biblioitems; Link Here
32
use Koha::CsvProfiles;
32
use Koha::CsvProfiles;
33
use Koha::Virtualshelves;
33
use Koha::Virtualshelves;
34
34
35
use constant ANYONE => 2;
36
35
my $query = new CGI;
37
my $query = new CGI;
36
38
37
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 49-55 my $category = $query->param('category') || 1; Link Here
49
my ( $shelf, $shelfnumber, @messages );
51
my ( $shelf, $shelfnumber, @messages );
50
52
51
if ( $op eq 'add_form' ) {
53
if ( $op eq 'add_form' ) {
52
    # Nothing to do
54
    # Only pass default
55
    $shelf = { allow_change_from_owner => 1 };
53
} elsif ( $op eq 'edit_form' ) {
56
} elsif ( $op eq 'edit_form' ) {
54
    $shelfnumber = $query->param('shelfnumber');
57
    $shelfnumber = $query->param('shelfnumber');
55
    $shelf       = Koha::Virtualshelves->find($shelfnumber);
58
    $shelf       = Koha::Virtualshelves->find($shelfnumber);
Lines 66-79 if ( $op eq 'add_form' ) { Link Here
66
        push @messages, { type => 'alert', code => 'does_not_exist' };
69
        push @messages, { type => 'alert', code => 'does_not_exist' };
67
    }
70
    }
68
} elsif ( $op eq 'add' ) {
71
} elsif ( $op eq 'add' ) {
72
    my $allow_changes_from = $query->param('allow_changes_from');
69
    eval {
73
    eval {
70
        $shelf = Koha::Virtualshelf->new(
74
        $shelf = Koha::Virtualshelf->new(
71
            {   shelfname          => scalar $query->param('shelfname'),
75
            {   shelfname          => scalar $query->param('shelfname'),
72
                sortfield          => scalar $query->param('sortfield'),
76
                sortfield          => scalar $query->param('sortfield'),
73
                category           => scalar $query->param('category'),
77
                category           => scalar $query->param('category'),
74
                allow_add          => scalar $query->param('allow_add'),
78
                allow_change_from_owner => $allow_changes_from > 0,
75
                allow_delete_own   => scalar $query->param('allow_delete_own'),
79
                allow_change_from_others => $allow_changes_from == ANYONE,
76
                allow_delete_other => scalar $query->param('allow_delete_other'),
77
                owner              => scalar $query->param('owner'),
80
                owner              => scalar $query->param('owner'),
78
            }
81
            }
79
        );
82
        );
Lines 100-108 if ( $op eq 'add_form' ) { Link Here
100
        if ( $shelf->can_be_managed( $loggedinuser ) ) {
103
        if ( $shelf->can_be_managed( $loggedinuser ) ) {
101
            $shelf->shelfname( scalar $query->param('shelfname') );
104
            $shelf->shelfname( scalar $query->param('shelfname') );
102
            $shelf->sortfield( $sortfield );
105
            $shelf->sortfield( $sortfield );
103
            $shelf->allow_add( scalar $query->param('allow_add') );
106
            my $allow_changes_from = $query->param('allow_changes_from');
104
            $shelf->allow_delete_own( scalar $query->param('allow_delete_own') );
107
            $shelf->allow_change_from_owner( $allow_changes_from > 0 );
105
            $shelf->allow_delete_other( scalar $query->param('allow_delete_other') );
108
            $shelf->allow_change_from_others( $allow_changes_from == ANYONE );
106
            $shelf->category( scalar $query->param('category') );
109
            $shelf->category( scalar $query->param('category') );
107
            eval { $shelf->store };
110
            eval { $shelf->store };
108
111
109
- 

Return to bug 18228