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

(-)a/Koha/REST/V1/Item.pm (+45 lines)
Line 0 Link Here
1
package Koha::REST::V1::Item;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
use Mojo::JSON;
22
23
use C4::Auth qw( haspermission );
24
25
use Koha::Items;
26
27
sub get {
28
    my ($c, $args, $cb) = @_;
29
30
    my $itemnumber = $c->param('itemnumber');
31
    my $item = Koha::Items->find($itemnumber);
32
    unless ($item) {
33
        return $c->$cb({error => "Item not found"}, 404);
34
    }
35
36
    # Hide non-public itemnotes if user has no staff access
37
    my $user = $c->stash('koha.user');
38
    unless ($user && haspermission($user->userid, {catalogue => 1})) {
39
        $item->set({ itemnotes_nonpublic => undef });
40
    }
41
42
    return $c->$cb($item->unblessed, 200);
43
}
44
45
1;
(-)a/api/v1/definitions/index.json (+1 lines)
Lines 2-6 Link Here
2
    "patron": { "$ref": "patron.json" },
2
    "patron": { "$ref": "patron.json" },
3
    "holds": { "$ref": "holds.json" },
3
    "holds": { "$ref": "holds.json" },
4
    "hold": { "$ref": "hold.json" },
4
    "hold": { "$ref": "hold.json" },
5
    "item": { "$ref": "item.json" },
5
    "error": { "$ref": "error.json" }
6
    "error": { "$ref": "error.json" }
