Bug 33782: (follow-up) Remove code duplication in OAuth client

This patch eliminates duplicated patron search logic in the
_get_data_and_patron method by extracting it into a dedicated
helper method _find_patron_by_matchpoint.

Changes:
- Extract duplicated patron search logic (8 lines removed)
- Add _find_patron_by_matchpoint helper method
- Improve code maintainability and readability
- No functional changes - behavior preserved

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/Auth/Client/OAuth.t
=> SUCCESS: Tests pass! OAuth client tests work correctly
  k$ prove t/db_dependent/api/v1/oauth.t
=> SUCCESS: Tests pass! OAuth API integration works
3. Confirm OAuth authentication still works in browser
4. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2025-09-20 11:23:31 -03:00 committed by Lucas Gass
parent 4ff2eb3469
commit 13e8f6105a
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 21 additions and 14 deletions

View File

@ -72,13 +72,7 @@ sub _get_data_and_patron {
if defined $claim->{$pkey};
}
my $value = $mapped_data->{$matchpoint};
my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } );
if ( defined $value and $matchpoint_rs->count ) {
$patron = $matchpoint_rs->next;
}
$patron = $self->_find_patron_by_matchpoint( $matchpoint, $mapped_data->{$matchpoint} );
}
if ( defined $config->{userinfo_url} ) {
@ -101,13 +95,7 @@ sub _get_data_and_patron {
}
unless ($patron) {
my $value = $mapped_data->{$matchpoint};
my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } );
if ( defined $value and $matchpoint_rs->count ) {
$patron = $matchpoint_rs->next;
}
$patron = $self->_find_patron_by_matchpoint( $matchpoint, $mapped_data->{$matchpoint} );
}
}
@ -115,4 +103,23 @@ sub _get_data_and_patron {
return ( $mapped_data, $patron );
}
=head3 _find_patron_by_matchpoint
my $patron = $client->_find_patron_by_matchpoint( $matchpoint, $value );
Internal method to find a patron by the given matchpoint and value.
Returns the patron object if found, undef otherwise.
=cut
sub _find_patron_by_matchpoint {
my ( $self, $matchpoint, $value ) = @_;
return unless defined $value;
my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } );
return $matchpoint_rs->count ? $matchpoint_rs->next : undef;
}
1;