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

(-)a/Koha/REST/V1/ItemTypes.pm (+48 lines)
Line 0 Link Here
1
package Koha::REST::V1::ItemTypes;
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 <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::ItemTypes;
23
24
use Try::Tiny;
25
26
=head1 API
27
28
=head2 Methods
29
30
=head3 list
31
32
=cut
33
34
sub list {
35
    my $c = shift->openapi->valid_input or return;
36
37
    return try {
38
        my $itemtypes_set = Koha::ItemTypes->new;
39
        my $itemtypes     = $c->objects->search( $itemtypes_set, { embed => $c->stash('koha.embed') } );
40
41
        return $c->render( status => 200, openapi => $itemtypes );
42
    } catch {
43
        $c->unhandled_exception($_);
44
    };
45
46
}
47
48
1;
(-)a/api/v1/swagger/definitions/itemtype.yaml (+96 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  itemtype:
5
    type: string
6
    description: Unique key, a code associated with the item type
7
    readOnly: true
8
  parent_type:
9
    description: Unique key, a code associated with the parent item type
10
    type:
11
      - string
12
      - "null"
13
  description:
14
    description: A plain text explanation of the item type
15
    type: string
16
  rentalcharge:
17
    description: The amount charged when this item is checked out/issued
18
    type:
19
      - number
20
      - "null"
21
  rentalcharge_daily:
22
    description: The amount charged for each day between checkout date and due date
23
    type:
24
      - number
25
      - "null"
26
  rentalcharge_daily_calendar:
27
    description: Controls if the daily rental fee is calculated directly or using finesCalendar
28
    type: boolean
29
  rentalcharge_hourly:
30
    description: The amount charged for each hour between checkout date and due date
31
    type:
32
      - number
33
      - "null"
34
  rentalcharge_hourly_calendar:
35
    description: Controls if the hourly rental fee is calculated directly or using finesCalendar
36
    type: boolean
37
  defaultreplacecost:
38
    description: Default replacement cost
39
    type:
40
      - number
41
      - "null"
42
  processfee:
43
    description: Default text be recorded in the column note when the processing fee is applied
44
    type:
45
      - number
46
      - "null"
47
  notforloan:
48
    description: Controls if the item is available for loan
49
    type:
50
      - boolean
51
      - "null"
52
  imageurl:
53
    description: URL for the item type icon
54
    type:
55
      - string
56
      - "null"
57
  summary:
58
    description: Information from the summary field, may include HTML
59
    type:
60
      - string
61
      - "null"
62
  checkinmsg:
63
    description: Message that is displayed when an item with the given item type is checked in
64
    type:
65
      - string
66
      - "null"
67
  checkinmsgtype:
68
    description: Type (CSS class) for the checkinmsg, can be 'alert' or 'message'
69
    type:
70
      - string
71
      - "null"
72
  sip_media_type:
73
    description: SIP2 protocol media type for this itemtype
74
    type:
75
      - string
76
      - "null"
77
  hideinopac:
78
    description: Hide the item type from the search options in OPAC
79
    type: boolean
80
  searchcategory:
81
    description: Group this item type with others with the same value on OPAC search options
82
    type:
83
      - string
84
      - "null"
85
  automatic_checkin:
86
    description: Controls if automatic checkin is enabled for items of this type
87
    type: boolean
88
  translated_descriptions:
89
    description: Translations of description plain text
90
    type: array
91
    items:
92
      $ref: "itemtype_translated_description.yaml"
93
94
additionalProperties: false
95
required:
96
  - itemtype
(-)a/api/v1/swagger/definitions/itemtype_translated_description.yaml (+13 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  lang:
5
    description: Language identifier
6
    type: string
7
  translation:
8
    description: Translated plain text
9
    type: string
10
additionalProperties: false
11
required:
12
  - lang
13
  - translation
(-)a/api/v1/swagger/paths/itemtypes.yaml (+59 lines)
Line 0 Link Here
1
---
2
/itemtypes:
3
  get:
4
    x-mojo-to: ItemTypes#list
5
    operationId: listItemTypes
6
    tags:
7
      - itemtypes
8
    summary: List item types
9
    produces:
10
      - application/json
11
    parameters:
12
      - name: x-koha-embed
13
        in: header
14
        required: false
15
        description: Embed list sent as a request header
16
        type: array
17
        items:
18
          type: string
19
          enum:
20
            - translated_descriptions
21
        collectionFormat: csv
22
      - $ref: "../swagger.yaml#/parameters/match"
23
      - $ref: "../swagger.yaml#/parameters/order_by"
24
      - $ref: "../swagger.yaml#/parameters/page"
25
      - $ref: "../swagger.yaml#/parameters/per_page"
26
      - $ref: "../swagger.yaml#/parameters/q_param"
27
      - $ref: "../swagger.yaml#/parameters/q_body"
28
    responses:
29
      200:
30
        description: A list of itemtypes
31
        schema:
32
          items:
33
            $ref: "../swagger.yaml#/definitions/itemtype"
34
          type: array
35
      400:
36
        description: Bad request
37
        schema:
38
          $ref: "../swagger.yaml#/definitions/error"
39
      403:
40
        description: Access forbidden
41
        schema:
42
          $ref: "../swagger.yaml#/definitions/error"
43
      404:
44
        description: Resource not found
45
        schema:
46
          $ref: "../swagger.yaml#/definitions/error"
47
      500:
48
        description: |-
49
          Internal server error. Possible `error_code` attribute values:
50
          * `internal_server_error`
51
        schema:
52
          $ref: "../swagger.yaml#/definitions/error"
53
      503:
54
        description: Under maintenance
55
        schema:
56
          $ref: "../swagger.yaml#/definitions/error"
57
    x-koha-authorization:
58
      permissions:
59
        catalogue: 1
(-)a/api/v1/swagger/swagger.yaml (+7 lines)
Lines 84-89 definitions: Link Here
84
    $ref: ./definitions/item.yaml
84
    $ref: ./definitions/item.yaml
85
  item_group:
85
  item_group:
86
    $ref: ./definitions/item_group.yaml
86
    $ref: ./definitions/item_group.yaml
87
  itemtype:
88
    $ref: ./definitions/itemtype.yaml
87
  job:
89
  job:
88
    $ref: ./definitions/job.yaml
90
    $ref: ./definitions/job.yaml
89
  library:
91
  library:
Lines 299-304 paths: Link Here
299
    $ref: ./paths/import_batch_profiles.yaml#/~1import_batch_profiles
301
    $ref: ./paths/import_batch_profiles.yaml#/~1import_batch_profiles
300
  "/import_batch_profiles/{import_batch_profile_id}":
302
  "/import_batch_profiles/{import_batch_profile_id}":
301
    $ref: "./paths/import_batch_profiles.yaml#/~1import_batch_profiles~1{import_batch_profile_id}"
303
    $ref: "./paths/import_batch_profiles.yaml#/~1import_batch_profiles~1{import_batch_profile_id}"
304
  /itemtypes:
305
    $ref: ./paths/itemtypes.yaml#/~1itemtypes
302
  /items:
306
  /items:
303
    $ref: ./paths/items.yaml#/~1items
307
    $ref: ./paths/items.yaml#/~1items
304
  "/items/{item_id}":
308
  "/items/{item_id}":
Lines 945-950 tags: Link Here
945
  - description: "Manage items\n"
949
  - description: "Manage items\n"
946
    name: items
950
    name: items
947
    x-displayName: Items
951
    x-displayName: Items
952
  - description: "Manage item types\n"
953
    name: itemtypes
954
    x-displayName: Item Types
948
  - description: "Manage jobs\n"
955
  - description: "Manage jobs\n"
949
    name: jobs
956
    name: jobs
950
    x-displayName: Jobs
957
    x-displayName: Jobs
(-)a/t/db_dependent/api/v1/itemtypes.t (-1 / +142 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 <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
use Test::Mojo;
22
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
26
use Koha::ItemTypes;
27
use Koha::Database;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
my $t = Test::Mojo->new('Koha::REST::V1');
33
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
34
35
subtest 'list_itemtypes() tests' => sub {
36
37
    plan tests => 12;
38
39
    $schema->storage->txn_begin;
40
41
    my $itemtype = $builder->build_object(
42
        {
43
            class => 'Koha::ItemTypes',
44
            value => {
45
                itemtype                     => 'TEST_IT',
46
                parent_type                  => undef,
47
                description                  => 'Test itemtype',
48
                rentalcharge                 => 100.0,
49
                rentalcharge_daily           => 50.,
50
                rentalcharge_daily_calendar  => 0,
51
                rentalcharge_hourly          => 0.60,
52
                rentalcharge_hourly_calendar => 1,
53
                defaultreplacecost           => 1000.0,
54
                processfee                   => 20.0,
55
                notforloan                   => 0,
56
                imageurl          => 'https://upload.wikimedia.org/wikipedia/commons/1/1f/202208_test-tube-4.svg',
57
                summary           => 'An itemtype for testing',
58
                checkinmsg        => 'Checking in test',
59
                checkinmsgtype    => 'message',
60
                sip_media_type    => 'spt',
61
                hideinopac        => 1,
62
                searchcategory    => 'test search category',
63
                automatic_checkin => 0,
64
            }
65
        }
66
    );
67
68
    my $en = $builder->build_object(
69
        {
70
            class => 'Koha::Localizations',
71
            value => {
72
                entity      => 'itemtypes',
73
                code        => 'TEST_IT',
74
                lang        => 'en',
75
                translation => 'English word "test"',
76
            }
77
        }
78
    );
79
    my $sv = $builder->build_object(
80
        {
81
            class => 'Koha::Localizations',
82
            value => {
83
                entity      => 'itemtypes',
84
                code        => 'TEST_IT',
85
                lang        => 'sv_SE',
86
                translation => 'Swedish word "test"',
87
            }
88
        }
89
    );
90
91
    my $librarian = $builder->build_object(
92
        {
93
            class => 'Koha::Patrons',
94
            value => { flags => 2**2 }    # catalogue flag = 2
95
        }
96
    );
97
    my $password = 'thePassword123';
98
    $librarian->set_password( { password => $password, skip_validation => 1 } );
99
    my $userid = $librarian->userid;
100
101
    my $patron = $builder->build_object(
102
        {
103
            class => 'Koha::Patrons',
104
            value => { flags => 0 }
105
        }
106
    );
107
108
    $patron->set_password( { password => $password, skip_validation => 1 } );
109
    my $unauth_userid = $patron->userid;
110
111
    ## Authorized user tests
112
    # No category, 404 expected
113
    $t->get_ok("//$userid:$password@/api/v1/itemtypes")->status_is(200)->json_has('/0');
114
115
    for my $json ( @{ $t->tx->res->json } ) {
116
        if ( $json->{itemtype} eq 'TEST_IT' ) {
117
            is( $json->{description}, 'Test itemtype' );
118
            ok( !exists $json->{translated_descriptions} );
119
        }
120
    }
121
122
    $t->get_ok( "//$userid:$password@/api/v1/itemtypes" => { 'x-koha-embed' => 'translated_descriptions' } )
123
        ->status_is(200)->json_has('/0');
124
125
    for my $json ( @{ $t->tx->res->json } ) {
126
        if ( $json->{itemtype} eq 'TEST_IT' ) {
127
            is( $json->{description}, 'Test itemtype' );
128
            is_deeply(
129
                $json->{translated_descriptions},
130
                [
131
                    { lang => 'en',    translation => 'English word "test"' },
132
                    { lang => 'sv_SE', translation => 'Swedish word "test"' },
133
                ]
134
            );
135
        }
136
    }
137
138
    # Unauthorized access
139
    $t->get_ok("//$unauth_userid:$password@/api/v1/itemtypes")->status_is(403);
140
141
    $schema->storage->txn_rollback;
142
};

Return to bug 34008