Bug 30055: Use /api/v1/suggestions/managers to list managers or suggestions
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 9 Feb 2022 09:24:35 +0000 (10:24 +0100)
committerFridolin Somers <fridolin.somers@biblibre.com>
Mon, 4 Apr 2022 07:46:57 +0000 (09:46 +0200)
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>
Signed-off-by: Séverine Queune <severine.queune@bulac.fr>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Koha/REST/V1/Suggestions.pm
api/v1/swagger/paths/suggestions.yaml
api/v1/swagger/swagger.yaml
koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt
koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt
members/search.pl
suggestion/add_user_search.pl [deleted file]

index 1c0532c..404318d 100644 (file)
@@ -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;
index 346598e..7ecadd5 100644 (file)
     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
index 1118cd1..e8fc6ef 100644 (file)
@@ -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:
index 0bcc2cf..c1d9e22 100644 (file)
             };
             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,
index 27ca89b..9930913 100644 (file)
         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'
         }
 
         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'
index 630f509..4689cf8 100755 (executable)
@@ -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 (executable)
index d71d033..0000000
+++ /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 );