[Bug 42405] New: Add single cover image upload path
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Bug ID: 42405 Summary: Add single cover image upload path Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: tomascohen@gmail.com QA Contact: testopia@bugs.koha-community.org CC: tomascohen@gmail.com -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Andrew Fuerste-Henry <andrew@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |42643 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42643 [Bug 42643] [OMNIBUS] Assorted performance and stability work -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED CC| |dcook@prosentient.com.au, | |martin.renvoize@openfifth.c | |o.uk -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |42404 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42404 [Bug 42404] Add a batch cover images upload endpoint -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Comma delimited| |ByWater Solutions list of Sponsors| | Sponsorship status|--- |Sponsored Status|ASSIGNED |Needs Signoff Patch complexity|--- |Small patch -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #1 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 200147 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200147&action=edit Bug 42405: Add Koha::Biblio->add_cover_image and Koha::Item->add_cover_image This patch adds add_cover_image methods to Koha::Biblio and Koha::Item. Each method takes a GD::Image object, creates the scaled versions via Koha::CoverImage, and stores the result linked to the corresponding biblio or item. A MissingParameter exception is thrown if src_image is not provided. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/cover_images_single.t => SUCCESS: Tests pass! 3. Tests cover: - MissingParameter thrown when src_image is undef (biblio) - MissingParameter thrown when src_image is undef (item) 4. Sign off :-D Sponsored-by: ByWater Solutions -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #2 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 200148 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200148&action=edit Bug 42405: Add REST API endpoints for single cover image operations This patch adds three REST API endpoints: POST /api/v1/biblios/{biblio_id}/cover_images POST /api/v1/items/{item_id}/cover_images DELETE /api/v1/cover_images/{image_id} These replace the svc/cover_images CGI script with proper REST endpoints. Upload endpoints accept an image via multipart/form-data and an optional replace query parameter. Test plan: 1. Apply patch 2. Regenerate the API bundle: $ ktd --shell k$ cd /kohadevbox/koha && yarn api:bundle 3. Run: k$ prove t/db_dependent/api/v1/cover_images_single.t => SUCCESS: Tests pass! 4. Tests cover: - Successful biblio image upload (201) - Multiple images without replace - Replace mode deletes existing images - Biblio not found (404) - Successful item image upload (201) - Item not found (404) - Delete image (204) - Delete non-existent image (404) 5. Sign off :-D Sponsored-by: ByWater Solutions -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kyle@bywatersolutions.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |42804 Attachment #200147|0 |1 is obsolete| | Attachment #200148|0 |1 is obsolete| | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42804 [Bug 42804] Replace svc/cover_images and tools/upload-cover-image.pl with REST API -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #3 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 200153 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200153&action=edit Bug 42405: Add Koha::Biblio->add_cover_image and Koha::Item->add_cover_image This patch adds add_cover_image methods to Koha::Biblio and Koha::Item. Each method takes a GD::Image object, creates the scaled versions via Koha::CoverImage, and stores the result linked to the corresponding biblio or item. A MissingParameter exception is thrown if src_image is not provided. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/cover_images_single.t => SUCCESS: Tests pass! 3. Tests cover: - MissingParameter thrown when src_image is undef (biblio) - MissingParameter thrown when src_image is undef (item) 4. Sign off :-D Sponsored-by: ByWater Solutions -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #4 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 200154 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200154&action=edit Bug 42405: Add REST API endpoints for single cover image operations This patch adds three REST API endpoints: POST /api/v1/biblios/{biblio_id}/cover_images POST /api/v1/items/{item_id}/cover_images DELETE /api/v1/cover_images/{image_id} These replace the svc/cover_images CGI script with proper REST endpoints. Upload endpoints accept an image via multipart/form-data and an optional replace query parameter. Test plan: 1. Apply patch 2. Regenerate the API bundle: $ ktd --shell k$ cd /kohadevbox/koha && yarn api:bundle 3. Run: k$ prove t/db_dependent/api/v1/cover_images_single.t => SUCCESS: Tests pass! 4. Tests cover: - Successful biblio image upload (201) - Multiple images without replace - Replace mode deletes existing images - Biblio not found (404) - Successful item image upload (201) - Item not found (404) - Delete image (204) - Delete non-existent image (404) 5. Sign off :-D Sponsored-by: ByWater Solutions -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|42643 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42643 [Bug 42643] [OMNIBUS] Assorted performance and stability work -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |martin.renvoize@openfifth.c |y.org |o.uk -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #200153|0 |1 is obsolete| | Attachment #200154|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #5 from David Nind <david@davidnind.com> --- Created attachment 201135 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201135&action=edit Bug 42405: Add Koha::Biblio->add_cover_image and Koha::Item->add_cover_image This patch adds add_cover_image methods to Koha::Biblio and Koha::Item. Each method takes a GD::Image object, creates the scaled versions via Koha::CoverImage, and stores the result linked to the corresponding biblio or item. A MissingParameter exception is thrown if src_image is not provided. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/cover_images_single.t => SUCCESS: Tests pass! 3. Tests cover: - MissingParameter thrown when src_image is undef (biblio) - MissingParameter thrown when src_image is undef (item) 4. Sign off :-D Sponsored-by: ByWater Solutions Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #6 from David Nind <david@davidnind.com> --- Created attachment 201136 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201136&action=edit Bug 42405: Add REST API endpoints for single cover image operations This patch adds three REST API endpoints: POST /api/v1/biblios/{biblio_id}/cover_images POST /api/v1/items/{item_id}/cover_images DELETE /api/v1/cover_images/{image_id} These replace the svc/cover_images CGI script with proper REST endpoints. Upload endpoints accept an image via multipart/form-data and an optional replace query parameter. Test plan: 1. Apply patch 2. Regenerate the API bundle: $ ktd --shell k$ cd /kohadevbox/koha && yarn api:bundle 3. Run: k$ prove t/db_dependent/api/v1/cover_images_single.t => SUCCESS: Tests pass! 4. Tests cover: - Successful biblio image upload (201) - Multiple images without replace - Replace mode deletes existing images - Biblio not found (404) - Successful item image upload (201) - Item not found (404) - Delete image (204) - Delete non-existent image (404) 5. Sign off :-D Sponsored-by: ByWater Solutions Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |david@davidnind.com --- Comment #7 from David Nind <david@davidnind.com> --- Testing notes (using KTD): 1. I did not manually test uploading cover images, I just ran the tests. 2. The qa script complains about tidyness: ... [FAIL] Koha/REST/V1/CoverImages.pm FAIL tidiness File is not tidy, please run `perl misc/devel/tidy.pl Koha/REST/V1/CoverImages.pm` ... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #201135|0 |1 is obsolete| | Attachment #201136|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #8 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 201317 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201317&action=edit Bug 42405: Add Koha::Biblio->add_cover_image and Koha::Item->add_cover_image This patch adds add_cover_image methods to Koha::Biblio and Koha::Item. Each method takes a GD::Image object, creates the scaled versions via Koha::CoverImage, and stores the result linked to the corresponding biblio or item. A MissingParameter exception is thrown if gd_image is not provided. A WrongParameter exception is thrown if gd_image is not a GD::Image. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Biblio.t t/db_dependent/Koha/Item.t => SUCCESS: Tests pass! 3. Sign off :-D Sponsored-by: ByWater Solutions Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #9 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 201318 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201318&action=edit Bug 42405: Add REST API endpoints for single cover image operations This patch adds three REST API endpoints: POST /api/v1/biblios/{biblio_id}/cover_images POST /api/v1/items/{item_id}/cover_images DELETE /api/v1/cover_images/{image_id} These replace the svc/cover_images CGI script with proper REST endpoints. Upload endpoints accept an image via multipart/form-data and an optional replace query parameter. Test plan: 1. Apply patch 2. Regenerate the API bundle: $ ktd --shell k$ cd /kohadevbox/koha && yarn api:bundle 3. Run: k$ prove t/db_dependent/api/v1/cover_images_single.t => SUCCESS: Tests pass! 4. Tests cover: - Successful biblio image upload (201) - Multiple images without replace - Replace mode deletes existing images - Biblio not found (404) - Successful item image upload (201) - Item not found (404) - Delete image (204) - Delete non-existent image (404) 5. Sign off :-D Sponsored-by: ByWater Solutions Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #10 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- (In reply to David Nind from comment #7)
Testing notes (using KTD): 1. I did not manually test uploading cover images, I just ran the tests. 2. The qa script complains about tidyness: ... [FAIL] Koha/REST/V1/CoverImages.pm FAIL tidiness File is not tidy, please run `perl misc/devel/tidy.pl Koha/REST/V1/CoverImages.pm` ...
Please retest! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #11 from David Nind <david@davidnind.com> --- (In reply to Tomás Cohen Arazi (tcohen) from comment #10)
(In reply to David Nind from comment #7)
Testing notes (using KTD): 1. I did not manually test uploading cover images, I just ran the tests. 2. The qa script complains about tidyness: ... [FAIL] Koha/REST/V1/CoverImages.pm FAIL tidiness File is not tidy, please run `perl misc/devel/tidy.pl Koha/REST/V1/CoverImages.pm` ...
Please retest!
The qa script is happy now 8-) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Andrew Fuerste-Henry <andrew@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |43016 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43016 [Bug 43016] [OMNIBUS] Server resource protection -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|martin.renvoize@openfifth.c |lucas@bywatersolutions.com |o.uk | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |zoho.roboto@bywatersolution | |s.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |This work adds the release notes| |following endpoints to the | |API: | | | |* `POST | |/api/v1/biblios/{biblio_id} | |/cover_images`: add a cover | |image to a bibliographic | |record. | |* `POST | |/api/v1/items/{item_id}/cov | |er_images`: add a cover | |image for an item | |* `DELETE | |/api/v1/cover_images/{image | |_id}`: remove a cover image | |from the system -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #12 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 206753 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=206753&action=edit Bug 42405: (follow-up) Use objects->find_rs in single cover image controllers This patch replaces direct Koha::Objects->find() calls with $c->objects->find_rs() in the delete, add_biblio, and add_item controllers, aligning them with the pattern used by other REST controllers (RecordSources, Transfers, Bookings). The goal is to make these lookups restrictions aware: routing them through the objects helper means they will honour access restrictions such as IndependentBranches automatically if and when a search_limited equivalent is implemented for this resultset, without further changes to these controllers. No functional changes - behavior preserved. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/cover_images_single.t t/db_dependent/api/v1/cover_images.t => SUCCESS: Tests pass! 3. Sign off :-D -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Lucas Gass (lukeg) <lucas@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |BLOCKED -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|BLOCKED |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405 --- Comment #13 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 209372 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209372&action=edit Bug 42405: (follow-up) Fix replace behaviour in single cover image endpoints POST /biblios/{biblio_id}/cover_images and POST /items/{item_id}/cover_images had two problems when replacing existing covers. They are the same Lucas reported for the batch import on bug 42404 comment #45: 1. Replacing a biblio's covers used $biblio->cover_images, which also includes the covers of its items, so the item level covers were deleted too. tools/upload-cover-image.pl only deleted the biblio level ones. 2. The AllowMultipleCovers system preference was ignored, so API consumers could attach several covers to a record when the library does not allow it. tools/upload-cover-image.pl always replaced existing covers when it was disabled. This patch only deletes the biblio level covers (itemnumber IS NULL) when replacing a biblio's covers, and replaces existing covers when AllowMultipleCovers is disabled, whatever the 'replace' parameter says. The logic is in a _replace_covers helper shared by both endpoints. The API spec documents the behaviour. This matches what bug 42404 does for the batch import. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ yarn api:bundle k$ restart_all k$ prove t/db_dependent/api/v1/cover_images_single.t \ xt/api.t => SUCCESS: Tests pass! 3. Revert the changes to Koha/REST/V1/CoverImages.pm and repeat 2 => FAIL: Item level covers are deleted, and covers pile up with AllowMultipleCovers disabled 4. Restore the changes and restart services: k$ restart_all 5. Enable LocalCoverImages, AllowMultipleCovers and RESTBasicAuth 6. Go to record 1, and upload an image for one of its items (holdings table: Edit -> Upload image) 7. Upload a record cover, replacing existing ones: k$ curl -u koha:koha \ -F file=@/kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/img/koha-logo.png \ "http://localhost:8081/api/v1/biblios/1/cover_images?replace=true" => SUCCESS: 201 with a cover_image_id 8. Go to record 1 => SUCCESS: The item cover uploaded in 6 is still there 9. Disable AllowMultipleCovers, repeat 7 twice without ?replace=true => SUCCESS: Record 1 has a single record level cover 10. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org