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

(-)a/Koha/Virtualshelf.pm (-1 / +36 lines)
Lines 360-367 sub transfer_ownership { Link Here
360
    Koha::Exceptions::MissingParameter->throw("Mandatory parameter 'patron' missing")
360
    Koha::Exceptions::MissingParameter->throw("Mandatory parameter 'patron' missing")
361
        unless $patron_id;
361
        unless $patron_id;
362
362
363
    ## before we change the owner, collect some details
364
    my $old_owner = Koha::Patrons->find( $self->owner );
365
    my $new_owner = Koha::Patrons->find($patron_id);
366
    my $library   = $new_owner->library->unblessed;
367
368
    ## first we change the owner
363
    $self->remove_share($patron_id) if $self->is_private;
369
    $self->remove_share($patron_id) if $self->is_private;
364
    return $self->set( { owner => $patron_id } )->store;
370
    $self->set( { owner => $patron_id } )->store;
371
372
    ## now we message the new owner
373
    my $letter = C4::Letters::GetPreparedLetter(
374
        module      => 'lists',
375
        letter_code => 'TRANSFER_OWNERSHIP',
376
        branchcode  => $library->{branchcode},
377
        lang        => $new_owner->lang || 'default',
378
        objects     => {
379
            old_owner => $old_owner,
380
            new_owner => $new_owner,
381
            shelf     => $self,
382
        },
383
        tables => {
384
            'branches' => $library->{branchcode},
385
        },
386
        message_transport_type => 'email',
387
    );
388
389
    if ($letter) {
390
        my $message_id = C4::Letters::EnqueueLetter(
391
            {
392
                letter                 => $letter,
393
                borrowernumber         => $patron_id,
394
                message_transport_type => 'email',
395
            }
396
        ) or warn "can't enqueue letter $letter";
397
    }
398
399
    return $self;
365
}
400
}
366
401
367
=head2 Internal methods
402
=head2 Internal methods
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+16 lines)
Lines 1305-1310 tables: Link Here
1305
            - "[% branch.branchillemail %]"
1305
            - "[% branch.branchillemail %]"
1306
            - "[% branch.branchemail %]"
1306
            - "[% branch.branchemail %]"
1307
1307
1308
        - module: lists
1309
          code: TRANSFER_OWNERSHIP
1310
          branchcode: ""
1311
          name: "Transfer ownership"
1312
          is_html: 1
1313
          title: "A list has been transferred to you"
1314
          message_transport_type: email
1315
          lang: default
1316
          content:
1317
            - "Dear [%- INCLUDE 'patron-title.inc' patron => new_owner -%],<br>"
1318
            - "<br>"
1319
            - "A public list, titled <em>[% shelf.shelfname | html %]</em>, has been transferred to you[% IF ( old_owner ) %] by [%- INCLUDE 'patron-title.inc' patron => old_owner%][% IF ( old_owner.email ) %] <em>([% old_owner.email | html %])</em>[% END %][% END %].<br>"
1320
            - "<br>"
1321
            - "Thank you<br>"
1322
            - "<br>"
1323
1308
        - module: members
1324
        - module: members
1309
          code: DISCHARGE
1325
          code: DISCHARGE
1310
          branchcode: ""
1326
          branchcode: ""
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt (+7 lines)
Lines 194-199 Link Here
194
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=claimissues">Claim serial issue</a></li>
194
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=claimissues">Claim serial issue</a></li>
195
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=reserves">Holds</a></li>
195
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=reserves">Holds</a></li>
196
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=ill">Interlibrary loans</a></li>
196
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=ill">Interlibrary loans</a></li>
197
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=lists">Lists</a></li>
197
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=orderacquisition">Order acquisition</a></li>
198
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=orderacquisition">Order acquisition</a></li>
198
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=members">Patrons</a></li>
199
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=members">Patrons</a></li>
199
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=patron_slip">Patrons (custom slip)</a></li>
200
                                <li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=patron_slip">Patrons (custom slip)</a></li>
Lines 257-262 Link Here
257
                                                    [% CASE 'claimissues' %]<span>Claim serial issue</span>
258
                                                    [% CASE 'claimissues' %]<span>Claim serial issue</span>
258
                                                    [% CASE 'reserves' %]<span>Holds</span>
259
                                                    [% CASE 'reserves' %]<span>Holds</span>
259
                                                    [% CASE 'ill' %]<span>Interlibrary loans</span>
