View | Details | Raw Unified | Return to bug 40504
Collapse All | Expand All

(-)a/Koha/REST/V1/ILL.pm (+57 lines)
Line 0 Link Here
1
package Koha::REST::V1::ILL;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Patrons;
23
24
use Try::Tiny qw( catch try );
25
26
=head1 NAME
27
28
Koha::REST::V1::ILL
29
30
=head1 API
31
32
=head2 Class methods
33
34
=head3 list_users
35
36
Return the list of possible ILL users
37
38
=cut
39
40
sub list_users {
41
    my $c = shift->openapi->valid_input or return;
42
43
    return try {
44
45
        my $patrons_rs = Koha::Patrons->search->filter_by_have_permission('ill');
46
        my $patrons    = $c->objects->search($patrons_rs);
47
48
        return $c->render(
49
            status  => 200,
50
            openapi => $patrons
51
        );
52
    } catch {
53
        $c->unhandled_exception($_);
54
    };
55
}
56
57
1;
(-)a/api/v1/swagger/paths/ill_users.yaml (+62 lines)
Line 0 Link Here
1
---
2
/ill/users:
3
  get:
4
    x-mojo-to: ILL#list_users
5
    operationId: listILLUsers
6
    description: This resource returns a list of patron allowed to be users of the ILL module
7
    summary: List possibe users for ILL
8
    tags:
9
      - ill_users
10
    parameters:
11
      - $ref: "../swagger.yaml#/parameters/match"
12
      - $ref: "../swagger.yaml#/parameters/order_by"
13
      - $ref: "../swagger.yaml#/parameters/page"
14
      - $ref: "../swagger.yaml#/parameters/per_page"
15
      - $ref: "../swagger.yaml#/parameters/q_param"
16
      - $ref: "../swagger.yaml#/parameters/q_body"
17
      - name: x-koha-embed
18
        in: header
19
        required: false
20
        description: Embed list sent as a request header
21
        type: array
22
        items:
23
          type: string
24
          enum:
25
            - extended_attributes
26
            - library
27
        collectionFormat: csv
28
    produces:
29
      - application/json
30
    responses:
31
      200:
32
        description: A list of ILL' users
33
        schema:
34
          type: array
35
          items:
36
            $ref: "../swagger.yaml#/definitions/patron"
37
      "400":
38
        description: |
39
          Bad request. Possible `error_code` attribute values:
40
41
            * `invalid_query`
42
        schema:
43
          $ref: "../swagger.yaml#/definitions/error"
44
      403:
45
        description: Access forbidden
46
        schema:
47
          $ref: "../swagger.yaml#/definitions/error"
48
      500:
49
        description: |
50
          Internal server error. Possible `error_code` attribute values:
51
52
          * `internal_server_error`
53
        schema:
54
          $ref: "../swagger.yaml#/definitions/error"
55
      503:
56
        description: Under maintenance
57
        schema:
58
          $ref: "../swagger.yaml#/definitions/error"
59
    x-koha-authorization:
60
      permissions:
61
        ill: 1
62
(-)a/api/v1/swagger/swagger.yaml (+5 lines)
Lines 439-444 paths: Link Here
439
    $ref: ./paths/ill_batchstatuses.yaml#/~1ill~1batchstatuses
439
    $ref: ./paths/ill_batchstatuses.yaml#/~1ill~1batchstatuses
440
  "/ill/batchstatuses/{ill_batchstatus_code}":
440
  "/ill/batchstatuses/{ill_batchstatus_code}":
441
    $ref: "./paths/ill_batchstatuses.yaml#/~1ill~1batchstatuses~1{ill_batchstatus_code}"
441
    $ref: "./paths/ill_batchstatuses.yaml#/~1ill~1batchstatuses~1{ill_batchstatus_code}"
442
  /ill/users:
443
    $ref: ./paths/ill_users.yaml#/~1ill~1users
442
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
444
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
443
    $ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen"
445
    $ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen"
444
  /import_batch_profiles:
446
  /import_batch_profiles:
Lines 1262-1267 tags: Link Here
1262
  - description: "Manage item groups\n"
1264
  - description: "Manage item groups\n"
1263
    name: item_groups
1265
    name: item_groups
1264
    x-displayName: Item groups
1266
    x-displayName: Item groups
1267
  - description: "Manage ILL users\n"
1268
    name: ill_users
1269
    x-displayName: ILL users
1265
  - description: "Manage record sources\n"
1270
  - description: "Manage record sources\n"
1266
    name: record_sources
1271
    name: record_sources
1267
    x-displayName: Record source
