Bug 5770: (QA follow-up) Allow feature to be disable

This patch adds 'None' to the available options for the feature so it
may be disabled entirely (and sets that as default)

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2019-05-01 14:14:38 +01:00 committed by Nick Clemens
parent f792bf5c93
commit a404b314b2
5 changed files with 45 additions and 30 deletions

View File

@ -456,33 +456,38 @@ sub NewSuggestion {
my $rs = Koha::Database->new->schema->resultset('Suggestion');
my $new_id = $rs->create($suggestion)->id;
my $full_suggestion = GetSuggestion( $new_id );
if (
my $letter = C4::Letters::GetPreparedLetter(
module => 'suggestions',
letter_code => 'NEW_SUGGESTION',
tables => {
'branches' => $full_suggestion->{branchcode},
'borrowers' => $full_suggestion->{suggestedby},
'suggestions' => $full_suggestion,
},
)
){
my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions");
my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions");
if ($emailpurchasesuggestions) {
my $full_suggestion = GetSuggestion( $new_id );
if (
my $letter = C4::Letters::GetPreparedLetter(
module => 'suggestions',
letter_code => 'NEW_SUGGESTION',
tables => {
'branches' => $full_suggestion->{branchcode},
'borrowers' => $full_suggestion->{suggestedby},
'suggestions' => $full_suggestion,
},
)
){
my $toaddress = ( $emailpurchasesuggestions eq "BranchEmailAddress" )
? ( Koha::Libraries->find($full_suggestion->{branchcode})->branchemail || C4::Context->preference('KohaAdminEmailAddress') )
: C4::Context->preference( $emailpurchasesuggestions ) ;
my $toaddress =
( $emailpurchasesuggestions eq "BranchEmailAddress" )
? ( Koha::Libraries->find( $full_suggestion->{branchcode} )
->branchemail
|| C4::Context->preference('KohaAdminEmailAddress') )
: C4::Context->preference($emailpurchasesuggestions);
C4::Letters::EnqueueLetter(
{
letter => $letter,
borrowernumber => $full_suggestion->{suggestedby},
suggestionid => $full_suggestion->{suggestionid},
to_address => $toaddress,
message_transport_type => 'email',
}
) or warn "can't enqueue letter $letter";
C4::Letters::EnqueueLetter(
{
letter => $letter,
borrowernumber => $full_suggestion->{suggestedby},
suggestionid => $full_suggestion->{suggestionid},
to_address => $toaddress,
message_transport_type => 'email',
}
) or warn "can't enqueue letter $letter";
}
}
return $new_id;

View File

@ -2,7 +2,7 @@ $DBversion = '18.12.00.XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
$dbh->do( q{
INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES
('EmailPurchaseSuggestions','KohaAdminEmailAddress','EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that will be sent new purchase suggestions','Choice'),
('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that will be sent new purchase suggestions','Choice'),
('EmailAddressForSuggestions','','','If you choose EmailAddressForSuggestions you should enter a valid email address','free')
});

View File

@ -161,7 +161,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('ElasticsearchIndexStatus_biblios', '0', 'Biblios index status', NULL, NULL),
('EmailAddressForSuggestions','','',' If you choose EmailAddressForSuggestions you have to enter a valid email address: ','free'),
('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'),
('EmailPurchaseSuggestions','KohaAdminEmailAddress','EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'),
('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'),
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),

View File

@ -9,8 +9,9 @@ Administration:
-
- "Choose email address that new purchase suggestions will be sent to: "
- pref: EmailPurchaseSuggestions
default: KohaAdminEmailAddress
default: 0
choices:
0: None
EmailAddressForSuggestions: EmailAddressForSuggestions
BranchEmailAddress: email address of branch
KohaAdminEmailAddress: KohaAdminEmailAddress

View File

@ -469,15 +469,24 @@ subtest 'DelSuggestionsOlderThan' => sub {
};
subtest 'EmailPurchaseSuggestions' => sub {
plan tests => 5;
plan tests => 6;
$dbh->do(q|DELETE FROM message_queue|);
Koha::Libraries->find('CPL')->update({ branchemail => 'branchemail@b.c' });
t::lib::Mocks::mock_preference( "KohaAdminEmailAddress", 'root@localhost');
t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", 'a@b.c');
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress"); # EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress
# EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress or 0
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "0");
NewSuggestion($my_suggestion);
my $newsuggestions_messages = C4::Letters::GetQueuedMessages({
borrowernumber => $borrowernumber
});
is( @$newsuggestions_messages, 0, 'NewSuggestions does not send an email when disabled' );
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress");
NewSuggestion($my_suggestion);
my $newsuggestions_messages = C4::Letters::GetQueuedMessages({
borrowernumber => $borrowernumber,