From 443f023bedb132afd80501bba6653ede05e15175 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 8 Sep 2023 12:06:26 +0100 Subject: [PATCH] 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. --- Koha/REST/V1/Patrons.pm | 3 ++- api/v1/swagger/paths/patrons.yaml | 12 +++++++++--- t/db_dependent/api/v1/patrons.t | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm index cfd8a08388..637ccef15e 100644 --- a/Koha/REST/V1/Patrons.pm +++ b/Koha/REST/V1/Patrons.pm @@ -116,7 +116,8 @@ 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 ) { diff --git a/api/v1/swagger/paths/patrons.yaml b/api/v1/swagger/paths/patrons.yaml index 2245d38156..ff64e71bbb 100644 --- a/api/v1/swagger/paths/patrons.yaml +++ b/api/v1/swagger/paths/patrons.yaml @@ -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: diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index befd960fe9..8e5d258637 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -398,8 +398,9 @@ 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*|, -- 2.41.0