@@ -, +, @@ --- Koha/Object.pm | 16 +++++++-------- Koha/REST/Plugin/Objects.pm | 12 ++++++------ Koha/REST/Plugin/Query.pm | 8 ++++---- t/Koha/REST/Plugin/Query.t | 22 ++++++++++----------- t/db_dependent/Koha/Object.t | 24 +++++++++++------------ t/db_dependent/Koha/REST/Plugin/Objects.t | 10 +++++----- 6 files changed, 46 insertions(+), 46 deletions(-) --- a/Koha/Object.pm +++ a/Koha/Object.pm @@ -558,13 +558,13 @@ sub to_api { $params = defined $params ? {%$params} : {}; # children should be able to handle without - my $embeds = delete $params->{embed}; - my $av_expand = delete $params->{av_expand}; + my $embeds = delete $params->{embed}; + my $strings = delete $params->{strings}; # coded values handling my $avs = {}; - if ( $av_expand and $self->can('api_av_mapping') ) { - $avs = $self->api_av_mapping($params); + if ( $strings and $self->can('api_strings_mapping') ) { + $avs = $self->api_strings_mapping($params); } # Remove forbidden attributes if required (including their coded values) @@ -573,7 +573,7 @@ sub to_api { delete $json_object->{$field} unless any { $_ eq $field } @{ $self->public_read_list }; } - if ( $av_expand ) { + if ( $strings ) { foreach my $field (keys %{$avs}) { delete $avs->{$field} unless any { $_ eq $field } @{ $self->public_read_list }; @@ -606,7 +606,7 @@ sub to_api { } $json_object->{_strings} = $avs - if $av_expand; + if $strings; if ($embeds) { foreach my $embed ( keys %{$embeds} ) { @@ -620,8 +620,8 @@ sub to_api { my $curr = $embed; my $next = $embeds->{$curr}->{children}; - $params->{av_expand} = 1 - if $embeds->{$embed}->{av_expand}; + $params->{strings} = 1 + if $embeds->{$embed}->{strings}; my $children = $self->$curr; --- a/Koha/REST/Plugin/Objects.pm +++ a/Koha/REST/Plugin/Objects.pm @@ -53,8 +53,8 @@ the requested object. It passes through any embeds if specified. my $attributes = {}; # Look for embeds - my $embed = $c->stash('koha.embed'); - my $av_expand = $c->stash('koha.av_expand'); + my $embed = $c->stash('koha.embed'); + my $strings = $c->stash('koha.strings'); # Generate prefetches for embedded stuff $c->dbic_merge_prefetch( @@ -68,7 +68,7 @@ the requested object. It passes through any embeds if specified. return unless $object; - return $object->to_api({ embed => $embed, av_expand => $av_expand }); + return $object->to_api({ embed => $embed, strings => $strings }); } ); @@ -99,8 +99,8 @@ shouldn't be called twice in it. # Privileged reques? my $is_public = $c->stash('is_public'); # Look for embeds - my $embed = $c->stash('koha.embed'); - my $av_expand = $c->stash('koha.av_expand'); + my $embed = $c->stash('koha.embed'); + my $strings = $c->stash('koha.strings'); # Merge sorting into query attributes $c->dbic_merge_sorting( @@ -205,7 +205,7 @@ shouldn't be called twice in it. } ); - return $objects->to_api({ embed => $embed, public => $is_public, av_expand => $av_expand }); + return $objects->to_api({ embed => $embed, public => $is_public, strings => $strings }); } ); } --- a/Koha/REST/Plugin/Query.pm +++ a/Koha/REST/Plugin/Query.pm @@ -242,8 +242,8 @@ Unwraps and stashes the x-koha-embed headers for use later query construction if ($embed_header) { my $THE_embed = {}; foreach my $embed_req ( split /\s*,\s*/, $embed_header ) { - if ( $embed_req eq '+av_expand' ) { # special case - $c->stash( 'koha.av_expand' => 1 ); + if ( $embed_req eq '+strings' ) { # special case + $c->stash( 'koha.strings' => 1 ); } else { _merge_embed( _parse_embed($embed_req), $THE_embed ); } @@ -368,9 +368,9 @@ sub _parse_embed { my $key = $+{relation} . "_count"; $result->{$key} = { is_count => 1 }; } - elsif ( $curr =~ m/^(?.*)\+av_expand/ ) { + elsif ( $curr =~ m/^(?.*)\+strings/ ) { my $key = $+{relation}; - $result->{$key} = { av_expand => 1 }; + $result->{$key} = { strings => 1 }; } else { $result->{$curr} = {}; --- a/t/Koha/REST/Plugin/Query.t +++ a/t/Koha/REST/Plugin/Query.t @@ -210,14 +210,14 @@ get '/stash_embed' => sub { my $c = shift; $c->stash_embed(); - my $embed = $c->stash('koha.embed'); - my $av_expand = $c->stash('koha.av_expand'); + my $embed = $c->stash('koha.embed'); + my $strings = $c->stash('koha.strings'); $c->render( status => 200, json => { - av_expand => $av_expand, - embed => $embed, + strings => $strings, + embed => $embed, } ); }; @@ -452,19 +452,19 @@ subtest 'stash_embed() tests' => sub { patron => {} }); - $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item+av_expand,patron+av_expand' } ) + $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item+strings,patron+strings' } ) ->json_is( '/embed' => { - checkouts => { children => { item => { av_expand => 1 } } }, - patron => { av_expand => 1 } + checkouts => { children => { item => { strings => 1 } } }, + patron => { strings => 1 } }) - ->json_is( '/av_expand' => undef ); + ->json_is( '/strings' => undef ); - $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts+av_expand,checkouts.item,patron,+av_expand' } ) + $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts+strings,checkouts.item,patron,+strings' } ) ->json_is( '/embed' => { - checkouts => { children => { item => { } }, av_expand => 1 }, + checkouts => { children => { item => { } }, strings => 1 }, patron => { } }) - ->json_is( '/av_expand' => 1 ); + ->json_is( '/strings' => 1 ); }; subtest 'stash_overrides() tests' => sub { --- a/t/db_dependent/Koha/Object.t +++ a/t/db_dependent/Koha/Object.t @@ -303,7 +303,7 @@ subtest "to_api() tests" => sub { is($biblio_api->{items}->[0]->{holds}->[0]->{hold_id}, $hold->reserve_id, 'Hold matches'); is_deeply($biblio_api->{biblioitem}, $biblio->biblioitem->to_api, 'More than one root'); - my $_str = { + my $_strings = { location => { category => 'ASD', str => 'Estante alto', @@ -311,18 +311,18 @@ subtest "to_api() tests" => sub { } }; - # mock Koha::Item so it implements 'api_av_mapping' + # mock Koha::Item so it implements 'api_strings_mapping' my $item_mock = Test::MockModule->new('Koha::Item'); $item_mock->mock( - 'api_av_mapping', + 'api_strings_mapping', sub { - return $_str; + return $_strings; } ); my $hold_api = $hold->to_api( { - embed => { 'item' => { av_expand => 1 } } + embed => { 'item' => { strings => 1 } } } ); @@ -330,8 +330,8 @@ subtest "to_api() tests" => sub { is( $hold_api->{item}->{item_id}, $item->itemnumber, 'Object embedded correctly' ); is_deeply( $hold_api->{item}->{_strings}, - $_str, - '_str correctly added to nested embed' + $_strings, + '_strings correctly added to nested embed' ); # biblio with no items @@ -475,7 +475,7 @@ subtest "to_api() tests" => sub { my $city_mock = Test::MockModule->new('Koha::City'); $city_mock->mock( - 'api_av_mapping', + 'api_strings_mapping', sub { my ( $self, $params ) = @_; @@ -508,11 +508,11 @@ subtest "to_api() tests" => sub { } ); - my $mobj = $marseille->to_api( { av_expand => 1, public => 1 } ); - my $cobj = $cordoba->to_api( { av_expand => 1, public => 0 } ); + my $mobj = $marseille->to_api( { strings => 1, public => 1 } ); + my $cobj = $cordoba->to_api( { strings => 1, public => 0 } ); - ok( exists $mobj->{_strings}, '_str exists for Marseille' ); - ok( exists $cobj->{_strings}, '_str exists for Córdoba' ); + ok( exists $mobj->{_strings}, '_strings exists for Marseille' ); + ok( exists $cobj->{_strings}, '_strings exists for Córdoba' ); is_deeply( $mobj->{_strings}->{country}, --- a/t/db_dependent/Koha/REST/Plugin/Objects.t +++ a/t/db_dependent/Koha/REST/Plugin/Objects.t @@ -673,7 +673,7 @@ subtest 'objects.find helper with expanded authorised values' => sub { my $city_class = Test::MockModule->new('Koha::City'); $city_class->mock( - 'api_av_mapping', + 'api_strings_mapping', sub { my ($self, $params) = @_; use Koha::AuthorisedValues; @@ -714,7 +714,7 @@ subtest 'objects.find helper with expanded authorised values' => sub { } ); - $t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '+av_expand' } ) + $t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '+strings' } ) ->status_is(200)->json_is( '/name' => 'Manuel' ) ->json_has('/_strings') ->json_is( '/_strings/country/type' => 'av' ) @@ -725,7 +725,7 @@ subtest 'objects.find helper with expanded authorised values' => sub { ->status_is(200)->json_is( '/name' => 'Manuel' ) ->json_hasnt('/_strings'); - $t->get_ok( '/cities/' . $manuela->id => { 'x-koha-embed' => '+av_expand' } ) + $t->get_ok( '/cities/' . $manuela->id => { 'x-koha-embed' => '+strings' } ) ->status_is(200)->json_is( '/name' => 'Manuela' ) ->json_has('/_strings') ->json_is( '/_strings/country/type' => 'av' ) @@ -786,7 +786,7 @@ subtest 'objects.search helper with expanded authorised values' => sub { my $city_class = Test::MockModule->new('Koha::City'); $city_class->mock( - 'api_av_mapping', + 'api_strings_mapping', sub { my ($self, $params) = @_; use Koha::AuthorisedValues; @@ -829,7 +829,7 @@ subtest 'objects.search helper with expanded authorised values' => sub { ); $t->get_ok( '/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' => - { 'x-koha-embed' => '+av_expand' } )->status_is(200) + { 'x-koha-embed' => '+strings' } )->status_is(200) ->json_has('/0')->json_has('/1')->json_hasnt('/2') ->json_is( '/0/name' => 'Manuel' ) ->json_has('/0/_strings') --