6
}
7
}
(-)a/api/v1/definitions/item.json (+177 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "itemnumber": {
5
      "type": "string",
6
      "description": "internally assigned item identifier"
7
    },
8
    "biblionumber": {
9
      "type": "string",
10
      "description": "internally assigned biblio identifier"
11
    },
12
    "biblioitemnumber": {
13
      "type": "string",
14
      "description": "internally assigned biblio item identifier"
15
    },
16
    "barcode": {
17
      "type": ["string", "null"],
18
      "description": "item barcode"
19
    },
20
    "dateaccessioned": {
21
      "type": ["string", "null"],
22
      "description": "date the item was acquired or added to Koha"
23
    },
24
    "booksellerid": {
25
      "type": ["string", "null"],
26
      "description": "where the item was purchased"
27
    },
28
    "homebranch": {
29
      "type": ["string", "null"],
30
      "description": "library that owns this item"
31
    },
32
    "price": {
33
      "type": ["string", "null"],
34
      "description": "purchase price"
35
    },
36
    "replacementprice": {
37
      "type": ["string", "null"],
38
      "description": "cost the library charges to replace the item if it has been marked lost"
39
    },
40
    "replacementpricedate": {
41
      "type": ["string", "null"],
42
      "description": "the date the price is effective from"
43
    },
44
    "datelastborrowed": {
45
      "type": ["string", "null"],
46
      "description": "the date the item was last checked out/issued"
47
    },
48
    "datelastseen": {
49
      "type": ["string", "null"],
50
      "description": "the date the item was last see (usually the last time the barcode was scanned or inventory was done)"
51
    },
52
    "stack": {
53
      "type": ["string", "null"],
54
      "description": "?"
55
    },
56
    "notforloan": {
57
      "type": "string",
58
      "description": "authorized value defining why this item is not for loan"
59
    },
60
    "damaged": {
61
      "type": "string",
62
      "description": "authorized value defining this item as damaged"
63
    },
64
    "itemlost": {
65
      "type": "string",
66
      "description": "authorized value defining this item as lost"
67
    },
68
    "itemlost_on": {
69
      "type": ["string", "null"],
70
      "description": "the date and time an item was last marked as lost, NULL if not lost"
71
    },
72
    "withdrawn": {
73
      "type": "string",
74
      "description": "authorized value defining this item as withdrawn"
75
    },
76
    "withdrawn_on": {
77
      "type": ["string", "null"],
78
      "description": "the date and time an item was last marked as withdrawn, NULL if not withdrawn"
79
    },
80
    "itemcallnumber": {
81
      "type": ["string", "null"],
82
      "description": "call number for this item"
83
    },
84
    "coded_location_qualifier": {
85
      "type": ["string", "null"],
86
      "description": "coded location qualifier"
87
    },
88
    "issues": {
89
      "type": ["string", "null"],
90
      "description": "number of times this item has been checked out/issued"
91
    },
92
    "renewals": {
93
      "type": ["string", "null"],
94
      "description": "number of times this item has been renewed"
95
    },
96
    "reserves": {
97
      "type": ["string", "null"],
98
      "description": "number of times this item has been placed on hold/reserved"
99
    },
100
    "restricted": {
101
      "type": ["string", "null"],
102
      "description": "authorized value defining use restrictions for this item"
103
    },
104
    "itemnotes": {
105
      "type": ["string", "null"],
106
      "description": "public notes on this item"
107
    },
108
    "itemnotes_nonpublic": {
109
      "type": ["string", "null"],
110
      "description": "non-public notes on this item"
111
    },
112
    "holdingbranch": {
113
      "type": ["string", "null"],
114
      "description": "library that is currently in possession item"
115
    },
116
    "paidfor": {
117
      "type": ["string", "null"],
118
      "description": "?"
119
    },
120
    "timestamp": {
121
      "type": "string",
122
      "description": "date and time this item was last altered"
123
    },
124
    "location": {
125
      "type": ["string", "null"],
126
      "description": "authorized value for the shelving location for this item"
127
    },
128
    "permanent_location": {
129
      "type": ["string", "null"],
130
      "description": "linked to the CART and PROC temporary locations feature, stores the permanent shelving location"
131
    },
132
    "onloan": {
133
      "type": ["string", "null"],
134
      "description": "defines if item is checked out (NULL for not checked out, and checkout date for checked out)"
135
    },
136
    "cn_source": {
137
      "type": ["string", "null"],
138
      "description": "classification source used on this item"
139
    },
140
    "cn_sort": {
141
      "type": ["string", "null"],
142
      "description": "?"
143
    },
144
    "ccode": {
145
      "type": ["string", "null"],
146
      "description": "authorized value for the collection code associated with this item"
147
    },
148
    "materials": {
149
      "type": ["string", "null"],
150
      "description": "materials specified"
151
    },
152
    "uri": {
153
      "type": ["string", "null"],
154
      "description": "URL for the item"
155
    },
156
    "itype": {
157
      "type": ["string", "null"],
158
      "description": "itemtype defining the type for this item"
159
    },
160
    "more_subfields_xml": {
161
      "type": ["string", "null"],
162
      "description": "additional 952 subfields in XML format"
163
    },
164
    "enumchron": {
165
      "type": ["string", "null"],
166
      "description": "serial enumeration/chronology for the item"
167
    },
168
    "copynumber": {
169
      "type": ["string", "null"],
170
      "description": "copy number"
171
    },
172
    "stocknumber": {
173
      "type": ["string", "null"],
174
      "description": "inventory number"
175
    }
176
  }
177
}
(-)a/api/v1/swagger.json (+32 lines)
Lines 231-236 Link Here
231
          }
231
          }
232
        }
232
        }
233
      }
233
      }
234
    },
235
    "/items/{itemnumber}": {
236
      "get": {
237
        "operationId": "getItem",
238
        "tags": ["items"],
239
        "parameters": [
240
          { "$ref": "#/parameters/itemnumberPathParam" }
241
        ],
242
        "consumes": ["application/json"],
243
        "produces": ["application/json"],
244
        "responses": {
245
          "200": {
246
            "description": "An item",
247
            "schema": { "$ref": "#/definitions/item" }
248
          },
249
          "400": {
250
            "description": "Missing or wrong parameters",
251
            "schema": { "$ref": "#/definitions/error" }
252
          },
253
          "404": {
254
            "description": "Item not found",
255
            "schema": { "$ref": "#/definitions/error" }
256
          }
257
        }
258
      }
234
    }
