diff --git a/Koha/SMTP/Server.pm b/Koha/SMTP/Server.pm index 919f7898b2..d5fec72611 100644 --- a/Koha/SMTP/Server.pm +++ b/Koha/SMTP/Server.pm @@ -99,6 +99,24 @@ sub is_system_default { return $self->{_is_system_default}; } +=head3 to_api + + my $json = $smtp_server->to_api; + +Overloaded method that returns a JSON representation of the Koha::SMTP::Server object, +suitable for API output. + +=cut + +sub to_api { + my ( $self, $params ) = @_; + + my $json = $self->SUPER::to_api( $params ); + delete $json->{password}; + + return $json; +} + =head3 to_api_mapping This method returns the mapping for representing a Koha::SMTP::Server object diff --git a/t/db_dependent/Koha/SMTP/Server.t b/t/db_dependent/Koha/SMTP/Server.t index 23b368320f..3a1c423e5e 100755 --- a/t/db_dependent/Koha/SMTP/Server.t +++ b/t/db_dependent/Koha/SMTP/Server.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Exception; use Test::Warn; @@ -70,3 +70,15 @@ subtest 'is_system_default() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'to_api() tests' => sub { + + plan tests => 1; + + $schema->storage->txn_begin; + + my $smtp_server = $builder->build_object({ class => 'Koha::SMTP::Servers' }); + ok( !exists $smtp_server->to_api->{password}, 'Password is not part of the API representation' ); + + $schema->storage->txn_rollback; +};