Bugzilla – Attachment 117655 Details for
Bug 27854
Clean GET /patrons controller
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27854: Clean GET /patrons controller
Bug-27854-Clean-GET-patrons-controller.patch (text/plain), 3.48 KB, created by
David Nind
on 2021-03-04 09:37:38 UTC
(
hide
)
Description:
Bug 27854: Clean GET /patrons controller
Filename:
MIME Type:
Creator:
David Nind
Created:
2021-03-04 09:37:38 UTC
Size:
3.48 KB
patch
obsolete
>From 1948646d2fdf989ed63fd4668075a3ed00bea0fc Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 3 Mar 2021 16:37:09 -0300 >Subject: [PATCH] Bug 27854: Clean GET /patrons controller > >The controller method was written a lot of time before the enhancements >we added to the objects.search helper, and it is now much easier to >handle the 'restricted' param use case. > >No need to do it like that anymore. > >This patch fetches the 'restricted' param from the query parameters and >cleans it from the validated data, so we can just pass the resultset to >$c->objects->search as in all other controllers. > >And we had tests for the expected behavior, so testing this is as easy >as: > >1. Run: > $ kshell > k$ prove t/db_dependent/api/v1/patrons.t >=> SUCCESS: Tests pass! >2. Apply this patch >3. Repeat 1 >=> SUCCESS: Tests still pass! Of course! >4. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/REST/V1/Patrons.pm | 56 ++++++++----------------------------------------- > 1 file changed, 9 insertions(+), 47 deletions(-) > >diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm >index b37452ec82..f82af2c8f9 100644 >--- a/Koha/REST/V1/Patrons.pm >+++ b/Koha/REST/V1/Patrons.pm >@@ -44,62 +44,24 @@ sub list { > > return try { > >- my $patrons_rs = Koha::Patrons->new; >- my $args = $c->validation->output; >- my $attributes = {}; >+ my $query = {}; >+ my $restricted = delete $c->validation->output->{restricted}; >+ $query->{debarred} = { '!=' => undef } >+ if $restricted; > >- # Extract reserved params >- my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($args); >+ my $patrons_rs = Koha::Patrons->search($query); >+ my $patrons = $c->objects->search( $patrons_rs ); > >- my $restricted = delete $filtered_params->{restricted}; >- >- # Merge sorting into query attributes >- $c->dbic_merge_sorting( >- { >- attributes => $attributes, >- params => $reserved_params, >- result_set => $patrons_rs >- } >- ); >- >- # Merge pagination into query attributes >- $c->dbic_merge_pagination( >- { >- filter => $attributes, >- params => $reserved_params >- } >- ); >- >- if ( defined $filtered_params ) { >- >- # Apply the mapping function to the passed params >- $filtered_params = $patrons_rs->attributes_from_api($filtered_params); >- $filtered_params = $c->build_query_params( $filtered_params, $reserved_params ); >- } >- >- # translate 'restricted' => 'debarred' >- $filtered_params->{debarred} = { '!=' => undef } >- if $restricted; >- >- my $patrons = $patrons_rs->search( $filtered_params, $attributes ); >- my $total = $patrons_rs->search->count; >- >- $c->add_pagination_headers( >- { >- total => ($patrons->is_paged ? $patrons->pager->total_entries : $patrons->count), >- base_total => $total, >- params => $args, >- } >+ return $c->render( >+ status => 200, >+ openapi => $patrons > ); >- >- return $c->render( status => 200, openapi => $patrons->to_api ); > } > catch { > $c->unhandled_exception($_); > }; > } > >- > =head3 get > > Controller function that handles retrieving a single Koha::Patron object >-- >2.11.0
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 27854
:
117624
|
117655
|
117675