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

(-)a/Koha/Virtualshelf.pm (-8 / +7 lines)
Lines 361-369 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 );
365
    my $new_owner = Koha::Patrons->find($patron_id);
365
    my $new_owner  = Koha::Patrons->find($patron_id);
366
    my $library   = $new_owner->library->unblessed;
366
    my $userenv    = C4::Context->userenv;
367
    my $branchcode = $userenv->{branch};
367
368
368
    ## first we change the owner
369
    ## first we change the owner
369
    $self->remove_share($patron_id) if $self->is_private;
370
    $self->remove_share($patron_id) if $self->is_private;
Lines 373-388 sub transfer_ownership { Link Here
373
    my $letter = C4::Letters::GetPreparedLetter(
374
    my $letter = C4::Letters::GetPreparedLetter(
374
        module      => 'lists',
375
        module      => 'lists',
375
        letter_code => 'TRANSFER_OWNERSHIP',
376
        letter_code => 'TRANSFER_OWNERSHIP',
376
        branchcode  => $library->{branchcode},
377
        branchcode  => $branchcode,
377
        lang        => $new_owner->lang || 'default',
378
        lang        => $new_owner->lang || 'default',
378
        objects     => {
379
        objects     => {
379
            old_owner => $old_owner,
380
            old_owner => $old_owner,
380
            new_owner => $new_owner,
381
            owner     => $new_owner,
381
            shelf     => $self,
382
            shelf     => $self,
382
        },
383
        },
383
        tables => {
384
        want_librarian         => 1,
384
            'branches' => $library->{branchcode},
385
        },
386
        message_transport_type => 'email',
385
        message_transport_type => 'email',
387
    );
386
    );
388
387
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (-2 / +3 lines)
Lines 1314-1323 tables: Link Here
1314
          message_transport_type: email
1314
          message_transport_type: email
1315
          lang: default
1315
          lang: default
1316
          content:
1316
          content:
1317
            - "Dear [%- INCLUDE 'patron-title.inc' patron => new_owner -%],<br>"
1317
            - "Dear [%- INCLUDE 'patron-title.inc' patron => owner -%],<br>"
1318
            - "<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>"
1319
            - "A public list, titled <em>[% shelf.shelfname | html %]</em>, has been transferred to you[% IF ( librarian ) %] by [%- INCLUDE 'patron-title.inc' patron => librarian %][% END %].<br>"
1320
            - "<br>"
1320
            - "<br>"
1321
            - "[% IF old_owner %]The list was previously owned by [%- INCLUDE 'patron-title.inc' patron => old_owner -%].<br><br>[% END %]"
1321
            - "Thank you<br>"
1322
            - "Thank you<br>"
1322
            - "<br>"
1323
            - "<br>"
1323
1324
(-)a/t/db_dependent/Koha/Virtualshelf.t (-13 / +20 lines)
Lines 34-42 subtest 'transfer_ownership() tests' => sub { Link Here
34
34
35
    $schema->storage->txn_begin;
35
    $schema->storage->txn_begin;
36
36
37
    my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' });
37
    my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } );
38
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
38
    my $patron_2 = $builder->build_object( { class => 'Koha::Patrons' } );
39
    my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' });
39
    my $patron_3 = $builder->build_object( { class => 'Koha::Patrons' } );
