Bug 27853 - POST /patrons doesn't enforce mandatory extended attributes
Summary: POST /patrons doesn't enforce mandatory extended attributes
Status: NEW
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:
URL:
Keywords:
Depends on: 27855 27857
Blocks:
  Show dependency treegraph
 
Reported: 2021-03-03 17:22 UTC by Tomás Cohen Arazi
Modified: 2021-05-07 18:35 UTC (History)
4 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2021-03-03 17:22:11 UTC
If there are extended attributes types that are mandatory, the POST /patrons route should fail if the request doesn't meet this requirement.

Unfortunately, we have no way (yet) to pass extended attributes on the POST. So to solve this bug, we need to add a way to pass extended attributes along with the patron object.

I propose:

POST /patrons
{
    "first_name": "Tomasito",
    ...
    "extended_attributes": {
        "SHOW_BCODE": [ 1 ],
        "COURSES": [ "ALGO1", "DATABASES" ]
    }
}

I choose to force them to be arrays for simplicity (they can be repeatable), but we can check the data type on the controller (i.e. if ( ref($extended_attributes) eq 'ARRAY') { # loop case } else { # scalar case } ).

I'm open for opinions.
Comment 1 Martin Renvoize 2021-03-03 17:43:26 UTC
How about an array of extended_attribute objects?

"extended_attributes": [
    { "type": "whatever", "code": "yup" },
    { "type": "another", "code": "top" }
]
Comment 2 Joonas Kylmälä 2021-03-15 12:39:25 UTC
At least the "Unique identifier" attribute check should be added as well there if it will be possible to add mandatory attribute in the future. And probably the same goes for checking the "Repeatable" attribute property.
Comment 3 Tomás Cohen Arazi 2021-03-15 13:08:06 UTC
(In reply to Joonas Kylmälä from comment #2)
> At least the "Unique identifier" attribute check should be added as well
> there if it will be possible to add mandatory attribute in the future. And
> probably the same goes for checking the "Repeatable" attribute property.

Yes! That's handled on bug 27857, in which this will rely.