260
                                                    [% CASE 'ill' %]<span>Interlibrary loans</span>
261
                                                    [% CASE 'lists' %]<span>Lists</span>
260
                                                    [% CASE 'members' %]<span>Patrons</span>
262
                                                    [% CASE 'members' %]<span>Patrons</span>
261
                                                    [% CASE 'patron_slip' %]<span>Patrons (custom slip)</span>
263
                                                    [% CASE 'patron_slip' %]<span>Patrons (custom slip)</span>
262
                                                    [% CASE 'add_message' %]<span>Patrons (custom message)</span>
264
                                                    [% CASE 'add_message' %]<span>Patrons (custom message)</span>
Lines 420-425 Link Here
420
                                        [% IF ( module == "ill" ) %]
422
                                        [% IF ( module == "ill" ) %]
421
                                        <option value="ill" selected="selected">Interlibrary loans</option>
423
                                        <option value="ill" selected="selected">Interlibrary loans</option>
422
                                        [% ELSE %]
424
                                        [% ELSE %]
425
                                        [% IF ( module == "lists" ) %]
426
                                        <option value="lists" selected="selected">Lists</option>
427
                                        [% ELSE %]
428
                                        <option value="lists">Lists</option>
429
                                        [% END %]
423
                                        <option value="ill">Interlibrary loans</option>
430
                                        <option value="ill">Interlibrary loans</option>
424
                                        [% END %]
431
                                        [% END %]
425
                                        [% IF ( module == "members" ) %]
432
                                        [% IF ( module == "members" ) %]
(-)a/t/db_dependent/Koha/Virtualshelf.t (-1 / +26 lines)
Lines 30-36 my $builder = t::lib::TestBuilder->new; Link Here
30
30
31
subtest 'transfer_ownership() tests' => sub {
31
subtest 'transfer_ownership() tests' => sub {
32
32
33
    plan tests => 8;
33
    plan tests => 13;
34
34
35
    $schema->storage->txn_begin;
35
    $schema->storage->txn_begin;
36
36
Lines 95-99 subtest 'transfer_ownership() tests' => sub { Link Here
95
    is( $private_list_shares->count, 1, 'Count is correct' );
95
    is( $private_list_shares->count, 1, 'Count is correct' );
96
    is( $private_list_shares->next->borrowernumber, $patron_3->id, "Private lists get the share for the new owner removed" );
96
    is( $private_list_shares->next->borrowernumber, $patron_3->id, "Private lists get the share for the new owner removed" );
97
97
98
    my %params;
99
    my $mocked_letters = Test::MockModule->new('C4::Letters');
100
    $mocked_letters->mock(
101
        'GetPreparedLetter',
102
        sub {
103
            %params = @_;
104
            return 1;
105
        }
106
    );
107
    $mocked_letters->mock(
108
        'EnqueueLetter',
109
        sub {
110
            return 1;
111
        }
112
    );
113
114
    $public_list->transfer_ownership( $patron_1->id );
115
    $public_list->discard_changes;
116
117
    is( $params{module}, "lists", "Enqueued letter with module lists correctly" );
118
    is( $params{letter_code}, "TRANSFER_OWNERSHIP", "Enqueued letter with code TRANSFER_OWNERSHIP correctly" );
119
    is( $params{objects}->{old_owner}->borrowernumber, $patron_2->borrowernumber, "old_owner passed to enqueue letter correctly" );
120
    is( $params{objects}->{new_owner}->borrowernumber, $patron_1->borrowernumber, "new_owner passed to enqueue letter correctly" );
121
    is( $params{objects}->{shelf}->shelfnumber, $public_list->shelfnumber, "shelf passed to enqueue letter correctly" );
122
98
    $schema->storage->txn_rollback;
123
    $schema->storage->txn_rollback;
99
};
124
};
(-)a/virtualshelves/shelves.pl (-2 / +1 lines)
Lines 266-272 if ( $op eq 'add_form' ) { Link Here
266
        push @messages, { type => 'error', code => $error_code };
266
        push @messages, { type => 'error', code => $error_code };
267
        $op = 'list';
267
        $op = 'list';
268
    } else {
268
    } else {
269
        $shelf->owner($new_owner)->store;
269
        $shelf->transfer_ownership($new_owner);
270
        $op = 'list';
270
        $op = 'list';
271
    }
271
    }
272
}
272
}
273
- 

Return to bug 30955