From 9203b675f2210dbcb29c2b7a9d0cc436bef82adf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 14 Oct 2020 14:12:44 +0200 Subject: [PATCH] Bug 26595: Embed the whole smtp_server object Signed-off-by: Tomas Cohen Arazi --- Koha/Library.pm | 17 --------------- admin/columns_settings.yml | 2 +- api/v1/swagger/definitions/library.json | 16 +++----------- api/v1/swagger/paths/libraries.json | 4 ++-- .../prog/en/modules/admin/branches.tt | 10 ++++----- t/db_dependent/Koha/Library.t | 21 +------------------ 6 files changed, 12 insertions(+), 58 deletions(-) diff --git a/Koha/Library.pm b/Koha/Library.pm index 90da8e28164..165d974f444 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -115,23 +115,6 @@ sub smtp_server { return $self; } -=head3 smtp_server_info - -Returns the SMTP server info for the library, or 'system_default' if it is the system default. - -=cut - -sub smtp_server_info { - my ($self) = @_; - - my $smtp_server = $self->smtp_server; - - return { name => 'system_default' } - if $smtp_server->is_system_default; - - return { name => $smtp_server->name, smtp_server_id => $smtp_server->id }; -} - =head3 inbound_email_address my $to_email = Koha::Library->inbound_email_address; diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml index f6d12dc846d..3d7a426059c 100644 --- a/admin/columns_settings.yml +++ b/admin/columns_settings.yml @@ -260,7 +260,7 @@ modules: - columnname: is_pickup_location - - columnname: smtp_server_info + columnname: smtp_server - columnname: actions cannot_be_toggled: 1 diff --git a/api/v1/swagger/definitions/library.json b/api/v1/swagger/definitions/library.json index bae291cefd9..28c3bf5f791 100644 --- a/api/v1/swagger/definitions/library.json +++ b/api/v1/swagger/definitions/library.json @@ -84,19 +84,9 @@ "type": "boolean", "description": "If the library can act as a pickup location" }, - "smtp_server_info": { - "type": "object", - "properties": { - "name": { - "description": "SMTP server name. 'system_default' if no SMTP server is assigned", - "type": "string" - }, - "smtp_server_id": { - "description": "Internal identifier for the SMTP server", - "type": ["integer", "null"] - } - }, - "description": "The library effective SMTP server information." + "smtp_server": { + "type": ["object", "null"], + "description": "The library effective SMTP server" } }, "additionalProperties": false, diff --git a/api/v1/swagger/paths/libraries.json b/api/v1/swagger/paths/libraries.json index 23131a36848..1a063aa291f 100644 --- a/api/v1/swagger/paths/libraries.json +++ b/api/v1/swagger/paths/libraries.json @@ -180,7 +180,7 @@ } }, "x-koha-embed": [ - "smtp_server_info" + "smtp_server" ] }, "post": { @@ -289,7 +289,7 @@ } }, "x-koha-embed": [ - "smtp_server_info" + "smtp_server" ] }, "put": { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt index 64c53b89bf4..94a83261e3d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt @@ -244,7 +244,7 @@ "ajax": { "url": libraries_url }, - 'embed': [ 'smtp_server_info' ], + 'embed': [ 'smtp_server' ], 'emptyTable': '
'+_("There are no libraries defined.")+' '+_("Start defining libraries")+'.
', "columnDefs": [ { "targets": [0,1,3,4,6,8,9,10,11,12,13,14,15], @@ -319,13 +319,13 @@ } }, { - "data": "smtp_server_info", + "data": "smtp_server", "render": function( data, type, row, meta ) { - if ( data.name == 'system_default' ) { - return _("Default"); + if ( data.smtp_server_id ) { + return ''+data.name.escapeHtml()+''; } else { - return ''+data.name.escapeHtml()+''; + return _("Default"); } }, "searchable": false, diff --git a/t/db_dependent/Koha/Library.t b/t/db_dependent/Koha/Library.t index 8c1d12ae28c..23e88578b3d 100755 --- a/t/db_dependent/Koha/Library.t +++ b/t/db_dependent/Koha/Library.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 1; use Koha::Database; use Koha::SMTP::Servers; @@ -93,22 +93,3 @@ subtest 'smtp_server() tests' => sub { $schema->storage->txn_rollback; }; - -subtest 'smtp_server_info() tests' => sub { - - plan tests => 2; - - $schema->storage->txn_begin; - - my $library = $builder->build_object({ class => 'Koha::Libraries' }); - my $smtp_server = $builder->build_object({ class => 'Koha::SMTP::Servers' }); - - # No SMTP server assigned to library, return system default - is_deeply( $library->smtp_server_info, { name => 'system_default' }, 'System default is returned' ); - - # Assign an SMTP server - $library->smtp_server({ smtp_server => $smtp_server }); - is_deeply( $library->smtp_server_info, { name => $smtp_server->name, smtp_server_id => $smtp_server->id }, 'The right information is returned when SMTP server is assigned' ); - - $schema->storage->txn_rollback; -}; -- 2.28.0