Bug 30955: Sends notice to new owner at transfer

This patch adds a new notice, TRANSFER_OWNERSHIP, under a new module,
Lists. When a list is transferred to a new owner, this notice is
triggered, containing a short paragraph detailing the list name.

TO TEST:
a)  log in as a koha superlibrarian
b)  go to the lists module, create a public list, and make a note of the
    title used
c)  on the lists module, transfer the list to some other user, and make
    a note of the user used
d)  go to the patron notices page for the user in step c
e)  ensure that a notice has been generated
    1)  check the contents of the notice, it should contain
      - the new owner's name
      - the list's title
      - the old owner's name & (if set) email
f)  under tools > notices, modify the notice for TRANSFER_OWNERSHIP
g)  repeat steps c-e
    1)  ensure the modifications you've made are now visible in the notice

Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jake Deery 2024-07-10 16:18:26 +01:00 committed by Katrin Fischer
parent 8c51b374d6
commit 85ba989f82
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
5 changed files with 86 additions and 3 deletions

View File

@ -360,8 +360,43 @@ sub transfer_ownership {
Koha::Exceptions::MissingParameter->throw("Mandatory parameter 'patron' missing")
unless $patron_id;
## before we change the owner, collect some details
my $old_owner = Koha::Patrons->find( $self->owner );
my $new_owner = Koha::Patrons->find($patron_id);
my $library = $new_owner->library->unblessed;
## first we change the owner
$self->remove_share($patron_id) if $self->is_private;
return $self->set( { owner => $patron_id } )->store;
$self->set( { owner => $patron_id } )->store;
## now we message the new owner
my $letter = C4::Letters::GetPreparedLetter(
module => 'lists',
letter_code => 'TRANSFER_OWNERSHIP',
branchcode => $library->{branchcode},
lang => $new_owner->lang || 'default',
objects => {
old_owner => $old_owner,
new_owner => $new_owner,
shelf => $self,
},
tables => {
'branches' => $library->{branchcode},
},
message_transport_type => 'email',
);
if ($letter) {
my $message_id = C4::Letters::EnqueueLetter(
{
letter => $letter,
borrowernumber => $patron_id,
message_transport_type => 'email',
}
) or warn "can't enqueue letter $letter";
}
return $self;
}
=head2 Internal methods

View File

@ -1329,6 +1329,22 @@ tables:
- "[% branch.branchillemail %]"
- "[% branch.branchemail %]"
- module: lists
code: TRANSFER_OWNERSHIP
branchcode: ""
name: "Transfer ownership"
is_html: 1
title: "A list has been transferred to you"
message_transport_type: email
lang: default
content:
- "Dear [%- INCLUDE 'patron-title.inc' patron => new_owner -%],<br>"
- "<br>"
- "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>"
- "<br>"
- "Thank you<br>"
- "<br>"
- module: members
code: DISCHARGE
branchcode: ""

View File

@ -194,6 +194,7 @@
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=claimissues">Claim serial issue</a></li>
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=reserves">Holds</a></li>
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=ill">Interlibrary loans</a></li>
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=lists">Lists</a></li>
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=orderacquisition">Order acquisition</a></li>
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=members">Patrons</a></li>
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=patron_slip">Patrons (custom slip)</a></li>
@ -257,6 +258,7 @@
[% CASE 'claimissues' %]<span>Claim serial issue</span>
[% CASE 'reserves' %]<span>Holds</span>
[% CASE 'ill' %]<span>Interlibrary loans</span>
[% CASE 'lists' %]<span>Lists</span>
[% CASE 'members' %]<span>Patrons</span>
[% CASE 'patron_slip' %]<span>Patrons (custom slip)</span>
[% CASE 'add_message' %]<span>Patrons (custom message)</span>
@ -420,6 +422,11 @@
[% IF ( module == "ill" ) %]
<option value="ill" selected="selected">Interlibrary loans</option>
[% ELSE %]
[% IF ( module == "lists" ) %]
<option value="lists" selected="selected">Lists</option>
[% ELSE %]
<option value="lists">Lists</option>
[% END %]
<option value="ill">Interlibrary loans</option>
[% END %]
[% IF ( module == "members" ) %]

View File

@ -30,7 +30,7 @@ my $builder = t::lib::TestBuilder->new;
subtest 'transfer_ownership() tests' => sub {
plan tests => 8;
plan tests => 13;
$schema->storage->txn_begin;
@ -95,5 +95,30 @@ subtest 'transfer_ownership() tests' => sub {
is( $private_list_shares->count, 1, 'Count is correct' );
is( $private_list_shares->next->borrowernumber, $patron_3->id, "Private lists get the share for the new owner removed" );
my %params;
my $mocked_letters = Test::MockModule->new('C4::Letters');
$mocked_letters->mock(
'GetPreparedLetter',
sub {
%params = @_;
return 1;
}
);
$mocked_letters->mock(
'EnqueueLetter',
sub {
return 1;
}
);
$public_list->transfer_ownership( $patron_1->id );
$public_list->discard_changes;
is( $params{module}, "lists", "Enqueued letter with module lists correctly" );
is( $params{letter_code}, "TRANSFER_OWNERSHIP", "Enqueued letter with code TRANSFER_OWNERSHIP correctly" );
is( $params{objects}->{old_owner}->borrowernumber, $patron_2->borrowernumber, "old_owner passed to enqueue letter correctly" );
is( $params{objects}->{new_owner}->borrowernumber, $patron_1->borrowernumber, "new_owner passed to enqueue letter correctly" );
is( $params{objects}->{shelf}->shelfnumber, $public_list->shelfnumber, "shelf passed to enqueue letter correctly" );
$schema->storage->txn_rollback;
};

View File

@ -266,7 +266,7 @@ if ( $op eq 'add_form' ) {
push @messages, { type => 'error', code => $error_code };
$op = 'list';
} else {
$shelf->owner($new_owner)->store;
$shelf->transfer_ownership($new_owner);
$op = 'list';
}
}