Bugzilla – Attachment 72891 Details for
Bug 20407
Hide some fields from unauthorized users
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20407 - REST API: Ability to hide fields from unauthorized users
Bug-20407---REST-API-Ability-to-hide-fields-from-u.patch (text/plain), 2.33 KB, created by
Alex Arnaud
on 2018-03-14 16:31:32 UTC
(
hide
)
Description:
Bug 20407 - REST API: Ability to hide fields from unauthorized users
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2018-03-14 16:31:32 UTC
Size:
2.33 KB
patch
obsolete
>From 547e613c1a790c5e53e84da45db8ff732d7482eb Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Wed, 14 Mar 2018 16:30:06 +0000 >Subject: [PATCH] Bug 20407 - REST API: Ability to hide fields from > unauthorized users > >Test plan: > - apply this patch, > - edit api/v1/swagger/definitions/city.json, > - remove the keys "country" and "postal_code" from required, > - add a key "x-public": false for country and postal_code > "postal_code": { > "description": "city postal code", > "type": ["string", "null"], > "x-public": false > }, > "country": { > "description": "city country", > "type": ["string", "null"], > "x-public": false > } > - logout from Koha and go to api/v1/cities, > - you should not see country and postal_code, > - login to Koha and refresh api/v1/cities, > - you should see country and postal_code >--- > Koha/REST/Plugin/Objects.pm | 25 ++++++++++++++++++++----- > 1 file changed, 20 insertions(+), 5 deletions(-) > >diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm >index 3653f91..6e63c03 100644 >--- a/Koha/REST/Plugin/Objects.pm >+++ b/Koha/REST/Plugin/Objects.pm >@@ -91,11 +91,26 @@ sub register { > }); > } > >- my @objects_list = map { >- ( defined $to_api ) >- ? $to_api->( $_->TO_JSON ) >- : $_->TO_JSON >- } $objects->as_list; >+ my $spec = $c->openapi->spec(); >+ my $properties = $spec->{responses}{200}{schema}{items}{properties}; >+ >+ my $user = $c->stash('koha.user'); >+ my @hidden_properties; >+ unless ( $user && $user->has_permission({ catalogue => 1 }) ) { >+ foreach my $property ( keys %$properties ) { >+ if ( defined( $properties->{ $property }{'x-public'} ) >+ && !$properties->{ $property }{'x-public'}) { >+ push @hidden_properties, $property; >+ } >+ } >+ } >+ >+ my @objects_list; >+ foreach my $o ( @{ $objects->as_list } ) { >+ my $json = defined($to_api) ? $to_api->( $o->TO_JSON ) : $o->TO_JSON; >+ delete @{ $json }{ @hidden_properties }; >+ push @objects_list, $json; >+ } > > return \@objects_list; > } >-- >2.7.4
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 20407
:
72891
|
72982