Bug 36505 - Allow updating patron attributes via PUT
Summary: Allow updating patron attributes via PUT
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Martin Renvoize
URL:
Keywords:
Depends on: 36495
Blocks:
  Show dependency treegraph
 
Reported: 2024-04-03 17:37 UTC by Nick Clemens (kidclamp)
Modified: 2024-04-26 16:07 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00


Attachments
Bug 36505: Unit tests (7.04 KB, patch)
2024-04-08 13:29 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 36505: Add support for `extended_attributes` in PUT /patrons/:patron_id (8.18 KB, patch)
2024-04-08 13:29 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 36505: (follow-up) Consistent error codes in POST (2.43 KB, patch)
2024-04-09 06:57 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 36505: Unit tests (7.09 KB, patch)
2024-04-11 15:34 UTC, Brendan Lawlor
Details | Diff | Splinter Review
Bug 36505: Add support for `extended_attributes` in PUT /patrons/:patron_id (8.23 KB, patch)
2024-04-11 15:34 UTC, Brendan Lawlor
Details | Diff | Splinter Review
Bug 36505: (follow-up) Consistent error codes in POST (2.48 KB, patch)
2024-04-11 15:34 UTC, Brendan Lawlor
Details | Diff | Splinter Review
Bug 36505: Unit tests (7.15 KB, patch)
2024-04-23 15:35 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 36505: Add support for `extended_attributes` in PUT /patrons/:patron_id (8.30 KB, patch)
2024-04-23 15:35 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 36505: (follow-up) Consistent error codes in POST (2.55 KB, patch)
2024-04-23 15:35 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clemens (kidclamp) 2024-04-03 17:37:59 UTC
According to our docs, you can include an array of patron attributes on a patrons PUT request:
https://api.koha-community.org/Development.html#tag/patrons/operation/updatePatron

When testing I sent:
{"category_id":"PT","library_id":"CPL","surname":"Ballard","extended_attributes":[{"extended_attribute_id":"1","type":"SHOW_BCODE","value":"0"}]}

And I got an error:
[2024/04/03 17:27:40] [ERROR] PUT /api/v1/patrons/21: unhandled exception (Koha::Exceptions::Object::PropertyNotFound)<<No property extended_attributes for Koha::Patron>>
Comment 1 Tomás Cohen Arazi 2024-04-08 13:29:03 UTC
Created attachment 164499 [details] [review]
Bug 36505: Unit tests
Comment 2 Tomás Cohen Arazi 2024-04-08 13:29:06 UTC
Created attachment 164500 [details] [review]
Bug 36505: Add support for `extended_attributes` in PUT /patrons/:patron_id

This patch does what the title says. With it, you will be able to PUT on
the already existing endpoint, but also pass:

```json
[ { "type": "THE_TYPE", "value": "a" }, ... ]
```

Bonus: to ease testing I added `x-koha-embed: extended_attributes`
support.

To test:
1. Apply the unit tests
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/patrons.t
=> FAIL: This is not implemented!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Exhaustive testes pass!
5. Sign off :-D
Comment 3 Tomás Cohen Arazi 2024-04-09 06:57:08 UTC
Created attachment 164527 [details] [review]
Bug 36505: (follow-up) Consistent error codes in POST
Comment 4 Brendan Lawlor 2024-04-09 20:51:31 UTC
When I try to apply this patch I get this error:

Applying: Bug 36505: Add support for `extended_attributes` in PUT /patrons/:patron_id
error: sha1 information is lacking or useless (Koha/REST/V1/Patrons.pm).
error: could not build fake ancestor
Patch failed at 0001 Bug 36505: Add support for `extended_attributes` in PUT /patrons/:patron_id

