Bugzilla – Attachment 132451 Details for
Bug 30055
Rewrite some of the patron searches to make them use the REST API routes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30055: Use /api/v1/suggestions/managers to list managers or suggestions
Bug-30055-Use-apiv1suggestionsmanagers-to-list-man.patch (text/plain), 9.78 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-03-29 15:34:55 UTC
(
hide
)
Description:
Bug 30055: Use /api/v1/suggestions/managers to list managers or suggestions
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-03-29 15:34:55 UTC
Size:
9.78 KB
patch
obsolete
>From b2283f6aca29ffca148160c489ff401fb9be6853 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 9 Feb 2022 10:24:35 +0100 >Subject: [PATCH] Bug 30055: Use /api/v1/suggestions/managers to list managers > or suggestions > >Test plan: >Select a manager for a suggestion > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/REST/V1/Suggestions.pm | 24 +++++++ > api/v1/swagger/paths/suggestions.yaml | 43 +++++++++++++ > api/v1/swagger/swagger.yaml | 2 + > .../prog/en/modules/members/search.tt | 7 +- > .../prog/en/modules/suggestion/suggestion.tt | 4 +- > members/search.pl | 13 ++-- > suggestion/add_user_search.pl | 64 ------------------- > 7 files changed, 86 insertions(+), 71 deletions(-) > delete mode 100755 suggestion/add_user_search.pl > >diff --git a/Koha/REST/V1/Suggestions.pm b/Koha/REST/V1/Suggestions.pm >index 1c0532cc61..404318da88 100644 >--- a/Koha/REST/V1/Suggestions.pm >+++ b/Koha/REST/V1/Suggestions.pm >@@ -177,4 +177,28 @@ sub delete { > }; > } > >+=head3 list_managers >+ >+Return the list of possible suggestions' managers >+ >+=cut >+ >+sub list_managers { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ >+ my $patrons_rs = Koha::Patrons->search->filter_by_have_subpermission('suggestions.suggestions_manage'); >+ my $patrons = $c->objects->search( $patrons_rs ); >+ >+ return $c->render( >+ status => 200, >+ openapi => $patrons >+ ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > 1; >diff --git a/api/v1/swagger/paths/suggestions.yaml b/api/v1/swagger/paths/suggestions.yaml >index 346598e121..7ecadd5e11 100644 >--- a/api/v1/swagger/paths/suggestions.yaml >+++ b/api/v1/swagger/paths/suggestions.yaml >@@ -214,3 +214,46 @@ > x-koha-authorization: > permissions: > suggestions: suggestions_manage >+/suggestions/managers: >+ get: >+ x-mojo-to: Suggestions#list_managers >+ operationId: listSuggestionsManagers >+ description: This resource returns a list of patron allowed to be a manager for suggestions >+ summary: List possibe managers for suggestions >+ tags: >+ - suggestions >+ parameters: >+ - $ref: ../parameters.yaml#/match >+ - $ref: ../parameters.yaml#/order_by >+ - $ref: ../parameters.yaml#/page >+ - $ref: ../parameters.yaml#/per_page >+ - $ref: ../parameters.yaml#/q_param >+ - $ref: ../parameters.yaml#/q_body >+ - $ref: ../parameters.yaml#/q_header >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: A list of suggestions' managers >+ schema: >+ type: array >+ items: >+ $ref: ../definitions.yaml#/patron >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: ../definitions.yaml#/error >+ "500": >+ description: | >+ Internal server error. Possible `error_code` attribute values: >+ >+ * `internal_server_error` >+ schema: >+ $ref: ../definitions.yaml#/error >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: ../definitions.yaml#/error >+ x-koha-authorization: >+ permissions: >+ suggestions: suggestions_manage >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 1118cd129c..e8fc6efe93 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -201,6 +201,8 @@ paths: > $ref: ./paths/suggestions.yaml#/~1suggestions > "/suggestions/{suggestion_id}": > $ref: "./paths/suggestions.yaml#/~1suggestions~1{suggestion_id}" >+ /suggestions/managers: >+ $ref: paths/suggestions.yaml#/~1suggestions~1managers > /transfer_limits: > $ref: ./paths/transfer_limits.yaml#/~1transfer_limits > /transfer_limits/batch: >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt >index 0bcc2cfd1d..c1d9e22e6b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt >@@ -164,7 +164,12 @@ > }; > patrons_table = $("#memberresultst").kohaTable({ > "ajax": { >- "url": '/api/v1/patrons' >+ [% SWITCH filter %] >+ [% CASE 'suggestions_managers' %] >+ "url": '/api/v1/suggestions/managers' >+ [% CASE %] >+ "url": '/api/v1/patrons' >+ [% END %] > }, > "order": [[ 1, "asc" ]], > "iDeferLoading": 0, >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt >index 27ca89ba9e..99309134cc 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt >@@ -1218,7 +1218,7 @@ > var tab = ''; > function editManagerPopup(selected_tab) { > tab = selected_tab; >- window.open("/cgi-bin/koha/suggestion/add_user_search.pl?selection_type=select&callback=select_manager&permissions=suggestions.suggestions_manage", >+ window.open("/cgi-bin/koha/members/search.pl?columns=cardnumber,name,branch,category,action&selection_type=select&callback=select_manager&filter=suggestions_managers", > 'PatronPopup', > 'width=740,height=450,location=yes,toolbar=no,' > + 'scrollbars=yes,resize=yes' >@@ -1255,7 +1255,7 @@ > } > > function editSuggesterPopup() { >- window.open("/cgi-bin/koha/suggestion/add_user_search.pl?selection_type=select&callback=select_suggester", >+ window.open("/cgi-bin/koha/members/search.pl?columns=cardnumber,name,branch,category,action&selection_type=select&callback=select_suggester", > 'PatronPopup', > 'width=740,height=450,location=yes,toolbar=no,' > + 'scrollbars=yes,resize=yes' >diff --git a/members/search.pl b/members/search.pl >index 630f509177..4689cf89b1 100755 >--- a/members/search.pl >+++ b/members/search.pl >@@ -34,11 +34,16 @@ my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( > my $referer = $input->referer(); > > my @columns = split ',', $input->param('columns'); >+my $callback = $input->param('callback'); >+my $selection_type = $input->param('selection_type') || 'select'; >+my $filter = $input->param('filter'); > > $template->param( >- view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", >- columns => \@columns, >- selection_type => 'select', >- alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ), >+ view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", >+ callback => $callback, >+ columns => \@columns, >+ filter => $filter, >+ selection_type => $selection_type, >+ alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ), > ); > output_html_with_http_headers( $input, $cookie, $template->output ); >diff --git a/suggestion/add_user_search.pl b/suggestion/add_user_search.pl >deleted file mode 100755 >index d71d033f0e..0000000000 >--- a/suggestion/add_user_search.pl >+++ /dev/null >@@ -1,64 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use CGI qw ( -utf8 ); >-use C4::Auth qw( get_template_and_user ); >-use C4::Output qw( output_html_with_http_headers ); >-use C4::Members; >- >-use Koha::Patron::Categories; >- >-my $input = CGI->new; >- >-my $dbh = C4::Context->dbh; >- >-my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( >- { template_name => "common/patron_search.tt", >- query => $input, >- type => "intranet", >- authnotrequired => 0, >- flagsrequired => { suggestions => 'suggestions_manage' }, >- } >-); >- >-my $q = $input->param('q') || ''; >-my $op = $input->param('op') || ''; >-my $selection_type = $input->param('selection_type') || 'add'; >- >-my $referer = $input->referer(); >- >-# The patrons to return should be superlibrarian or have the suggestions_manage flag >-my $permissions = $input->param('permissions'); >-my $search_patrons_with_suggestion_perm_only = >- ( $permissions && $permissions eq 'suggestions.suggestions_manage' ) >- ? 1 : 0; >- >-my $patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']});; >-$template->param( >- patrons_with_suggestion_perm_only => $search_patrons_with_suggestion_perm_only, >- view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", >- callback => scalar $input->param('callback'), >- columns => ['cardnumber', 'name', 'branch', 'category', 'action'], >- json_template => 'acqui/tables/members_results.tt', >- selection_type => $selection_type, >- alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ), >- categories => $patron_categories, >- aaSorting => 1, >-); >-output_html_with_http_headers( $input, $cookie, $template->output ); >-- >2.35.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 30055
:
130364
|
130365
|
130366
|
130367
|
130368
|
130369
|
130370
|
130371
|
130372
|
130385
|
130386
|
130387
|
130388
|
130389
|
130390
|
130391
|
130392
|
130393
|
130394
|
130395
|
130457
|
130487
|
130488
|
130491
|
130507
|
130511
|
130629
|
130630
|
130671
|
130672
|
130701
|
130702
|
130704
|
130716
|
130717
|
131829
|
132168
|
132419
|
132420
|
132421
|
132422
|
132423
|
132424
|
132425
|
132426
|
132427
|
132428
|
132429
|
132430
|
132431
|
132432
|
132433
|
132434
|
132435
|
132436
|
132437
|
132438
|
132439
|
132440
|
132441
|
132450
|
132451
|
132452
|
132453
|
132454
|
132455
|
132456
|
132457
|
132458
|
132459
|
132460
|
132461
|
132462
|
132463
|
132464
|
132465
|
132466
|
132467
|
132468
|
132469
|
132470
|
132471
|
132472
|
132473
|
132539
|
132616
|
132617
|
132618
|
132619
|
132620
|
132621
|
132622
|
132623
|
132624
|
132625
|
132627
|
132628
|
132629
|
132630
|
132631
|
132632
|
132633
|
132634
|
132635
|
132636
|
132637
|
132638
|
132639
|
132640
|
132641
|
132664
|
132665
|
132666
|
132667
|
132668
|
132669
|
132670
|
132671
|
132672
|
132673
|
132674
|
132675
|
132676
|
132677
|
132678
|
132679
|
132680
|
132681
|
132682
|
132683
|
132684
|
132685
|
132686
|
132687
|
132688