Bugzilla – Attachment 119477 Details for
Bug 17499
Koha objects for messaging preferences
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17499: (follow-up) Validate phone and itiva transport types
Bug-17499-follow-up-Validate-phone-and-itiva-trans.patch (text/plain), 7.63 KB, created by
Lari Taskula
on 2021-04-12 19:37:29 UTC
(
hide
)
Description:
Bug 17499: (follow-up) Validate phone and itiva transport types
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2021-04-12 19:37:29 UTC
Size:
7.63 KB
patch
obsolete
>From 8184e9a1f58589607d6ec9d699d08f0d038c7207 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Wed, 18 Nov 2020 04:10:48 +0000 >Subject: [PATCH] Bug 17499: (follow-up) Validate phone and itiva transport > types > >Message transport types 'phone' and 'itiva' were not validated unlike >'email' and 'sms'. This patch adds equivalent checks to the missing mtts. > >To test: >1. prove t/db_dependent/Koha/Patron/Message/Preferences.t > >Sponsored-by: The National Library of Finland >--- > Koha/Exceptions/Patron/Message/Preference.pm | 10 +++++ > Koha/Patron/Message/Preference.pm | 21 +++++++++ > .../Koha/Patron/Message/Preferences.t | 43 +++++++++++++++++-- > 3 files changed, 71 insertions(+), 3 deletions(-) > >diff --git a/Koha/Exceptions/Patron/Message/Preference.pm b/Koha/Exceptions/Patron/Message/Preference.pm >index 23f78029f5..ddde51e181 100644 >--- a/Koha/Exceptions/Patron/Message/Preference.pm >+++ b/Koha/Exceptions/Patron/Message/Preference.pm >@@ -57,11 +57,21 @@ use Exception::Class ( > description => "Transport type not available for this message.", > fields => ['message_name', 'transport_type'] > }, >+ 'Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired' => { >+ isa => 'Koha::Exceptions::Patron::Message::Preference', >+ description => "Patron has no phone number, cannot use phone transport type.", >+ fields => ['message_name', 'borrowernumber' ] >+ }, > 'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired' => { > isa => 'Koha::Exceptions::Patron::Message::Preference', > description => "Patron has no SMS number, cannot use sms transport type.", > fields => ['message_name', 'borrowernumber' ] > }, >+ 'Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired' => { >+ isa => 'Koha::Exceptions::Patron::Message::Preference', >+ description => "System preference TalkingTechItivaPhoneNotification is disabled, cannot use itiva transport type.", >+ fields => ['message_name', 'borrowernumber' ] >+ }, > ); > > 1; >diff --git a/Koha/Patron/Message/Preference.pm b/Koha/Patron/Message/Preference.pm >index 32fec13cd0..a3ffffa695 100644 >--- a/Koha/Patron/Message/Preference.pm >+++ b/Koha/Patron/Message/Preference.pm >@@ -419,6 +419,27 @@ sub _set_message_transport_types { > ); > } > } >+ elsif ($type eq 'itiva') { >+ if (!C4::Context->preference('TalkingTechItivaPhoneNotification')) { >+ Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired->throw( >+ error => 'System preference TalkingTechItivaPhoneNotification disabled'. >+ 'cannot use itiva as message transport', >+ message_name => $self->message_name, >+ borrowernumber => $self->borrowernumber, >+ ); >+ } >+ } >+ elsif ($type eq 'phone') { >+ if ( !$patron->phone ) { >+ Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired->throw( >+ error => 'Patron has not set phone number'. >+ 'cannot use phone as message transport', >+ message_name => $self->message_name, >+ borrowernumber => $self->borrowernumber, >+ ); >+ } >+ >+ } > elsif ($type eq 'sms') { > if ( !$patron->smsalertnumber ){ > Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired->throw( >diff --git a/t/db_dependent/Koha/Patron/Message/Preferences.t b/t/db_dependent/Koha/Patron/Message/Preferences.t >index 7bc08103a6..75cdb600e5 100644 >--- a/t/db_dependent/Koha/Patron/Message/Preferences.t >+++ b/t/db_dependent/Koha/Patron/Message/Preferences.t >@@ -282,7 +282,7 @@ HERE > }; > > subtest 'set message_transport_types' => sub { >- plan tests => 12; >+ plan tests => 18; > > $schema->storage->txn_begin; > >@@ -339,10 +339,16 @@ HERE > }); > is($stored_transports->count, 2, 'Two transports selected'); > >- # Test email and smsalertnumber validation >+ # Test contact information validation > eval { Koha::Patron::Message::Transport::Types->new({ > message_transport_type => 'email' > })->store }; >+ eval { Koha::Patron::Message::Transport::Types->new({ >+ message_transport_type => 'itiva' >+ })->store }; >+ eval { Koha::Patron::Message::Transport::Types->new({ >+ message_transport_type => 'phone' >+ })->store }; > eval { Koha::Patron::Message::Transport::Types->new({ > message_transport_type => 'sms' > })->store }; >@@ -351,12 +357,23 @@ HERE > message_transport_type => 'email', > is_digest => 1 > })->store; >+ Koha::Patron::Message::Transport->new({ >+ message_attribute_id => $preference->message_attribute_id, >+ message_transport_type => 'itiva', >+ is_digest => 1 >+ })->store; >+ Koha::Patron::Message::Transport->new({ >+ message_attribute_id => $preference->message_attribute_id, >+ message_transport_type => 'phone', >+ is_digest => 1 >+ })->store; > Koha::Patron::Message::Transport->new({ > message_attribute_id => $preference->message_attribute_id, > message_transport_type => 'sms', > is_digest => 1 > })->store; >- $patron->set({ email => '', smsalertnumber => '' })->store; >+ t::lib::Mocks::mock_preference('TalkingTechItivaPhoneNotification', 0); >+ $patron->set({ email => '', phone => '', smsalertnumber => '' })->store; > eval { > $preference->message_transport_types('email')->store; > }; >@@ -367,6 +384,26 @@ HERE > .' tells us it which message name it was.'); > is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' > .' tells us which patron it was.'); >+ eval { >+ $preference->message_transport_types('itiva')->store; >+ }; >+ is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired', >+ 'Adding a message preference with invalid message_transport_type' >+ .' => Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired'); >+ is ($@->message_name, $preference->message_name, 'The previous exception ' >+ .' tells us it which message name it was.'); >+ is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' >+ .' tells us which patron it was.'); >+ eval { >+ $preference->message_transport_types('phone')->store; >+ }; >+ is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired', >+ 'Adding a message preference with invalid message_transport_type' >+ .' => Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired'); >+ is ($@->message_name, $preference->message_name, 'The previous exception ' >+ .' tells us it which message name it was.'); >+ is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' >+ .' tells us which patron it was.'); > eval { > $preference->message_transport_types('sms')->store; > }; >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17499
:
63427
|
63428
|
63429
|
63430
|
63431
|
63432
|
63433
|
63434
|
63786
|
63787
|
63788
|
63789
|
63790
|
63791
|
63792
|
63793
|
63801
|
63802
|
63803
|
63804
|
63805
|
63806
|
63807
|
63808
|
63809
|
63810
|
63811
|
63812
|
63878
|
63895
|
64035
|
64036
|
64037
|
64038
|
64039
|
64040
|
64041
|
64042
|
64043
|
64044
|
64795
|
66686
|
69434
|
69435
|
69458
|
91864
|
93863
|
93865
|
93872
|
94748
|
99479
|
99634
|
99668
|
99669
|
99670
|
103441
|
103442
|
103443
|
106653
|
106654
|
106655
|
106656
|
106657
|
107612
|
107613
|
107614
|
107615
|
107616
|
113010
|
113011
|
113127
|
113129
|
113686
|
113687
|
113765
|
113766
|
113767
|
113768
|
118452
|
118453
|
119470
|
119471
|
119472
|
119473
|
119474
|
119475
|
119476
|
119477
|
119478
|
119479
|
119480
|
119481
|
119482
|
119483
|
119484
|
119485
|
119486
|
119487
|
119488
|
119489
|
119490
|
119491
|
141408
|
141409
|
141410
|
141411
|
141412
|
141413
|
141414
|
141415
|
141416
|
141417
|
141418
|
146529
|
146530
|
146531
|
146532
|
146533
|
146534
|
146535
|
146536
|
146537
|
146538
|
146539
|
146540
|
151900
|
151901
|
151902
|
151903
|
151904
|
151905
|
151906
|
151907
|
151908
|
151909
|
151910
|
151911
|
151937
|
151938
|
151939
|
151940
|
151941
|
151942
|
151943
|
151944
|
151945
|
151946
|
151947
|
151948
|
155365
|
155366
|
155367
|
155368
|
155369
|
155370
|
155371
|
155372
|
155373
|
155374
|
155375
|
155376