From 4ee46be97e69e0abf1475eec40efeff27413a483 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Feb 2022 12:38:18 +0100 Subject: [PATCH] Bug 30055: Use /acquisitions/baskets/managers for basket's manager MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Test plan: Add a manager to a basket Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi Signed-off-by: Séverine Queune Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- Koha/REST/V1/Acquisitions/Baskets.pm | 62 ++++++++++++++++++ acqui/add_user_search.pl | 64 ------------------- api/v1/swagger/swagger.yaml | 2 + .../prog/en/modules/acqui/basket.tt | 2 +- .../prog/en/modules/members/search.tt | 2 + 5 files changed, 67 insertions(+), 65 deletions(-) create mode 100644 Koha/REST/V1/Acquisitions/Baskets.pm delete mode 100755 acqui/add_user_search.pl diff --git a/Koha/REST/V1/Acquisitions/Baskets.pm b/Koha/REST/V1/Acquisitions/Baskets.pm new file mode 100644 index 0000000000..a521b631cc --- /dev/null +++ b/Koha/REST/V1/Acquisitions/Baskets.pm @@ -0,0 +1,62 @@ +package Koha::REST::V1::Acquisitions::Baskets; + +# 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 Mojo::Base 'Mojolicious::Controller'; + +use Try::Tiny qw( catch try ); + +=head1 NAME + +Koha::REST::V1::Acquisitions::Baskets + +=head1 API + +=head2 Class methods + +=head3 list + +Controller function that handles baskets + +=cut + +=head3 list_managers + +Return the list of possible orders' 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('acquisition.order_manage'); + my $patrons = $c->objects->search( $patrons_rs ); + + return $c->render( + status => 200, + openapi => $patrons + ); + } + catch { + $c->unhandled_exception($_); + }; +} + +1; diff --git a/acqui/add_user_search.pl b/acqui/add_user_search.pl deleted file mode 100755 index 1246b0149d..0000000000 --- a/acqui/add_user_search.pl +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/perl - -# This file is part of Koha. -# -# Copyright 2014 BibLibre -# -# 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", - flagsrequired => { acquisition => 'order_manage' }, - } -); - -my $q = $input->param('q') || ''; -my $op = $input->param('op') || ''; - -my $referer = $input->referer(); - -# If this script is called by acqui/basket.pl -# the patrons to return should be superlibrarian or have the order_manage -# acquisition flag. -my $search_patrons_with_acq_perm_only = - ( $referer =~ m|acqui/basket.pl| ) - ? 1 : 0; - -my $patron_categories = Koha::Patron::Categories->search_with_library_limits; -$template->param( - patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only, - view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", - columns => ['cardnumber', 'name', 'branch', 'category', 'action'], - json_template => 'acqui/tables/members_results.tt', - selection_type => 'add', - alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ), - categories => $patron_categories, - aaSorting => 1, -); -output_html_with_http_headers( $input, $cookie, $template->output ); diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index e8fc6efe93..9564dba35d 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -65,6 +65,8 @@ definitions: vendor: $ref: ./definitions/vendor.yaml paths: + /acquisitions/baskets/managers: + $ref: paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets~1managers /acquisitions/funds: $ref: ./paths/acquisitions_funds.yaml#/~1acquisitions~1funds /acquisitions/orders: diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt index 09648ab56a..9ef5b60c62 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -1010,7 +1010,7 @@ function UserSearchPopup(f) { window.open( - "/cgi-bin/koha/acqui/add_user_search.pl", + "/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=add&filter=baskets_managers", 'UserSearchPopup', 'width=840, height=500, scrollbars=yes, toolbar=no,' ); 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 c1d9e22e6b..51a3f8aa60 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt @@ -167,6 +167,8 @@ [% SWITCH filter %] [% CASE 'suggestions_managers' %] "url": '/api/v1/suggestions/managers' + [% CASE 'baskets_managers' %] + "url": '/api/v1/acquisitions/baskets/managers' [% CASE %] "url": '/api/v1/patrons' [% END %] -- 2.39.5