It appears that from 18.11.03 (maybe earlier), patrons that are created/imported through the API does not get messaging preferences set as specified in the system preferences ("Default messaging preferences for this patron category"). This should work in the same way that messaging preferences are set for patrons created in the GUI.
Created attachment 131131 [details] [review] Bug 22993: Unit tests
Created attachment 131132 [details] [review] Bug 22993: Handle default messaging preferences during patron creation from API TO test: 1 - Set default messaging preferences for a patron category 2 - Create a patron in that category using the API 3 - Verify messaging preferences are not set 4 - Apply patch, restart all 5 - Create another patron 6 - Verify messaging preferences are correctly set 7 - prove -v t/db_dependent/api/v1/patrons.t
Created attachment 131358 [details] [review] Bug 22993: Unit tests Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Created attachment 131359 [details] [review] Bug 22993: Handle default messaging preferences during patron creation from API TO test: 1 - Set default messaging preferences for a patron category 2 - Create a patron in that category using the API 3 - Verify messaging preferences are not set 4 - Apply patch, restart all 5 - Create another patron 6 - Verify messaging preferences are correctly set 7 - prove -v t/db_dependent/api/v1/patrons.t Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Created attachment 131361 [details] [review] Bug 22993: Unit tests Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 131362 [details] [review] Bug 22993: Handle default messaging preferences during patron creation from API TO test: 1 - Set default messaging preferences for a patron category 2 - Create a patron in that category using the API 3 - Verify messaging preferences are not set 4 - Apply patch, restart all 5 - Create another patron 6 - Verify messaging preferences are correctly set 7 - prove -v t/db_dependent/api/v1/patrons.t Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Well done. Only members/memberentry.pl uses handle_form_action, the rest of the tools that add patrons do what Nick added to the API controller.
Pushed to master for 22.05, thanks to everybody involved [U+1F984]
Pushed to 21.11.x for 21.11.04
Pushed to 21.05.x for 21.05.13
Not backported to oldoldstable (20.11.x). Feel free to ask if it's needed.
Hi Victor, we applied this manually to our 20.11.16 branch, it's working and needed. Just had to move it a little as there was a tiny conflict with some additional code in master.
I don't see a simple way to solve the conflict. Can you attach your 20.11.x version here? Here is the conflict I get. We can see that there is another patch missing for 20.11.x that changes stuffs and this ticket just adds the block with if EnhancedMessagingPreferences The 3 sections are: <<<<<<< the code on 20.11.x before the patch ||||||| the code on 21.05.x before the patch ======= the code on 21.05.x after the patch >>>>>>> <<<<<<< HEAD $c->res->headers->location( $c->req->url->to_string . '/' . $patron->borrowernumber ); return $c->render( status => 201, openapi => $patron->to_api ||||||| parent of ced32711bb (Bug 22993: Handle default messaging preferences during patron creation from API) my $body = $c->validation->param('body'); my $extended_attributes = delete $body->{extended_attributes} // []; my $patron = Koha::Patron->new_from_api($body)->store; $patron->extended_attributes( [ map { { code => $_->{type}, attribute => $_->{value} } } @$extended_attributes ] ); $c->res->headers->location($c->req->url->to_string . '/' . $patron->borrowernumber); return $c->render( status => 201, openapi => $patron->to_api ); } ======= my $body = $c->validation->param('body'); my $extended_attributes = delete $body->{extended_attributes} // []; my $patron = Koha::Patron->new_from_api($body)->store; $patron->extended_attributes( [ map { { code => $_->{type}, attribute => $_->{value} } } @$extended_attributes ] ); if ( C4::Context->preference('EnhancedMessagingPreferences') ) { C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $patron->borrowernumber, categorycode => $patron->categorycode, } ); } $c->res->headers->location($c->req->url->to_string . '/' . $patron->borrowernumber); return $c->render( status => 201, openapi => $patron->to_api ); } >>>>>>> ced32711bb (Bug 22993: Handle default messaging preferences during patron creation from API)
the changes are due to bug 28002
Created attachment 132300 [details] [review] [20.11] Bug 22993: Handle default messaging preferences during patron creation through API Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Hi Victor, I have attached the patch from our branch. We might want to fix the author still.
Ok, the code is independent. Moving the new if block in the old code worked :) Backported: Pushed to 20.11.x branch for 20.11.18
Mid air collision! Thanks, after doublechecking, my solution is the same as yours so it will work :D
(In reply to Victor Grousset/tuxayo from comment #18) > Mid air collision! > Thanks, after doublechecking, my solution is the same as yours so it will > work :D That's the important bit :)