Bug 27853

Summary: POST /patrons doesn't enforce mandatory extended attributes
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: REST APIAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P5 - low CC: ephetteplace, jonathan.druart, joonas.kylmala, martin.renvoize
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23666
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 27855, 27857    
Bug Blocks:    

Description Tomás Cohen Arazi (tcohen) 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 (ashimema) 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 (tcohen) 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.