From 7b9982eea0a5aa660786fff6091bbf38ec0dc37a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 29 Nov 2022 15:14:23 -0300 Subject: [PATCH] Bug 32370: Adapt Koha::Auth::Identity::Provider This patch adapts the Koha::Auth::Identity::Provider class to make use of this, and also to prove the behavior is correct (expected results, exceptions, encoding, etc). To test: 1. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Auth/Identity/Provider.t \ t/db_dependent/api/v1/idp.t => SUCCESS: Identity provider related tests pass! 2. Apply this patches 3. Repeat 1 => SUCCESS: Tests still pass! 4. Sign off :-D Signed-off-by: Nick Clemens --- Koha/Auth/Identity/Provider.pm | 36 +++++----------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/Koha/Auth/Identity/Provider.pm b/Koha/Auth/Identity/Provider.pm index 0916a0173fc..382b9090f0e 100644 --- a/Koha/Auth/Identity/Provider.pm +++ b/Koha/Auth/Identity/Provider.pm @@ -19,14 +19,10 @@ package Koha::Auth::Identity::Provider; use Modern::Perl; -use base qw(Koha::Object); - -use JSON qw( decode_json encode_json ); -use Try::Tiny; +use base qw(Koha::Object Koha::Object::JSONFields); use Koha::Auth::Identity::Provider::Domains; use Koha::Exceptions; -use Koha::Exceptions::Object; =head1 NAME @@ -61,11 +57,7 @@ Returns a I containing the configuration parameters for the provider. sub get_config { my ($self) = @_; - return try { - return decode_json( Encode::encode_utf8( $self->config ) ); - } catch { - Koha::Exceptions::Object::BadValue->throw("Error reading JSON data: $_"); - }; + return $self->decode_json_field( { field => 'config' } ); } =head3 set_config @@ -104,14 +96,7 @@ sub set_config { } } - try { - my $encoded_config = encode_json($config); - $self->config($encoded_config); - } catch { - Koha::Exceptions::Object::BadValue->throw("Error serializing data into JSON: $_"); - }; - - return $self; + return $self->set_encoded_json_field( { data => $config, field => 'config' } ); } =head3 get_mapping @@ -125,11 +110,7 @@ Returns a I containing the attribute mapping for the provider. sub get_mapping { my ($self) = @_; - return try { - return decode_json( Encode::encode_utf8( $self->mapping ) ); - } catch { - Koha::Exceptions::Object::BadValue->throw("Error reading JSON data: $_"); - }; + return $self->decode_json_field( { field => 'mapping' } ); } =head3 set_mapping @@ -143,14 +124,7 @@ This method stores the passed mappings in JSON format. sub set_mapping { my ( $self, $mapping ) = @_; - try { - my $encoded_mapping = encode_json($mapping); - $self->mapping($encoded_mapping); - } catch { - Koha::Exceptions::Object::BadValue->throw("Error serializing data into JSON: $_"); - }; - - return $self; + return $self->set_encoded_json_field( { data => $mapping, field => 'mapping' } ); } =head3 upgrade_class -- 2.50.1