Bugzilla – Attachment 145699 Details for
Bug 27424
One should be able to assign an SMTP server as the default
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27424: Add ability to specify an SMTP server in the database as the default server
Bug-27424-Add-ability-to-specify-an-SMTP-server-in.patch (text/plain), 10.11 KB, created by
Kyle M Hall (khall)
on 2023-01-26 18:44:56 UTC
(
hide
)
Description:
Bug 27424: Add ability to specify an SMTP server in the database as the default server
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2023-01-26 18:44:56 UTC
Size:
10.11 KB
patch
obsolete
>From bbcb9a64a0cdb4f8490ebe612473a14ff153a317 Mon Sep 17 00:00:00 2001 >From: Kyle Hall <kyle@bywatersolutions.com> >Date: Thu, 20 Jan 2022 14:26:13 -0500 >Subject: [PATCH] Bug 27424: Add ability to specify an SMTP server in the > database as the default server > >Bug 22343 adds the ability to defined SMTP servers via the UI; But to then utilise them you have to go to each individual library via the libraries admin area and select the SMTP server. > >We should have a way to override the fallback/default SMTP server right from the SMTP servers administration page.. setting one of our defined SMTP Servers as the system default rather than using the hard coded fallback options. > >Test Plan: >1) Apply this patch set >2) Restart all the things! >3) Browser to the SMTP servers editor, > verify only one server can be set as the default server >4) Set a default server, verify that server was used to send email from > a cronjob, AND/OR prove t/db_dependent/Koha/SMTP/Server.t > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/SMTP/Servers.pm | 6 +++- > admin/smtp_servers.pl | 33 +++++++++++++++---- > api/v1/swagger/definitions/smtp_server.yaml | 3 ++ > installer/data/mysql/kohastructure.sql | 1 + > .../prog/en/modules/admin/smtp_servers.tt | 27 +++++++++++++++ > t/db_dependent/Koha/SMTP/Server.t | 20 +++++++++-- > 6 files changed, 80 insertions(+), 10 deletions(-) > >diff --git a/Koha/SMTP/Servers.pm b/Koha/SMTP/Servers.pm >index d7451e9a87..6925c811b2 100644 >--- a/Koha/SMTP/Servers.pm >+++ b/Koha/SMTP/Servers.pm >@@ -44,9 +44,13 @@ sub get_default { > my ($self) = @_; > > my $default; >+ > my $smtp_config = C4::Context->config('smtp_server'); > >- if ( $smtp_config ) { >+ if ( $default = $self->search({ is_default => 1 }, { rows => 1 })->single ) { >+ >+ } >+ elsif ( $smtp_config ) { > $default = Koha::SMTP::Server->new( $smtp_config ); > } > else { >diff --git a/admin/smtp_servers.pl b/admin/smtp_servers.pl >index 8c53bfc4be..ccad8e95ff 100755 >--- a/admin/smtp_servers.pl >+++ b/admin/smtp_servers.pl >@@ -52,8 +52,14 @@ if ( $op eq 'add' ) { > my $user_name = $input->param('smtp_user_name') || undef; > my $password = $input->param('smtp_password') || undef; > my $debug = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0; >+ my $is_default = ( scalar $input->param('smtp_default') ) ? 1 : 0; > >+ my $schema = Koha::Database->new->schema; > try { >+ $schema->storage->txn_begin; >+ >+ Koha::SMTP::Servers->search->update({ is_default => 0 }) if $is_default; >+ > Koha::SMTP::Server->new( > { > name => $name, >@@ -64,12 +70,15 @@ if ( $op eq 'add' ) { > user_name => $user_name, > password => $password, > debug => $debug, >+ is_default => $is_default, > } > )->store; > > push @messages, { type => 'message', code => 'success_on_insert' }; >+ $schema->storage->txn_commit; > } > catch { >+ $schema->storage->txn_rollback; > if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { > push @messages, > { >@@ -122,21 +131,29 @@ elsif ( $op eq 'edit_save' ) { > my $user_name = $input->param('smtp_user_name') || undef; > my $password = $input->param('smtp_password') || undef; > my $debug = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0; >+ my $is_default = ( scalar $input->param('smtp_default') ) ? 1 : 0; >+ >+ my $schema = Koha::Database->new->schema; > > try { >+ $schema->storage->txn_begin; >+ >+ Koha::SMTP::Servers->search->update({ is_default => 0 }) if $is_default; >+ > $smtp_server->password( $password ) > if defined $password and $password ne '****' > or not defined $password; > > $smtp_server->set( > { >- name => $name, >- host => $host, >- port => $port, >- timeout => $timeout, >- ssl_mode => $ssl_mode, >- user_name => $user_name, >- debug => $debug >+ name => $name, >+ host => $host, >+ port => $port, >+ timeout => $timeout, >+ ssl_mode => $ssl_mode, >+ user_name => $user_name, >+ debug => $debug, >+ is_default => $is_default, > } > )->store; > >@@ -145,8 +162,10 @@ elsif ( $op eq 'edit_save' ) { > type => 'message', > code => 'success_on_update' > }; >+ $schema->storage->txn_commit; > } > catch { >+ $schema->storage->txn_rollback; > push @messages, > { > type => 'alert', >diff --git a/api/v1/swagger/definitions/smtp_server.yaml b/api/v1/swagger/definitions/smtp_server.yaml >index c06831eb97..fe8d1c0e61 100644 >--- a/api/v1/swagger/definitions/smtp_server.yaml >+++ b/api/v1/swagger/definitions/smtp_server.yaml >@@ -37,6 +37,9 @@ properties: > debug: > type: boolean > description: If the SMTP connection is set to debug mode >+ is_default: >+ type: boolean >+ description: Is this the default SMTP server > additionalProperties: false > required: > - name >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 59607073ca..f9ae4c4cd7 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -5270,6 +5270,7 @@ CREATE TABLE `smtp_servers` ( > `user_name` varchar(80) DEFAULT NULL, > `password` varchar(80) DEFAULT NULL, > `debug` tinyint(1) NOT NULL DEFAULT 0, >+ `is_default` tinyint(1) NOT NULL DEFAULT 0, > PRIMARY KEY (`id`), > KEY `host_idx` (`host`) > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt >index 1d7cd0e8d2..4d73447f3b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt >@@ -134,6 +134,11 @@ > </select> > <span>Enables additional debug output in the logs</span> > </li> >+ <li> >+ <label for="smtp_default">Default server: </label> >+ <input type="checkbox" name="smtp_default" id="smtp_default" /> >+ <span>Sets this SMTP server as the default SMTP server.</span> >+ </li> > </ol> > </fieldset> > <fieldset class="action"> >@@ -216,6 +221,15 @@ > [%- END -%] > </select> > </li> >+ <li> >+ <label for="smtp_default">Default server: </label> >+ [% IF smtp_server.is_default %] >+ <input type="checkbox" name="smtp_default" id="smtp_default" checked="checked"/> >+ [% ELSE %] >+ <input type="checkbox" name="smtp_default" id="smtp_default" /> >+ [% END %] >+ <span>Sets this SMTP server as the default SMTP server.</span> >+ </li> > </ol> > </fieldset> > <fieldset class="action"> >@@ -256,6 +270,7 @@ > <th>Timeout (secs)</th> > <th>SSL</th> > <th>Authenticated</th> >+ <th>Is default</th> > <th data-class-name="actions noExport">Actions</th> > </tr> > </thead> >@@ -370,6 +385,18 @@ > "searchable": false, > "orderable": false > }, >+ { >+ "data": function( row, type, val, meta ) { >+ if ( row.is_default ) { >+ return _("Yes"); >+ } >+ else { >+ return _("No"); >+ } >+ }, >+ "searchable": false, >+ "orderable": false >+ }, > { > "data": function( row, type, val, meta ) { > var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&smtp_server_id='+ encodeURIComponent(row.smtp_server_id) +'"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n"; >diff --git a/t/db_dependent/Koha/SMTP/Server.t b/t/db_dependent/Koha/SMTP/Server.t >index c951196f2d..c8922177dd 100755 >--- a/t/db_dependent/Koha/SMTP/Server.t >+++ b/t/db_dependent/Koha/SMTP/Server.t >@@ -64,16 +64,32 @@ subtest 'transport() tests' => sub { > > subtest 'is_system_default() tests' => sub { > >- plan tests => 2; >+ plan tests => 3; > > $schema->storage->txn_begin; > >- my $smtp_server = $builder->build_object({ class => 'Koha::SMTP::Servers' }); >+ Koha::SMTP::Servers->search()->delete(); >+ >+ my $smtp_server = $builder->build_object( >+ { >+ class => 'Koha::SMTP::Servers', >+ value => { is_default => 0 } >+ } >+ ); >+ > ok( !$smtp_server->is_system_default, 'A generated server is not the system default' ); > > my $system_default_server = Koha::SMTP::Servers->get_default; > ok( $system_default_server->is_system_default, 'The server returned by get_default is the system default' ); > >+ $smtp_server = $builder->build_object( >+ { >+ class => 'Koha::SMTP::Servers', >+ value => { ssl_mode => 'disabled', debug => 0, is_default => 1 } >+ } >+ ); >+ is( Koha::SMTP::Servers->get_default->id, $smtp_server->id, "Default server correctly retrieved from database" ); >+ > $schema->storage->txn_rollback; > }; > >-- >2.30.2
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 27424
:
129673
|
129674
|
129675
|
129814
|
130168
|
130169
|
130170
|
130171
|
130172
|
130300
|
130301
|
130302
|
130303
|
130304
|
145697
|
145698
| 145699 |
145700
|
145701
|
145702
|
145705
|
145723
|
145724
|
145725
|
152192