Bug 16825 - REST API: Add API route for getting an item
Summary: REST API: Add API route for getting an item
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Web services (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Lari Taskula
QA Contact: Testopia
URL:
Whiteboard:
Keywords:
Depends on: 18137
Blocks: 16652 16826 18191
  Show dependency treegraph
 
Reported: 2016-06-28 14:17 UTC by Lari Taskula
Modified: 2017-07-12 12:10 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 16825: Add API route for getting an item (14.27 KB, patch)
2016-06-29 09:14 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: Add API route for getting an item (13.55 KB, patch)
2016-06-29 15:39 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: Add API route for getting an item (13.50 KB, patch)
2016-07-01 15:58 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: Add API route for getting an item (13.55 KB, patch)
2016-07-05 18:36 UTC, Jiri Kozlovsky
Details | Diff | Splinter Review
Bug 16825: Add API route for getting an item (13.54 KB, patch)
2016-07-05 19:05 UTC, Jiri Kozlovsky
Details | Diff | Splinter Review
Bug 16825: Add API route for getting an item (13.63 KB, patch)
2016-07-08 11:57 UTC, Benjamin Rokseth
Details | Diff | Splinter Review
Bug 16825: (followup) Add API route for getting an item (2.00 KB, patch)
2016-08-01 13:42 UTC, Jiri Kozlovsky
Details | Diff | Splinter Review
Bug 16826: [QA Follow-up] Add 'new_status' to Swagger definition (2.15 KB, patch)
2016-08-02 16:26 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition (2.14 KB, patch)
2016-08-02 19:04 UTC, Jiri Kozlovsky
Details | Diff | Splinter Review
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition (868 bytes, patch)
2016-08-05 14:59 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: (followup) Add API route for getting an item (2.05 KB, patch)
2016-08-22 12:44 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition (868 bytes, patch)
2016-08-22 12:44 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: Add API route for getting an item (14.83 KB, patch)
2016-10-11 07:13 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: Add API route for getting an item (14.97 KB, patch)
2016-10-11 07:16 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: (followup) Add API route for getting an item (2.05 KB, patch)
2016-10-11 07:17 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition (1.19 KB, patch)
2016-10-11 07:22 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition (1.20 KB, patch)
2016-10-11 08:02 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition (1.20 KB, patch)
2016-10-11 08:04 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: Add API route for getting an item (14.84 KB, patch)
2016-10-12 14:29 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: (followup) Add API route for getting an item (2.05 KB, patch)
2016-10-12 14:30 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition (1.09 KB, patch)
2016-10-12 14:30 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16825: Add API route for getting an item (19.16 KB, patch)
2017-03-16 16:38 UTC, Lari Taskula
Details | Diff | Splinter Review
[SIGNED-OFF] Bug 16825: Add API route for getting an item (19.23 KB, patch)
2017-06-14 08:36 UTC, Josef Moravec
Details | Diff | Splinter Review
Bug 16825: (squashable) Fix test cleanup issues (1.61 KB, patch)
2017-07-12 12:10 UTC, Lari Taskula
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lari Taskula 2016-06-28 14:17:49 UTC
Add API route for getting an item

GET /api/v1/items/{itemnumber} Gets one Item
Comment 1 Lari Taskula 2016-06-29 09:14:29 UTC Comment hidden (obsolete)
Comment 2 Lari Taskula 2016-06-29 15:39:25 UTC Comment hidden (obsolete)
Comment 3 Lari Taskula 2016-07-01 15:58:18 UTC Comment hidden (obsolete)
Comment 4 Jiri Kozlovsky 2016-07-05 18:36:00 UTC Comment hidden (obsolete)
Comment 5 Jiri Kozlovsky 2016-07-05 19:05:23 UTC Comment hidden (obsolete)
Comment 6 Benjamin Rokseth 2016-07-08 11:57:14 UTC
Created attachment 53222 [details] [review]
Bug 16825: Add API route for getting an item

GET /api/v1/items/{itemnumber} Gets one Item

This patch adds route to get one item from koha.items table. This table has
a column "itemnotes_nonpublic", which should not be returned if the user has no
catalogue permission.

To test:
1. Open a browser tab on Koha staff and log in (to create CGISESSID
   cookie).
2. Send GET request to http://yourlibrary/api/v1/items/YYY
   where YYY is an existing itemnumber.
3. Make sure the returned data is correct.
4. Run unit tests in t/db_dependent/api/v1/items.t

Signed-off-by: jirislav <mail@jkozlovsky.cz>
Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>
Comment 7 Jiri Kozlovsky 2016-08-01 13:42:16 UTC Comment hidden (obsolete)
Comment 8 Jonathan Druart 2016-08-02 11:50:54 UTC
items.new_status is missing in the swagger file.
Please have a look at bug 15126 comment 53.
We need a way to keep this file up-to-date.
Comment 9 Lari Taskula 2016-08-02 16:26:19 UTC Comment hidden (obsolete)
Comment 10 Lari Taskula 2016-08-02 16:34:43 UTC
I created Bug 17032 to add similar tests for what's already in master.
Comment 11 Jiri Kozlovsky 2016-08-02 19:04:58 UTC Comment hidden (obsolete)
Comment 12 Jonathan Druart 2016-08-03 08:03:35 UTC
(In reply to Lari Taskula from comment #9)
> Also, to avoid forgotten columns in definitions, adds a test to
> compare item-definition to database's items-table.

Lari, thanks for that!
Do you think you could provide a global check?
It would look at the api/v1/definitions/*.json files and compare the columns with Koha::Objects->columns (added by bug 16889).
Comment 13 Lari Taskula 2016-08-03 15:33:53 UTC
(In reply to Jiri Kozlovsky from comment #11)
> Lari: You have probably changed in your comment bug ID for 16826
> https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=16825#c9

Indeed. Sorry about that!

(In reply to Jonathan Druart from comment #12)
> (In reply to Lari Taskula from comment #9)
> > Also, to avoid forgotten columns in definitions, adds a test to
> > compare item-definition to database's items-table.
> 
> Lari, thanks for that!
> Do you think you could provide a global check?
> It would look at the api/v1/definitions/*.json files and compare the columns
> with Koha::Objects->columns (added by bug 16889).

As discussed on IRC, I have provided a test that does this, in Bug 17032.
Comment 14 Lari Taskula 2016-08-05 14:59:19 UTC Comment hidden (obsolete)
Comment 15 Lari Taskula 2016-08-22 12:44:05 UTC
Created attachment 54686 [details] [review]
Bug 16825: (followup) Add API route for getting an item

Fixed tab-character.

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>

Signed-off-by: Lari Taskula <larit@student.uef.fi>
Comment 16 Lari Taskula 2016-08-22 12:44:27 UTC
Created attachment 54687 [details] [review]
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition

Adds missing "new_status" to item's Swagger definition.

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Comment 17 Lari Taskula 2016-10-11 07:13:02 UTC
Created attachment 56122 [details] [review]
Bug 16825: Add API route for getting an item

GET /api/v1/items/{itemnumber} Gets one Item

This patch adds route to get one item from koha.items table. This table has
a column "itemnotes_nonpublic", which should not be returned if the user has no
catalogue permission.

To test:
1. Open a browser tab on Koha staff and log in (to create CGISESSID
   cookie).
2. Send GET request to http://yourlibrary/api/v1/items/YYY
   where YYY is an existing itemnumber.
3. Make sure the returned data is correct.
4. Run unit tests in t/db_dependent/api/v1/items.t

Signed-off-by: jirislav <mail@jkozlovsky.cz>
Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>
Comment 18 Lari Taskula 2016-10-11 07:16:40 UTC
Created attachment 56123 [details] [review]
Bug 16825: Add API route for getting an item

GET /api/v1/items/{itemnumber} Gets one Item

This patch adds route to get one item from koha.items table. This table has
a column "itemnotes_nonpublic", which should not be returned if the user has no
catalogue permission.

To test:
1. Apply patch and run minifySwagger.pl
   perl misc/devel/minifySwagger.pl -s api/v1/swagger/swagger.json -d api/v1/swagger/swagger.min.json
2. Open a browser tab on Koha staff and log in (to create CGISESSID
   cookie).
3. Send GET request to http://yourlibrary/api/v1/items/YYY
   where YYY is an existing itemnumber.
4. Make sure the returned data is correct.
5. Run unit tests in t/db_dependent/api/v1/items.t

Signed-off-by: jirislav <mail@jkozlovsky.cz>
Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>
Comment 19 Lari Taskula 2016-10-11 07:17:17 UTC
Created attachment 56124 [details] [review]
Bug 16825: (followup) Add API route for getting an item

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>

Signed-off-by: Lari Taskula <larit@student.uef.fi>
Comment 20 Lari Taskula 2016-10-11 07:22:16 UTC
Created attachment 56125 [details] [review]
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition

Adds missing "new_status" to item's Swagger definition.

To test:
1. Run t/db_dependent/api/v1/swagger/definitions.t
2. Observe that test fails because of missing new_status.
3. Apply patch and test again
4. Observe that test no longer complains about new_status.

(minify swagger)
perl misc/devel/minifySwagger.pl -s api/v1/swagger/swagger.json -d api/v1/swagger

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Comment 21 Lari Taskula 2016-10-11 07:24:31 UTC
Rebased on top of master and added Swagger-minifying into test plan.
Comment 22 Lari Taskula 2016-10-11 08:02:38 UTC
Created attachment 56131 [details] [review]
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Comment 23 Lari Taskula 2016-10-11 08:04:16 UTC
Created attachment 56133 [details] [review]
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition

Adds missing "new_status" to item's Swagger definition.

To test:
1. Run t/db_dependent/api/v1/swagger/definitions.t
2. Observe that test fails because of missing new_status.
3. Apply patch and test again
4. Observe that test no longer complains about new_status.

(minify swagger)
perl misc/devel/minifySwagger.pl -s api/v1/swagger/swagger.json -d api/v1/swagger/swagger.min.json

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>

Fixed a typo in minifying command.
Comment 24 Lari Taskula 2016-10-12 14:29:31 UTC
Created attachment 56290 [details] [review]
Bug 16825: Add API route for getting an item

GET /api/v1/items/{itemnumber} Gets one Item

This patch adds route to get one item from koha.items table. This table has
a column "itemnotes_nonpublic", which should not be returned if the user has no
catalogue permission.

To test:
1. Apply patch
2. Open a browser tab on Koha staff and log in (to create CGISESSID
   cookie).
3. Send GET request to http://yourlibrary/api/v1/items/YYY
   where YYY is an existing itemnumber.
4. Make sure the returned data is correct.
5. Run unit tests in t/db_dependent/api/v1/items.t

Signed-off-by: jirislav <mail@jkozlovsky.cz>
Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>
Comment 25 Lari Taskula 2016-10-12 14:30:32 UTC
Created attachment 56292 [details] [review]
Bug 16825: (followup) Add API route for getting an item

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>

Signed-off-by: Lari Taskula <larit@student.uef.fi>
Comment 26 Lari Taskula 2016-10-12 14:30:48 UTC
Created attachment 56293 [details] [review]
Bug 16825: [QA Follow-up] Add 'new_status' to Swagger definition

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Comment 27 Lari Taskula 2016-10-12 14:31:07 UTC
Removed minifying step from test plan after Bug 17432.
Comment 28 Lari Taskula 2017-03-16 16:38:52 UTC
Created attachment 61176 [details] [review]
Bug 16825: Add API route for getting an item

GET /api/v1/items/{itemnumber} Gets one Item

This patch adds route to get one item from koha.items table. This table has
a column "itemnotes_nonpublic", which should not be returned if the user has no
catalogue permission.

The OpacHiddenItems syspref restriction is considered for users who are not staff.
They see "Item Not Found" when trying to view item hidden from OPAC. Only staff
can see those items.

To test:
1. Apply patch
2. Open a browser tab on Koha staff and log in (to create CGISESSID
   cookie).
3. Send GET request to http://yourlibrary/api/v1/items/YYY
   where YYY is an existing itemnumber.
4. Make sure the returned data is correct.
5. Run unit tests in t/db_dependent/api/v1/items.t
Comment 29 Lari Taskula 2017-03-16 16:41:12 UTC
Rewritten, now Mojolicious::Plugin::OpenAPI compatible.
Comment 30 Lari Taskula 2017-03-16 17:03:22 UTC
(In reply to Lari Taskula from comment #29)
> Rewritten, now Mojolicious::Plugin::OpenAPI compatible.

Forgot to include this in the previous comment - Additional note for testers: requires JSON::Validator version 0.96, otherwise tests fail for the following reason: 

GET /api/v1/items/340856 [{"message":"Does not match date-time format.","path":"\/timestamp"},{"message":"anyOf failed: Does not match date-time format.","path":"\/itemlost_on"},{"message":"anyOf failed: Does not match date-time format.","path":"\/withdrawn_on"}].
Comment 31 Josef Moravec 2017-06-14 08:36:28 UTC
Created attachment 64275 [details] [review]
[SIGNED-OFF] Bug 16825: Add API route for getting an item

GET /api/v1/items/{itemnumber} Gets one Item

This patch adds route to get one item from koha.items table. This table has
a column "itemnotes_nonpublic", which should not be returned if the user has no
catalogue permission.

The OpacHiddenItems syspref restriction is considered for users who are not staff.
They see "Item Not Found" when trying to view item hidden from OPAC. Only staff
can see those items.

To test:
1. Apply patch
2. Open a browser tab on Koha staff and log in (to create CGISESSID
   cookie).
3. Send GET request to http://yourlibrary/api/v1/items/YYY
   where YYY is an existing itemnumber.
4. Make sure the returned data is correct.
5. Run unit tests in t/db_dependent/api/v1/items.t

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 32 Katrin Fischer 2017-06-15 20:31:12 UTC
Excluding itemnotes_nonpublic is good thinking, but what about other fields that are set to not display in the OPAC in the frameworks?

I know we got some libraries using more_subfields_xml to store additional information that is not for thought to be seen by normal users.
I think those should only show if you have catalogue permission.
Comment 33 Lari Taskula 2017-07-12 12:10:57 UTC
Created attachment 65007 [details] [review]
Bug 16825: (squashable) Fix test cleanup issues

Roll back failed at the end of the test. Apply this patch to fix the issue.

To test:
1. prove t/db_dependent/api/v1/items.t
2. Check your database to make sure nothing persists after the test