Browse Source

Bug 26595: Embed the whole smtp_server object

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Jonathan Druart 2 years ago
parent
commit
8eb68c082a
  1. 17
      Koha/Library.pm
  2. 2
      admin/columns_settings.yml
  3. 16
      api/v1/swagger/definitions/library.json
  4. 4
      api/v1/swagger/paths/libraries.json
  5. 10
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
  6. 21
      t/db_dependent/Koha/Library.t

17
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;

2
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

16
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,

4
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": {

10
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': '<div class="dialog message">'+_("There are no libraries defined.")+' <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">'+_("Start defining libraries")+'</a>.</div>',
"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 '<a href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&smtp_server_id='+encodeURIComponent(data.smtp_server_id)+'">'+data.name.escapeHtml()+'</a>';
}
else {
return '<a href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&smtp_server_id='+encodeURIComponent(data.smtp_server_id)+'">'+data.name.escapeHtml()+'</a>';
return _("Default");
}
},
"searchable": false,

21
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;
};

Loading…
Cancel
Save