Thanks for working on this! We need this to work for our eCard renewal vendor to update patron attibutes correctly.
Comment 5 Tomás Cohen Arazi 2024-04-11 12:20:36 UTC
This was missing a dependency. Hopefully those will be pushed pretty soon.
Comment 6 Brendan Lawlor 2024-04-11 13:00:24 UTC
(In reply to Tomás Cohen Arazi from comment #5)
> This was missing a dependency. Hopefully those will be pushed pretty soon.

Thanks Tomás. Is there a bug to watch for the dependency to be pushed. I would like to follow up and test this when I can.
Comment 7 Tomás Cohen Arazi 2024-04-11 13:27:39 UTC
(In reply to Brendan Lawlor from comment #6)
> (In reply to Tomás Cohen Arazi from comment #5)
> > This was missing a dependency. Hopefully those will be pushed pretty soon.
> 
> Thanks Tomás. Is there a bug to watch for the dependency to be pushed. I
> would like to follow up and test this when I can.

Hi, Brendan. If you are testing using KTD, when you try to do a:

```shell
git fetch
git checkout origin/master -b bug_36505
git bz apply 36505
```

the last command should offer you the option to recursivelly apply the dependencies! If you feel like, give it a try. My only advise is: sometimes it is not smart enough and it offers you to apply an already applied bug. But that doesn't happen quite often.

Thanks for your interest on this bug!
Comment 8 Brendan Lawlor 2024-04-11 15:34:52 UTC
Created attachment 164771 [details] [review]
Bug 36505: Unit tests

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 9 Brendan Lawlor 2024-04-11 15:34:54 UTC
Created attachment 164772 [details] [review]
Bug 36505: Add support for `extended_attributes` in PUT /patrons/:patron_id

This patch does what the title says. With it, you will be able to PUT on
the already existing endpoint, but also pass:

```json
[ { "type": "THE_TYPE", "value": "a" }, ... ]
```

Bonus: to ease testing I added `x-koha-embed: extended_attributes`
support.

To test:
1. Apply the unit tests
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/patrons.t
=> FAIL: This is not implemented!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Exhaustive testes pass!
5. Sign off :-D

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 10 Brendan Lawlor 2024-04-11 15:34:56 UTC
Created attachment 164773 [details] [review]
Bug 36505: (follow-up) Consistent error codes in POST

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 11 Brendan Lawlor 2024-04-11 15:40:52 UTC
Thanks Tomás!

Testing notes:

Apply dependencies and patch
```shell
git fetch
git checkout origin/master -b bug_36505
git bz apply 36505
```

Enable system preference RESTOAuth2ClientCredentials
Create a patron with edit borrowers permissions
Get an API authentication token

curl --location --request PUT 'http://localhost:8080/api/v1/patrons/21' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer MTcxMjg0OTAyOC00NTc2OTEtMC4yNTUwNzU4MzY0NjM2NS1SbVF0UzdROW1qTDE0b1ViVjJKYXhuSFFlblZLcjY=' \
--data '{
    "category_id": "PT",
    "library_id": "CPL",
    "surname": "Ballard",
    "extended_attributes": [
        {
            "extended_attribute_id": "1",
            "type": "SHOW_BCODE",
            "value": "1"
        }
    ]
}'

This returns 200 and updates the patron attribute!

Run test:
kohadev-koha@kohadevbox:koha(bug_36505)$ prove t/db_dependent/api/v1/patrons.t
t/db_dependent/api/v1/patrons.t .. ok   
All tests successful.
Files=1, Tests=7, 11 wallclock secs ( 0.03 usr  0.01 sys +  9.11 cusr  0.65 csys =  9.80 CPU)
Result: PASS
Comment 12 Martin Renvoize 2024-04-23 15:35:20 UTC
Created attachment 165409 [details] [review]
Bug 36505: Unit tests

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 13 Martin Renvoize 2024-04-23 15:35:23 UTC
Created attachment 165410 [details] [review]
Bug 36505: Add support for `extended_attributes` in PUT /patrons/:patron_id

This patch does what the title says. With it, you will be able to PUT on
the already existing endpoint, but also pass:

```json
[ { "type": "THE_TYPE", "value": "a" }, ... ]
```

Bonus: to ease testing I added `x-koha-embed: extended_attributes`
support.

To test:
1. Apply the unit tests
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/patrons.t
=> FAIL: This is not implemented!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Exhaustive testes pass!
5. Sign off :-D

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 14 Martin Renvoize 2024-04-23 15:35:26 UTC
Created attachment 165411 [details] [review]
Bug 36505: (follow-up) Consistent error codes in POST

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 15 Martin Renvoize 2024-04-23 15:35:58 UTC
Fixed and working, thanks Tomas.

Tests passing and present.

Passing QA
Comment 16 Katrin Fischer 2024-04-26 08:45:24 UTC
This is just the tip of the iceberg, the dependency includes several "enh" bugs. Skipping for now (will be back later).
Comment 17 Katrin Fischer 2024-04-26 16:07:35 UTC
Pushed for 24.05!

Well done everyone, thank you!