From f90715782c0acb4cd548e005b34a76e08c20b0c5 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. Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/Patrons.pm | 5 ++++- api/v1/swagger/paths/patrons.yaml | 12 +++++++++--- t/db_dependent/api/v1/patrons.t | 4 +++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm index cfd8a08388..d89d47e102 100644 --- a/Koha/REST/V1/Patrons.pm +++ b/Koha/REST/V1/Patrons.pm @@ -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 ) { 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 0d98ad0c98..3eb4e3e525 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -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*|, -- 2.39.5