1272
    x-displayName: Record source
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-1 / +5 lines)
Lines 117-123 Link Here
117
[%# - Browse by last name %]
117
[%# - Browse by last name %]
118
[%# - The table %]
118
[%# - The table %]
119
[%# Get the following parameters: %]
119
[%# Get the following parameters: %]
120
[%# - filter: can be 'suggestions_managers', 'orders_managers', 'funds_owners', 'funds_users' or 'erm_users' to filter patrons on their permissions %]
120
[%# - filter: can be 'suggestions_managers', 'orders_managers', 'funds_owners', 'funds_users', 'erm_users' or 'ill_users' to filter patrons on their permissions %]
121
[%# - table_id: the ID of the table %]
121
[%# - table_id: the ID of the table %]
122
[%# open_on_row_click: See patron_search_js %]
122
[%# open_on_row_click: See patron_search_js %]
123
[%# columns: See patron_search_js %]
123
[%# columns: See patron_search_js %]
Lines 135-140 Link Here
135
        <div class="alert alert-info">Only staff with superlibrarian or acquisitions permissions (or budget_modify permission if granular permissions are enabled) are returned in the search results</div>
135
        <div class="alert alert-info">Only staff with superlibrarian or acquisitions permissions (or budget_modify permission if granular permissions are enabled) are returned in the search results</div>
136
    [% ELSIF filter == 'erm_users' %]
136
    [% ELSIF filter == 'erm_users' %]
137
        <div class="alert alert-info">Only staff with superlibrarian or ERM permissions are returned in the search results</div>
137
        <div class="alert alert-info">Only staff with superlibrarian or ERM permissions are returned in the search results</div>
138
    [% ELSIF filter == 'ill_users' %]
139
        <div class="alert alert-info">Only staff with superlibrarian or ILL permissions are returned in the search results</div>
138
    [% END %]
140
    [% END %]
139
141
140
    <div class="browse">
142
    <div class="browse">
Lines 341-346 Link Here
341
                let patron_search_url = '/api/v1/acquisitions/funds/users';
343
                let patron_search_url = '/api/v1/acquisitions/funds/users';
342
            [% CASE 'erm_users' %]
344
            [% CASE 'erm_users' %]
343
                let patron_search_url = '/api/v1/erm/users';
345
                let patron_search_url = '/api/v1/erm/users';
346
            [% CASE 'ill_users' %]
347
                let patron_search_url = '/api/v1/ill/users';
344
            [% CASE %]
348
            [% CASE %]
345
                let patron_search_url = '/api/v1/patrons';
349
                let patron_search_url = '/api/v1/patrons';
346
            [% END %]
350
            [% END %]
(-)a/t/db_dependent/api/v1/ill_users.t (-1 / +107 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::NoWarnings;
21
use Test::More tests => 2;
22
use Test::Mojo;
23
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
26
27
use Koha::Patron::Attributes;
28
use Koha::Database;
29
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
my $t = Test::Mojo->new('Koha::REST::V1');
34
t::lib::Mocks::mock_preference( 'RESTBasicAuth',       1 );
35
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 );
36
37
subtest 'list() tests' => sub {
38
39
    plan tests => 14;
40
41
    $schema->storage->txn_begin;
42
43
    my $patron_category =
44
        $builder->build( { source => 'Category', value => { category_type => 'A', can_be_guarantee => 0 } } )
45
        ->{categorycode};
46
47
    Koha::Patrons->search->update( { flags => 0, categorycode => $patron_category } );
48
    $schema->resultset('UserPermission')->delete;
49
50
    my $librarian = $builder->build_object(
51
        {
52
            class => 'Koha::Patrons',
53
            value => { flags => 2**22 }
54
        }
55
    );
56
57
    my $password = 'thePassword123';
58
    $librarian->set_password( { password => $password, skip_validation => 1 } );
59
    my $userid = $librarian->userid;
60
61
    ## Authorized user tests
62
    # One erm_user created, should get returned
63
    $librarian->discard_changes;
64
    $t->get_ok("//$userid:$password@/api/v1/ill/users")->status_is(200)
65
        ->json_is( [ $librarian->to_api( { user => $librarian } ) ] );
66
67
    my $another_erm_user = $builder->build_object(
68
        {
69
            class => 'Koha::Patrons',
70
            value => { flags => 2**22 }
71
        }
72
    );
73
74
    # Two erm_users created, only self is returned without permission to view_any_borrower
75
    $t->get_ok("//$userid:$password@/api/v1/ill/users")->status_is(200)
76
        ->json_is( [ $librarian->to_api( { user => $librarian } ) ] );
77
78
    my $dbh = C4::Context->dbh;
79
    $dbh->do(
80
        q{INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, ?, ?)}, undef,
81
        ( $librarian->borrowernumber, 4, 'view_borrower_infos_from_any_libraries' )
82
    );
83
84
    # Two erm_users created, they should both be returned
85
    $t->get_ok("//$userid:$password@/api/v1/ill/users")->status_is(200)
86
        ->json_is(
87
        [ $librarian->to_api( { user => $librarian } ), $another_erm_user->to_api( { user => $another_erm_user } ) ] );
88
89
    # Warn on unsupported query parameter
90
    $t->get_ok("//$userid:$password@/api/v1/ill/users?blah=blah")->status_is(400)
91
        ->json_is( [ { path => '/query/blah', message => 'Malformed query string' } ] );
92
93
    my $patron = $builder->build_object(
94
        {
95
            class => 'Koha::Patrons',
96
            value => { flags => 0 }
97
        }
98
    );
99
100
    $patron->set_password( { password => $password, skip_validation => 1 } );
101
    my $unauth_userid = $patron->userid;
102
103
    # Unauthorized access
104
    $t->get_ok("//$unauth_userid:$password@/api/v1/ill/users")->status_is(403);
105
106
    $schema->storage->txn_rollback;
107
};

Return to bug 40504