Bug 33690: Convert to x-koha-override

This patch converts the existing work to use x-koha-override instead of
introducing an entirely new header and we default to the system
preference value if the override isn't passed.

I believe this is more consistent with our approach in other areas of
koha to date.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2023-09-08 12:06:26 +01:00 committed by Tomas Cohen Arazi
parent 6a9b4d9096
commit f90715782c
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
3 changed files with 16 additions and 5 deletions

View file

@ -116,7 +116,10 @@ sub add {
my $patron = Koha::Patron->new_from_api($body)->store;
if ( $c->req->headers->header('x-koha-welcome') ) {
my $overrides = $c->stash('koha.overrides');
if ( $overrides->{welcome_yes}
|| ( C4::Context->preference("AutoEmailNewUser") && !$overrides->{welcome_no} ) )
{
# if we manage to find a valid email address, send notice
if ( $patron->notice_email_address ) {

View file

@ -405,11 +405,17 @@
required: true
schema:
$ref: "../swagger.yaml#/definitions/patron"
- name: x-koha-welcome
- name: x-koha-override
in: header
required: false
description: If set to 'email' triggers the sending of a welcome email
type: string
description: Overrides list sent as a request header
type: array
items:
type: string
enum:
- welcome_yes
- welcome_no
collectionFormat: csv
consumes:
- application/json
produces:

View file

@ -408,8 +408,10 @@ subtest 'add() tests' => sub {
# Set a date-time field
$newpatron->{last_seen} = output_pref({ dt => dt_from_string->add( days => -1 ), dateformat => 'rfc3339' });
t::lib::Mocks::mock_preference( 'AutoEmailNewUser', 0 );
$letter_enqueued = 0;
$t->post_ok("//$userid:$password@/api/v1/patrons" => { 'x-koha-welcome' => 'email' } => json => $newpatron)
$t->post_ok(
"//$userid:$password@/api/v1/patrons" => { 'x-koha-override' => 'welcome_yes' } => json => $newpatron )
->status_is(201, 'Patron created successfully')
->header_like(
Location => qr|^\/api\/v1\/patrons/\d*|,