From e4df5d03522cc4597131c68a80aba3a11a8e3700 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Feb 2022 10:24:35 +0100 Subject: [PATCH] Bug 30055: Use /api/v1/suggestions/managers to list managers or suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test plan: Select a manager for a suggestion Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi Signed-off-by: Séverine Queune Signed-off-by: Martin Renvoize --- 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 . - -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.20.1