259
    }
235
  },
260
  },
236
  "definitions": {
261
  "definitions": {
Lines 250-255 Link Here
250
      "description": "Internal hold identifier",
275
      "description": "Internal hold identifier",
251
      "required": true,
276
      "required": true,
252
      "type": "integer"
277
      "type": "integer"
278
    },
279
    "itemnumberPathParam": {
280
      "name": "itemnumber",
281
      "in": "path",
282
      "description": "Internal item identifier",
283
      "required": true,
284
      "type": "integer"
253
    }
285
    }
254
  }
286
  }
255
}
287
}
(-)a/t/db_dependent/api/v1/items.t (-1 / +117 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# Copyright 2016 Koha-Suomi
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Test::More tests => 12;
23
use Test::Mojo;
24
use t::lib::TestBuilder;
25
26
use C4::Auth;
27
use C4::Biblio;
28
use C4::Context;
29
use C4::Items;
30
31
use Koha::Database;
32
use Koha::Patron;
33
use Koha::Items;
34
35
my $builder = t::lib::TestBuilder->new();
36
37
my $dbh = C4::Context->dbh;
38
$dbh->{AutoCommit} = 0;
39
$dbh->{RaiseError} = 1;
40
41
$ENV{REMOTE_ADDR} = '127.0.0.1';
42
my $t = Test::Mojo->new('Koha::REST::V1');
43
44
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
45
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
46
my $borrower = $builder->build({
47
    source => 'Borrower',
48
    value => {
49
        branchcode   => $branchcode,
50
        categorycode => $categorycode,
51
        flags => 16,
52
    }
53
});
54
55
my $librarian = $builder->build({
56
    source => "Borrower",
57
    value => {
58
        categorycode => $categorycode,
59
        branchcode => $branchcode,
60
        flags => 4,
61
    },
62
});
63
64
my ($session, $session2) = create_session($borrower, $librarian);
65
66
my $biblio = $builder->build({
67
    source => 'Biblio'
68
});
69
my $biblionumber = $biblio->{biblionumber};
70
my $item = $builder->build({
71
    source => 'Item',
72
    value => {
73
        biblionumber => $biblionumber,
74
    }
75
});
76
my $itemnumber = $item->{itemnumber};
77
78
my $nonExistentItemnumber = -14362719;
79
my $tx = $t->ua->build_tx(GET => "/api/v1/items/$nonExistentItemnumber");
80
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
81
$t->request_ok($tx)
82
  ->status_is(404);
83
84
$tx = $t->ua->build_tx(GET => "/api/v1/items/$itemnumber");
85
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
86
$t->request_ok($tx)
87
  ->status_is(200)
88
  ->json_is('/itemnumber' => $itemnumber)
89
  ->json_is('/biblionumber' => $biblionumber)
90
  ->json_is('/itemnotes_nonpublic' => undef);
91
92
$tx = $t->ua->build_tx(GET => "/api/v1/items/$itemnumber");
93
$tx->req->cookies({name => 'CGISESSID', value => $session2->id});
94
$t->request_ok($tx)
95
  ->status_is(200)
96
  ->json_is('/itemnumber' => $itemnumber)
97
  ->json_is('/biblionumber' => $biblionumber)
98
  ->json_is('/itemnotes_nonpublic' => $item->{itemnotes_nonpublic});
99
100
$dbh->rollback;
101
102
sub create_session {
103
    my (@borrowers) = @_;
104
105
    my @sessions;
106
    foreach $borrower (@borrowers) {
107
        my $session = C4::Auth::get_session('');
108
        $session->param('number', $borrower->{borrowernumber});
109
        $session->param('id', $borrower->{userid});
110
        $session->param('ip', '127.0.0.1');
111
        $session->param('lasttime', time());
112
        $session->flush;
113
        push @sessions, $session;
114
    }
115
116
    return @sessions;
117
}

Return to bug 16825