40
40
41
    my $public_list = $builder->build_object(
41
    my $public_list = $builder->build_object(
42
        {
42
        {
Lines 52-60 subtest 'transfer_ownership() tests' => sub { Link Here
52
        }
52
        }
53
    );
53
    );
54
54
55
    throws_ok
55
    throws_ok { $public_list->transfer_ownership }
56
        { $public_list->transfer_ownership }
56
    'Koha::Exceptions::MissingParameter',
57
        'Koha::Exceptions::MissingParameter',
58
        'Exception thrown if missing parameter';
57
        'Exception thrown if missing parameter';
59
58
60
    like( "$@", qr/Mandatory parameter 'patron' missing/, 'Exception string as expected' );
59
    like( "$@", qr/Mandatory parameter 'patron' missing/, 'Exception string as expected' );
Lines 63-69 subtest 'transfer_ownership() tests' => sub { Link Here
63
    $builder->build_object(
62
    $builder->build_object(
64
        {
63
        {
65
            class => 'Koha::Virtualshelfshares',
64
            class => 'Koha::Virtualshelfshares',
66
            value => { shelfnumber => $public_list->id,  invitekey => undef, borrowernumber => $patron_2->id }
65
            value => { shelfnumber => $public_list->id, invitekey => undef, borrowernumber => $patron_2->id }
67
        }
66
        }
68
    );
67
    );
69
    $builder->build_object(
68
    $builder->build_object(
Lines 84-90 subtest 'transfer_ownership() tests' => sub { Link Here
84
83
85
    is( $public_list->owner, $patron_2->id, 'Owner changed correctly' );
84
    is( $public_list->owner, $patron_2->id, 'Owner changed correctly' );
86
    my $public_list_shares = $public_list->get_shares;
85
    my $public_list_shares = $public_list->get_shares;
87
    is( $public_list_shares->count, 1, 'Count is correct' );
86
    is( $public_list_shares->count,                1,             'Count is correct' );
88
    is( $public_list_shares->next->borrowernumber, $patron_2->id, "Public lists don't get the share removed" );
87
    is( $public_list_shares->next->borrowernumber, $patron_2->id, "Public lists don't get the share removed" );
89
88
90
    $private_list->transfer_ownership( $patron_2->id );
89
    $private_list->transfer_ownership( $patron_2->id );
Lines 93-99 subtest 'transfer_ownership() tests' => sub { Link Here
93
    is( $private_list->owner, $patron_2->id );
92
    is( $private_list->owner, $patron_2->id );
94
    my $private_list_shares = $private_list->get_shares;
93
    my $private_list_shares = $private_list->get_shares;
95
    is( $private_list_shares->count, 1, 'Count is correct' );
94
    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" );
95
    is(
96
        $private_list_shares->next->borrowernumber, $patron_3->id,
97
        "Private lists get the share for the new owner removed"
98
    );
97
99
98
    my %params;
100
    my %params;
99
    my $mocked_letters = Test::MockModule->new('C4::Letters');
101
    my $mocked_letters = Test::MockModule->new('C4::Letters');
Lines 114-123 subtest 'transfer_ownership() tests' => sub { Link Here
114
    $public_list->transfer_ownership( $patron_1->id );
116
    $public_list->transfer_ownership( $patron_1->id );
115
    $public_list->discard_changes;
117
    $public_list->discard_changes;
116
118
117
    is( $params{module}, "lists", "Enqueued letter with module lists correctly" );
119
    is( $params{module},      "lists",              "Enqueued letter with module lists correctly" );
118
    is( $params{letter_code}, "TRANSFER_OWNERSHIP", "Enqueued letter with code TRANSFER_OWNERSHIP correctly" );
120
    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" );
121
    is(
120
    is( $params{objects}->{new_owner}->borrowernumber, $patron_1->borrowernumber, "new_owner passed to enqueue letter correctly" );
122
        $params{objects}->{old_owner}->borrowernumber, $patron_2->borrowernumber,
123
        "old_owner passed to enqueue letter correctly"
124
    );
125
    is(
126
        $params{objects}->{owner}->borrowernumber, $patron_1->borrowernumber,
127
        "owner passed to enqueue letter correctly"
128
    );
121
    is( $params{objects}->{shelf}->shelfnumber, $public_list->shelfnumber, "shelf passed to enqueue letter correctly" );
129
    is( $params{objects}->{shelf}->shelfnumber, $public_list->shelfnumber, "shelf passed to enqueue letter correctly" );
122
130
123
    $schema->storage->txn_rollback;
131
    $schema->storage->txn_rollback;
124
- 

Return to bug 30955