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

(-)a/Koha/Virtualshelf.pm (-4 / +39 lines)
Lines 346-356 This method transfers the list ownership to the passed I<$patron_id>. Link Here
346
sub transfer_ownership {
346
sub transfer_ownership {
347
    my ( $self, $patron_id ) = @_;
347
    my ( $self, $patron_id ) = @_;
348
348
349
    Koha::Exceptions::MissingParameter->throw( "Mandatory parameter 'patron' missing" )
349
    Koha::Exceptions::MissingParameter->throw("Mandatory parameter 'patron' missing")
350
      unless $patron_id;
350
        unless $patron_id;
351
352
    ## before we change the owner, collect some details
353
    my $old_owner = Koha::Patrons->find( $self->owner );
354
    my $new_owner = Koha::Patrons->find($patron_id);
355
    my $library   = $new_owner->library->unblessed;
356
357
    ## first we change the owner
358
    $self->remove_share($patron_id) if $self->is_private;
359
    $self->set( { owner => $patron_id } )->store;
360
361
    ## now we message the new owner
362
    my $letter = C4::Letters::GetPreparedLetter(
363
        module      => 'lists',
364
        letter_code => 'TRANSFER_OWNERSHIP',
365
        branchcode  => $library->{branchcode},
366
        lang        => $new_owner->lang || 'default',
367
        objects     => {
368
            old_owner => $old_owner,
369
            new_owner => $new_owner,
370
            shelf     => $self,
371
        },
372
        tables => {
373
            'branches' => $library->{branchcode},
374
        },
375
        message_transport_type => 'email',
376
    );
377
378
    if ($letter) {
379
        my $message_id = C4::Letters::EnqueueLetter(
380
            {
381
                letter                 => $letter,
382
                borrowernumber         => $patron_id,
383
                message_transport_type => 'email',
384
            }
385
        ) or warn "can't enqueue letter $letter";
386
    }
351
387
352
    $self->remove_share( $patron_id ) if $self->is_private;
388
    return $self;
353
    return $self->set({ owner => $patron_id })->store;
354
}
389
}
355
390
356
=head2 Internal methods
391
=head2 Internal methods
(-)a/installer/data/mysql/atomicupdate/bug_30955-add-new-notice.pl (+16 lines)
Line 0 Link Here
1
	use Modern::Perl;
2
3
 return {
4
    bug_number  => "30955",
5
    description => "Send a notice to new owner when transferring shared list",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
         $dbh->do(
11
            q{ INSERT IGNORE INTO letter (module, code, name, is_html, title, content, message_transport_type) VALUES ('lists', 'TRANSFER_OWNERSHIP', 'Transfer ownership', 1, 'A list has been transferred to you', "Dear [%- INCLUDE 'patron-title.inc' patron => new_owner -%],<br>\r\n<br>\r\nA 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>\r\n<br>\r\nThank you<br>\r\n<br>\r\n", 'email') }
12
        );
13
        say $out "Added notice TRANSFER_OWNERSHIP";
14
15
     },
16
};
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+16 lines)
Lines 1264-1269 tables: Link Here
1264
            - "[% branch.branchillemail %]"
1264
            - "[% branch.branchillemail %]"
1265
            - "[% branch.branchemail %]"
1265
            - "[% branch.branchemail %]"
1266
1266
1267
        - module: lists
1268
          code: TRANSFER_OWNERSHIP
1269
          branchcode: ""
1270
          name: "Transfer ownership"
1271
          is_html: 1
1272
          title: "A list has been transferred to you"
1273
          message_transport_type: email
1274
          lang: default
1275
          content:
1276
            - "Dear [%- INCLUDE 'patron-title.inc' patron => new_owner -%],<br>"
1277
            - "<br>"
1278
            - "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>"
1279
            - "<br>"
1280
            - "Thank you<br>"
1281
            - "<br>"
1282
1267
        - module: members
1283
        - module: members
1268
          code: DISCHARGE
1284
          code: DISCHARGE
1269
          branchcode: ""
1285
          branchcode: ""
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt (+7 lines)
Lines 194-199 Link Here
194
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=claimissues">Claim serial issue</a></li>
194
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=claimissues">Claim serial issue</a></li>
195
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=reserves">Holds</a></li>
195
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=reserves">Holds</a></li>
196
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=ill">Interlibrary loans</a></li>
196
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=ill">Interlibrary loans</a></li>
197
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=lists">Lists</a></li>
197
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=orderacquisition">Order acquisition</a></li>
198
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=orderacquisition">Order acquisition</a></li>
198
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=members">Patrons</a></li>
199
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=members">Patrons</a></li>
199
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=patron_slip">Patrons (custom slip)</a></li>
200
                                <li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=patron_slip">Patrons (custom slip)</a></li>
Lines 256-261 Link Here
256
                                                    [% CASE 'claimissues' %]<span>Claim serial issue</span>
257
                                                    [% CASE 'claimissues' %]<span>Claim serial issue</span>
257
                                                    [% CASE 'reserves' %]<span>Holds</span>
258
                                                    [% CASE 'reserves' %]<span>Holds</span>
258
                                                    [% CASE 'ill' %]<span>Interlibrary loans</span>
259
                                                    [% CASE 'ill' %]<span>Interlibrary loans</span>
260
                                                    [% CASE 'lists' %]<span>Lists</span>
259
                                                    [% CASE 'members' %]<span>Patrons</span>
261
                                                    [% CASE 'members' %]<span>Patrons</span>
260
                                                    [% CASE 'patron_slip' %]<span>Patrons (custom slip)</span>
262
                                                    [% CASE 'patron_slip' %]<span>Patrons (custom slip)</span>
261
                                                    [% CASE 'add_message' %]<span>Patrons (custom message)</span>
263
                                                    [% 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 260-266 if ( $op eq 'add_form' ) { Link Here
260
        push @messages, { type => 'error', code => $error_code };
260
        push @messages, { type => 'error', code => $error_code };
261
        $op = 'list';
261
        $op = 'list';
262
    } else {
262
    } else {
263
        $shelf->owner($new_owner)->store;
263
        $shelf->transfer_ownership($new_owner);
264
        $op = 'list';
264
        $op = 'list';
265
    }
265
    }
266
}
266
}
267
- 

Return to bug 30955