Bug 28002 - Add optional extended_attributes param to POST /patrons
Summary: Add optional extended_attributes param to POST /patrons
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Tomás Cohen Arazi (tcohen)
QA Contact: Kyle M Hall (khall)
URL:
Keywords:
Depends on: 23666 27855 28157
Blocks:
  Show dependency treegraph
 
Reported: 2021-03-19 13:05 UTC by Tomás Cohen Arazi (tcohen)
Modified: 2021-12-13 21:12 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This development adds an optional parameter to the POST /patrons route, so extended attributes can be passed for patron creation. It relies on the underlying code to handle extended attributes constraints/requirements (repeatable, mandatory, unique, etc). The added attribute (to be passed in the body of the POST request) is 'extended_attributes' and consists of an array of extended attribute objects (properly described on the spec).
Version(s) released in:
21.05.00
Circulation function:


Attachments
Bug 28002: Unit tests (7.98 KB, patch)
2021-03-31 13:15 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 28002: Add extended_attributes support to POST /patrons (5.86 KB, patch)
2021-03-31 13:15 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 28002: Unit tests (8.05 KB, patch)
2021-04-09 15:33 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 28002: Unit tests (8.05 KB, patch)
2021-04-09 15:34 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 28002: Add extended_attributes support to POST /patrons (5.93 KB, patch)
2021-04-09 15:34 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 28002: Unit tests (8.03 KB, patch)
2021-04-09 16:11 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 28002: Add extended_attributes support to POST /patrons (5.92 KB, patch)
2021-04-09 16:11 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 28002: Unit tests (8.09 KB, patch)
2021-04-09 16:15 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 28002: Add extended_attributes support to POST /patrons (5.97 KB, patch)
2021-04-09 16:15 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 28002: Unit tests (8.16 KB, patch)
2021-04-09 17:09 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi (tcohen) 2021-03-19 13:05:33 UTC
Bug 27853 highlighted some patron's shouldn't be created through the API if they don't satisfy the mandatory extended attributes requirements.

Solving it is not possible without adding a new parameter and proper handling to the current route.

This bug proposes to add that parameter. It is based on the work done in bug 23666 and its tree.
Comment 1 Tomás Cohen Arazi (tcohen) 2021-03-31 13:15:37 UTC
Created attachment 119047 [details] [review]
Bug 28002: Unit tests
Comment 2 Tomás Cohen Arazi (tcohen) 2021-03-31 13:15:41 UTC
Created attachment 119048 [details] [review]
Bug 28002: Add extended_attributes support to POST /patrons

This patch adds support for the 'extended_attributes' parameter in the
route for adding a patron. It relies on
Koha::Patron->extended_attributes for the tests. Exceptions are catch
and the whole operation is rolled back.

I chose to handle each exception on its own if branch, with bug 28020 in
mind.

To test:
1. Apply this patchset
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/patrons.t
=> SUCCES: Tests pass!
3. Check they cover all the exception situations!
=> SUCCESS: They do!
4. Sign off :-D
Comment 3 Kyle M Hall (khall) 2021-04-09 15:33:38 UTC
Created attachment 119395 [details] [review]
Bug 28002: Unit tests

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 4 Kyle M Hall (khall) 2021-04-09 15:34:35 UTC
Created attachment 119396 [details] [review]
Bug 28002: Unit tests

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 5 Kyle M Hall (khall) 2021-04-09 15:34:46 UTC
Created attachment 119397 [details] [review]
Bug 28002: Add extended_attributes support to POST /patrons

This patch adds support for the 'extended_attributes' parameter in the
route for adding a patron. It relies on
Koha::Patron->extended_attributes for the tests. Exceptions are catch
and the whole operation is rolled back.

I chose to handle each exception on its own if branch, with bug 28020 in
mind.

To test:
1. Apply this patchset
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/patrons.t
=> SUCCES: Tests pass!
3. Check they cover all the exception situations!
=> SUCCESS: They do!
4. Sign off :-D

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 6 Victor Grousset/tuxayo 2021-04-09 16:11:34 UTC Comment hidden (obsolete)
Comment 7 Victor Grousset/tuxayo 2021-04-09 16:11:39 UTC Comment hidden (obsolete)
Comment 8 Victor Grousset/tuxayo 2021-04-09 16:15:09 UTC
Created attachment 119417 [details] [review]
Bug 28002: Unit tests

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 9 Victor Grousset/tuxayo 2021-04-09 16:15:13 UTC
Created attachment 119418 [details] [review]
Bug 28002: Add extended_attributes support to POST /patrons

This patch adds support for the 'extended_attributes' parameter in the
route for adding a patron. It relies on
Koha::Patron->extended_attributes for the tests. Exceptions are catch
and the whole operation is rolled back.

I chose to handle each exception on its own if branch, with bug 28020 in
mind.

To test:
1. Apply this patchset
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/patrons.t
=> SUCCES: Tests pass!
3. Check they cover all the exception situations!
=> SUCCESS: They do!
4. Sign off :-D

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 10 Kyle M Hall (khall) 2021-04-09 17:09:18 UTC
Created attachment 119425 [details] [review]
Bug 28002: Unit tests

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 11 Tomás Cohen Arazi (tcohen) 2021-04-12 19:26:51 UTC
Kyle/Victor, it seems you overlapped on the QA step. Can any of you check you SO lines are ok?
Comment 12 Jonathan Druart 2021-04-16 13:17:27 UTC
We need to discuss how to deal with the "library limitations". Tomas will send an email to the list.
Comment 13 Tomás Cohen Arazi (tcohen) 2021-04-21 10:57:03 UTC
This implementation relies on Koha::Patron->extended_attributes, which is aware of library limitations by means of userenv. This, paired with bug 28157, should give us a secure way [1] to specify the library the request comes from and have Koha::Patron->extended_attributes act correctly.

[1] The bug 28157 will reject the request if the alleged library is not valid for the caller user.
Comment 14 Jonathan Druart 2021-04-22 12:39:55 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 15 Martin Renvoize (ashimema) 2021-04-22 13:43:13 UTC
So happy to see this having worked it way through.. a great team effort, especially thankful for all Tomas's work!
Comment 16 Fridolin Somers 2021-04-29 14:26:23 UTC
Depends on Bug 23666 not in 20.11.x