View | Details | Raw Unified | Return to bug 38010
Collapse All | Expand All

(-)a/Koha/Acquisition/Bookseller.pm (-28 lines)
Lines 219-252 sub to_api_mapping { Link Here
219
    };
219
    };
220
}
220
}
221
221
222
=head3 to_api
223
224
    my $json = $av->to_api;
225
226
Overloaded method that returns a JSON representation of the Koha::Acquisition::Bookseller object,
227
suitable for API output.
228
229
=cut
230
231
sub to_api {
232
    my ( $self, $params ) = @_;
233
234
    my $response  = $self->SUPER::to_api($params);
235
    my $overrides = {};
236
237
    if ( $self->interfaces ) {
238
        my $interfaces = $self->interfaces->as_list;
239
        my @updated_interfaces;
240
        foreach my $interface ( @{$interfaces} ) {
241
            $interface->password( $interface->plain_text_password );
242
            push @updated_interfaces, $interface->unblessed;
243
        }
244
        $overrides->{interfaces} = ( \@updated_interfaces );
245
    }
246
247
    return { %$response, %$overrides };
248
}
249
250
=head2 Internal methods
222
=head2 Internal methods
251
223
252
=head3 _type
224
=head3 _type
(-)a/Koha/REST/V1/Acquisitions/Vendors.pm (-1 / +12 lines)
Lines 70-78 sub get { Link Here
70
        unless $vendor;
70
        unless $vendor;
71
71
72
    return try {
72
    return try {
73
        my $vendor_to_return = $c->objects->to_api($vendor);
74
        if ( $vendor_to_return->{interfaces} ) {
75
            my $interfaces = $vendor->interfaces->as_list;
76
            my @updated_interfaces;
77
            foreach my $interface ( @{$interfaces} ) {
78
                $interface->password( $interface->plain_text_password );
79
                push @updated_interfaces, $interface->unblessed;
80
            }
81
            $vendor_to_return->{interfaces} = \@updated_interfaces;
82
        }
83
73
        return $c->render(
84
        return $c->render(
74
            status  => 200,
85
            status  => 200,
75
            openapi => $c->objects->to_api($vendor),
86
            openapi => $vendor_to_return,
76
        );
87
        );
77
    } catch {
88
    } catch {
78
        $c->unhandled_exception($_);
89
        $c->unhandled_exception($_);
(-)a/t/db_dependent/Koha/Acquisition/Booksellers.t (-24 / +1 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 9;
20
use Test::More tests => 8;
21
21
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
Lines 310-334 subtest 'invoices' => sub { Link Here
310
310
311
    $schema->storage->txn_rollback();
311
    $schema->storage->txn_rollback();
312
};
312
};
313
314
subtest 'to_api() tests' => sub {
315
316
    plan tests => 4;
317
318
    $schema->storage->txn_begin;
319
320
    my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } );
321
322
    is( $vendor->interfaces->count, 0, 'Vendor has no interfaces' );
323
324
    $vendor->interfaces(
325
        [ { name => 'first interface' }, { name => 'second interface', login => 'one_login', password => 'Test1234' } ]
326
    );
327
328
    my $interfaces = $vendor->to_api->{interfaces};
329
    is( scalar(@$interfaces),          2,          'Vendor has two interfaces' );
330
    is( @{$interfaces}[0]->{password}, undef,      'No password set for the interface' );
331
    is( @{$interfaces}[1]->{password}, 'Test1234', 'password is unhashed' );
332
333
    $schema->storage->txn_rollback;
334
};
335
- 

Return to bug 38010