Bugzilla – Attachment 166111 Details for
Bug 36503
Add a plugin hook to modify patrons after authentication
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36503: Add a plugin hook after user authentication
Bug-36503-Add-a-plugin-hook-after-user-authenticat.patch (text/plain), 4.58 KB, created by
Martin Renvoize (ashimema)
on 2024-05-03 11:48:41 UTC
(
hide
)
Description:
Bug 36503: Add a plugin hook after user authentication
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-05-03 11:48:41 UTC
Size:
4.58 KB
patch
obsolete
>From c8b7a779bbf275fd0b199cf215516b818d64b5ba Mon Sep 17 00:00:00 2001 >From: Raphael Straub <raphael.straub@kit.edu> >Date: Thu, 28 Mar 2024 12:31:15 +0000 >Subject: [PATCH] Bug 36503: Add a plugin hook after user authentication > >This plugin hook allows to change patron data or define the patron >based on the authenticated user. > >To test: Run >prove t/db_dependent/Koha/Auth/Client.t > >Sponsored-by: Karlsruhe Institute of Technology (KIT) >Signed-off-by: Thomas Klausner <domm@plix.at> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Auth/Client.pm | 25 ++++++++++++++++++ > t/db_dependent/Koha/Auth/Client.t | 43 ++++++++++++++++++++++++++++++- > 2 files changed, 67 insertions(+), 1 deletion(-) > >diff --git a/Koha/Auth/Client.pm b/Koha/Auth/Client.pm >index 159dd40c8f7..7e9d69e6406 100644 >--- a/Koha/Auth/Client.pm >+++ b/Koha/Auth/Client.pm >@@ -19,6 +19,8 @@ package Koha::Auth::Client; > > use Modern::Perl; > >+use C4::Context; >+ > use Koha::Exceptions::Auth; > use Koha::Auth::Identity::Providers; > >@@ -62,6 +64,29 @@ sub get_user { > > my ( $mapped_data, $patron ) = $self->_get_data_and_patron({ provider => $provider, data => $data, config => $config }); > >+ # Call the plugin hook "auth_client_get_user" of all plugins in >+ # ascending priority. >+ if ( C4::Context->config('enable_plugins') ) { >+ my @plugins = Koha::Plugins->new()->GetPlugins( >+ { >+ method => 'auth_client_get_user', >+ } >+ ); >+ @plugins = sort { $a->retrieve_data('priority') <=> $b->retrieve_data('priority') } @plugins; >+ my $args = { >+ provider => $provider, >+ data => $data, >+ config => $config, >+ mapped_data => $mapped_data, >+ patron => $patron, >+ }; >+ foreach my $plugin (@plugins) { >+ $plugin->auth_client_get_user($args); >+ } >+ $mapped_data = $args->{'mapped_data'}; >+ $patron = $args->{'patron'}; >+ } >+ > $mapped_data //= {}; > > my $domain = $self->has_valid_domain_config({ provider => $provider, email => $mapped_data->{email}, interface => $interface}); >diff --git a/t/db_dependent/Koha/Auth/Client.t b/t/db_dependent/Koha/Auth/Client.t >index 149aaa48185..7020cef9ecd 100755 >--- a/t/db_dependent/Koha/Auth/Client.t >+++ b/t/db_dependent/Koha/Auth/Client.t >@@ -22,6 +22,7 @@ use Modern::Perl; > use Test::More tests => 4; > > use Test::MockModule; >+use Test::MockObject; > use Test::Exception; > > use JSON qw(encode_json); >@@ -38,7 +39,7 @@ my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > > subtest 'get_user() tests' => sub { >- plan tests => 4; >+ plan tests => 5; > > $schema->storage->txn_begin; > >@@ -77,6 +78,46 @@ subtest 'get_user() tests' => sub { > is( $mapped_data->{surname}, undef, 'No surname mapped' ); > is( $domain->identity_provider_domain_id, $resolved_domain->identity_provider_domain_id, 'Is the same domain' ); > >+ # Test the plugin hook "auth_client_get_user". >+ t::lib::Mocks::mock_config( 'enable_plugins', 1 ); >+ my $get_plugins = sub { >+ my $methods = [ >+ { >+ auth_client_get_user => sub { >+ $_[1]->{mapped_data}->{firstname} = 'test name modified 1'; >+ return; >+ }, >+ retrieve_data => sub { return $_[1] eq 'priority' ? 2 : undef; } >+ }, >+ { >+ auth_client_get_user => sub { >+ $_[1]->{mapped_data}->{firstname} = 'test name modified 2'; >+ return; >+ }, >+ retrieve_data => sub { return $_[1] eq 'priority' ? 1 : undef; } >+ } >+ ]; >+ my @plugins; >+ foreach my $method ( @{$methods} ) { >+ my $plugin = Test::MockObject->new; >+ foreach my $name ( keys %{$method} ) { >+ $plugin->mock( $name, $method->{$name} ); >+ } >+ push @plugins, $plugin; >+ } >+ return @plugins; >+ }; >+ my $plugins_module = Test::MockModule->new('Koha::Plugins'); >+ $plugins_module->mock( 'GetPlugins', $get_plugins ); >+ $plugins_module->mock( 'get_enabled_plugins', $get_plugins ); >+ ( $resolved_patron, $mapped_data, $resolved_domain ) = >+ $client->get_user( { provider => $provider->code, data => $data, interface => 'opac' } ); >+ is( >+ $mapped_data->{firstname}, >+ 'test name modified 1', >+ 'Data modified correctly by plugins' >+ ); >+ > $schema->storage->txn_rollback; > > }; >-- >2.44.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36503
:
164379
|
164628
|
164893
|
164894
|
165466
|
166050
|
166111
|
166112
|
166113
|
166114
|
166115
|
166116
|
166458
|
166459
|
166460
|
166461
|
166462
|
166531
|
166532