From afd0bf0678efe2726930ee271403ef43246eda5e Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 18 Nov 2022 12:29:55 -0300 Subject: [PATCH] Bug 31378: (QA follow-up) Defer store until JSON fields are populated Signed-off-by: Tomas Cohen Arazi --- Koha/Auth/Identity/Provider.pm | 4 ++-- Koha/REST/V1/Auth/Identity/Providers.pm | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Koha/Auth/Identity/Provider.pm b/Koha/Auth/Identity/Provider.pm index 4d29b81270..e9dfc2fddb 100644 --- a/Koha/Auth/Identity/Provider.pm +++ b/Koha/Auth/Identity/Provider.pm @@ -107,7 +107,7 @@ sub set_config { try { my $encoded_config = encode_json($config); - $self->config($encoded_config)->store; + $self->config($encoded_config); } catch { Koha::Exceptions::Object::BadValue->throw("Error serializing data into JSON: $_"); }; @@ -147,7 +147,7 @@ sub set_mapping { try { my $encoded_mapping = encode_json( $mapping ); - $self->mapping( $encoded_mapping )->store; + $self->mapping( $encoded_mapping ); } catch { Koha::Exceptions::Object::BadValue->throw("Error serializing data into JSON: $_"); diff --git a/Koha/REST/V1/Auth/Identity/Providers.pm b/Koha/REST/V1/Auth/Identity/Providers.pm index 6862ae7570..2f3dede36a 100644 --- a/Koha/REST/V1/Auth/Identity/Providers.pm +++ b/Koha/REST/V1/Auth/Identity/Providers.pm @@ -108,11 +108,10 @@ sub add { my $class = Koha::Auth::Identity::Provider::protocol_to_class_mapping->{$protocol}; - my $provider = $class->new_from_api( $body ); - $provider->store; - - $provider->set_config( $config ); - $provider->set_mapping( $mapping ); + my $provider = $class->new_from_api( $body ) + ->set_config( $config ) + ->set_mapping( $mapping ) + ->store; $c->res->headers->location( $c->req->url->to_string . '/' . $provider->identity_provider_id ); return $c->render( @@ -173,9 +172,10 @@ sub update { $provider = $provider->set_from_api( $body )->upgrade_class; - $provider->set_config( $config ); - $provider->set_mapping( $mapping ); - # set_config and set_mapping already called store() + $provider->set_config( $config ) + ->set_mapping( $mapping ) + ->store; + $provider->discard_changes; return $c->render( -- 2.39.5