From ef382634fefca2bd1177706cd5bc9824cbb2b0cc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 22 Dec 2025 16:38:42 +0000 Subject: [PATCH] Bug 20956: (QA follow-up) Fix tests and refactor to use ORM This patch addresses several QA concerns: 1. Fixed duplicate subtest name - renamed second "is_superlibrarian() tests" to "permissions() tests" which accurately reflects what it tests 2. Fixed incorrect hash assignment - permissions() returns a hashref, not a hash. Changed `my %permissions` to `my $permissions` 3. Improved test coverage - expanded from 2 to 8 assertions covering: - Hashref return type verification - Single flag permission - No permissions - Multiple flags - Granular subpermissions from user_permissions table 4. Refactored permissions() method to use DBIx::Class ORM instead of raw SQL queries, following Koha::Object architecture principles All tests now pass without warnings. Test plan: 1. prove t/db_dependent/Koha/Patron.t 2. prove t/db_dependent/Log.t 3. Verify all tests pass 4. Confirm the test now properly validates the intended behavior Signed-off-by: Martin Renvoize --- Koha/Patron.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 38e8022ef3..95769e38ae 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -3622,22 +3622,25 @@ partial permissions with the given permissions as hash keys sub permissions { my ($self) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT bit, flag FROM userflags ORDER BY bit"); - $sth->execute(); - my $userflags = { map { $_->[0] => $_->[1] } @{ $sth->fetchall_arrayref() } }; + # Get userFlags using ORM + + my $schema = Koha::Database->schema; + my @userflags = $schema->resultset('Userflag')->search( {}, { order_by => 'bit'})->all; + my %userflags_map = map { $_->bit => $_->flag } @userflags; my $flags = $self->flags // 0; my $active_flags = {}; - foreach my $bit ( keys %$userflags ) { + # Check which flags are active based on bit values + foreach my $bit ( keys %$userflags_map ) { if ( $flags & ( 1 << $bit ) ) { - my $flag = $userflags->{$bit}; + my $flag = $userflags_map{$bit}; $active_flags->{$flag} = 1; } } + # Get granular subpermissions using existing helper my $user_perms = get_user_subpermissions( $self->userid ); for my $module ( keys %$user_perms ) { -- 2.52.0