From 97f331743657765304c223f95c5fa874abb29d88 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Feb 2022 12:58:28 +0100 Subject: [PATCH] Bug 30055: /api/v1/acquisitions/funds/owners and users for funds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two new routes that do the same thing /api/v1/acquisitions/funds/owners /api/v1/acquisitions/funds/users To list the possible owners and users for a fund 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/Acquisitions/Funds.pm | 48 +++++++++++ admin/add_user_search.pl | 65 -------------- api/v1/swagger/paths/acquisitions_funds.yaml | 86 +++++++++++++++++++ api/v1/swagger/swagger.yaml | 4 + .../modules/acqui/tables/members_results.tt | 26 ------ .../prog/en/modules/admin/aqbudgets.tt | 4 +- .../prog/en/modules/members/search.tt | 4 + 7 files changed, 144 insertions(+), 93 deletions(-) delete mode 100755 admin/add_user_search.pl delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt diff --git a/Koha/REST/V1/Acquisitions/Funds.pm b/Koha/REST/V1/Acquisitions/Funds.pm index c4209289fe..59f9f3577f 100644 --- a/Koha/REST/V1/Acquisitions/Funds.pm +++ b/Koha/REST/V1/Acquisitions/Funds.pm @@ -55,4 +55,52 @@ sub list { }; } +=head3 list_owners + +Return the list of possible funds' owners + +=cut + +sub list_owners { + my $c = shift->openapi->valid_input or return; + + return try { + + my $patrons_rs = Koha::Patrons->search->filter_by_have_subpermission('acquisition.budget_modify'); + my $patrons = $c->objects->search( $patrons_rs ); + + return $c->render( + status => 200, + openapi => $patrons + ); + } + catch { + $c->unhandled_exception($_); + }; +} + +=head3 list_users + +Return the list of possible funds' users + +=cut + +sub list_users { + my $c = shift->openapi->valid_input or return; + + return try { + + my $patrons_rs = Koha::Patrons->search->filter_by_have_subpermission('acquisition.budget_modify'); + my $patrons = $c->objects->search( $patrons_rs ); + + return $c->render( + status => 200, + openapi => $patrons + ); + } + catch { + $c->unhandled_exception($_); + }; +} + 1; diff --git a/admin/add_user_search.pl b/admin/add_user_search.pl deleted file mode 100755 index 032301a6d7..0000000000 --- a/admin/add_user_search.pl +++ /dev/null @@ -1,65 +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 => 'budget_modify' }, - } -); - -my $q = $input->param('q') || ''; -my $op = $input->param('op') || ''; -my $selection_type = $input->param('selection_type') || 'add'; - -my $referer = $input->referer(); - -# If this script is called by admin/aqbudgets.pl -# the patrons to return should be superlibrarian or have the order_manage -# acquisition flag. -my $search_patrons_with_acq_perm_only = - ( $referer =~ m|admin/aqbudgets.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 => $selection_type, - 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/paths/acquisitions_funds.yaml b/api/v1/swagger/paths/acquisitions_funds.yaml index 9dd00ef4b7..188c91e537 100644 --- a/api/v1/swagger/paths/acquisitions_funds.yaml +++ b/api/v1/swagger/paths/acquisitions_funds.yaml @@ -59,3 +59,89 @@ x-koha-authorization: permissions: acquisition: budget_manage_all +/acquisitions/funds/owners: + get: + x-mojo-to: Acquisitions::Funds#list_owners + operationId: listFundsOwners + description: This resource returns a list of patron allowed to be owner of funds + summary: List possibe owners for funds + tags: + - funds + 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 funds' owners + 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: + acquisition: budget_modify +/acquisitions/funds/users: + get: + x-mojo-to: Acquisitions::Funds#list_users + operationId: listFundsUsers + description: This resource returns a list of patron allowed to be owner of funds + summary: List possibe users for funds + tags: + - funds + 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 funds' users + 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: + acquisition: budget_modify diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 9564dba35d..b724868c0c 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -69,6 +69,10 @@ paths: $ref: paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets~1managers /acquisitions/funds: $ref: ./paths/acquisitions_funds.yaml#/~1acquisitions~1funds + /acquisitions/funds/owners: + $ref: paths/acquisitions_funds.yaml#/~1acquisitions~1funds~1owners + /acquisitions/funds/users: + $ref: paths/acquisitions_funds.yaml#/~1acquisitions~1funds~1users /acquisitions/orders: $ref: ./paths/acquisitions_orders.yaml#/~1acquisitions~1orders "/acquisitions/orders/{order_id}": diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt deleted file mode 100644 index 50cc702350..0000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt +++ /dev/null @@ -1,26 +0,0 @@ -[% USE To %] -{ - "sEcho": [% sEcho | html %], - "iTotalRecords": [% iTotalRecords | html %], - "iTotalDisplayRecords": [% iTotalDisplayRecords | html %], - "aaData": [ - [% FOREACH data IN aaData %] - { - "dt_cardnumber": - "[% data.cardnumber | html %]", - "dt_name": - "[% INCLUDE 'patron-title.inc' borrowernumber = data.borrowernumber category_type = data.category_type firstname = To.json(data.firstname) surname = To.json(data.surname) othernames = To.json(data.othernames) cardnumber = data.cardnumber invert_name = 1%]", - "dt_branch": - "[% data.branchname | html %]", - "dt_category": - "[% data.category_description | html %] ([% data.category_type | html %])", - "dt_action": - [%- IF selection_type == 'select' -%] - "Select" - [%- ELSE -%] - " Add" - [%- END -%] - }[% UNLESS loop.last %],[% END %] - [% END %] - ] -} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt index d7f15fe08d..347f79f9c6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -495,7 +495,7 @@ //