Bugzilla – Attachment 143357 Details for
Bug 26635
Expand coded values in REST API call
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26635: AV expansion should ackowledge $params->{public}
Bug-26635-AV-expansion-should-ackowledge-params-pu.patch (text/plain), 4.74 KB, created by
Martin Renvoize (ashimema)
on 2022-11-07 12:29:54 UTC
(
hide
)
Description:
Bug 26635: AV expansion should ackowledge $params->{public}
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-11-07 12:29:54 UTC
Size:
4.74 KB
patch
obsolete
>From 7185b933fd71e40915de1b32f4cb49247575b485 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 28 Oct 2022 11:50:13 -0300 >Subject: [PATCH] Bug 26635: AV expansion should ackowledge $params->{public} > >This patch simplifies the original implementation so it is more >readable, removing extra loops and methods and just dealing with the >coded values inline on the existing loops. > >It also adds non-public attributes removal from the original list, to >address the changes introduced by bug 28948. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Object.t \ > t/db_dependent/Koha/REST/Plugin/Objects.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/Object.pm | 78 +++++++++++++++++--------------------------------- > 1 file changed, 26 insertions(+), 52 deletions(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index 384e7fd59a..a574bf8fc7 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -553,35 +553,52 @@ sub to_api { > my ( $self, $params ) = @_; > my $json_object = $self->TO_JSON; > >- # Remove forbidden attributes if required >+ # coded values handling >+ my $avs = {}; >+ if ( $params->{av_expand} and $self->can('_fetch_authorised_values') ) { >+ $avs = $self->_fetch_authorised_values; >+ } >+ >+ # Remove forbidden attributes if required (including their coded values) > if ( $params->{public} ) { > for my $field ( keys %{$json_object} ) { > delete $json_object->{$field} unless any { $_ eq $field } @{ $self->public_read_list }; > } >+ >+ if ( $params->{av_expand} ) { >+ foreach my $field (keys %{$avs}) { >+ delete $avs->{$field} >+ unless any { $_ eq $field } @{ $self->public_read_list }; >+ } >+ } > } > > my $to_api_mapping = $self->to_api_mapping; > >- # Rename attributes if there's a mapping >+ # Rename attributes and coded values if there's a mapping > if ( $self->can('to_api_mapping') ) { > foreach my $column ( keys %{ $self->to_api_mapping } ) { > my $mapped_column = $self->to_api_mapping->{$column}; > if ( exists $json_object->{$column} >- && defined $mapped_column ) >- { >+ && defined $mapped_column ) { >+ > # key != undef > $json_object->{$mapped_column} = delete $json_object->{$column}; >- } >- elsif ( exists $json_object->{$column} >- && !defined $mapped_column ) >- { >+ $avs->{$mapped_column} = delete $avs->{$column} >+ if exists $avs->{$column}; >+ >+ } elsif ( exists $json_object->{$column} >+ && !defined $mapped_column ) { >+ > # key == undef > delete $json_object->{$column}; >+ delete $avs->{$column}; > } > } > } > >- my $av_expand = $params->{av_expand}; >+ $json_object->{_authorised_values} = $avs >+ if $params->{av_expand}; > > # Make sure we duplicate the $params variable to avoid > # breaking calls in a loop (Koha::Objects->to_api) >@@ -629,49 +646,6 @@ sub to_api { > } > } > >- if ( $av_expand && $self->can('_fetch_authorised_values') ) { >- >- # _fetch_authorised_values should return a hash as the following >- # { >- # column_name => <authorised_value>->unblessed >- # ... >- # } >- my $avs = $self->_fetch_authorised_values($av_expand); >- >- # Language selection will be implemented when lang overlay for av is ready >- # Now we will just fetch plain authorised values from the Koha::AuthorisedValues >- $avs = $self->_do_api_mapping($avs); >- >- $json_object->{_authorised_values} = $avs || {}; >- } >- >- return $json_object; >-} >- >-=head3 _do_api_mapping >- >-=cut >- >-sub _do_api_mapping { >- my ($self, $json_object) = @_; >- # Rename attributes if there's a mapping >- if ( $self->can('to_api_mapping') ) { >- foreach my $column ( keys %{ $self->to_api_mapping } ) { >- my $mapped_column = $self->to_api_mapping->{$column}; >- if ( exists $json_object->{$column} >- && defined $mapped_column ) >- { >- # key != undef >- $json_object->{$mapped_column} = delete $json_object->{$column}; >- } >- elsif ( exists $json_object->{$column} >- && !defined $mapped_column ) >- { >- # key == undef >- delete $json_object->{$column}; >- } >- } >- } > return $json_object; > } > >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26635
:
111400
|
111401
|
111402
|
111411
|
111412
|
111413
|
111414
|
112538
|
112539
|
116232
|
116233
|
116234
|
116235
|
116592
|
116593
|
120698
|
120699
|
120700
|
124268
|
142761
|
142762
|
142763
|
142776
|
142792
|
142793
|
142794
|
142795
|
142796
|
142801
|
142802
|
142803
|
142804
|
142805
|
143039
|
143040
|
143041
|
143042
|
143043
|
143044
|
143073
|
143074
|
143075
|
143076
|
143077
|
143078
|
143079
|
143080
|
143127
|
143128
|
143129
|
143130
|
143131
|
143132
|
143133
|
143134
|
143276
|
143354
|
143355
|
143356
| 143357 |
143358
|
143359
|
143360
|
143361
|
143362