From a22aa83ddc2c5d0609c0ec1f3ab25c19c0ab4831 Mon Sep 17 00:00:00 2001 From: Ayoub Glizi-Vicioso Date: Thu, 5 Mar 2026 11:05:50 -0500 Subject: [PATCH] Bug 20956: (QA follow-up) Fix display of permission logs --- Koha/Patron.pm | 6 +- .../prog/en/modules/tools/viewlog.tt | 50 +++++++++++++++- t/db_dependent/Koha/Patron.t | 60 +++++++++++-------- tools/viewlog.pl | 15 +++++ 4 files changed, 100 insertions(+), 31 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 700a58a600..b1f9f161cf 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -3600,7 +3600,7 @@ my $flags = $patron->permissions Returns a hashref of the patron's permissions. This method has the same return structure as C4::Auth::getuserflags for consistency. -Exemple return structure: +Example return structure: { "superlibrarian": 0, "permissions": 0, @@ -3633,8 +3633,8 @@ sub permissions { # Get userFlags using ORM - my $schema = Koha::Database->schema; - my @userflags = $schema->resultset('Userflag')->search( {}, { order_by => 'bit'})->all; + 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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt index 42634a034e..60aff8d686 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -406,11 +406,23 @@ > [% ELSE %] -
[% loopro.info | html %]
+
+ [% IF ( loopro.module == 'MEMBERS' ) %] +
[% loopro.info | html %]
+ [% ELSE %] + [% loopro.info | html %] + [% END %] +
[% END %] [% PROCESS translate_log_interface log_interface=loopro.interface %] - [% loopro.diff | html %] + + [% IF ( loopro.module == 'MEMBERS' ) %] +
[% loopro.diff | html %]
+ [% ELSE %] + [% loopro.diff | html %] + [% END %] + [% END %] @@ -474,6 +486,40 @@ [% Asset.js("js/viewlog.js") | $raw %] [% END %] diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 9c256b95df..5e33d166aa 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -2386,21 +2386,24 @@ subtest 'alert_subscriptions tests' => sub { my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); - my $subscription1 = $builder->build_object( { - class => 'Koha::Subscriptions', - value => { - librarian => $patron->borrowernumber, + my $subscription1 = $builder->build_object( + { + class => 'Koha::Subscriptions', + value => { + librarian => $patron->borrowernumber, + } } - }); + ); $subscription1->add_subscriber($patron); - - my $subscription2 = $builder->build_object( { - class => 'Koha::Subscriptions', - value => { - librarian => $patron->borrowernumber, + my $subscription2 = $builder->build_object( + { + class => 'Koha::Subscriptions', + value => { + librarian => $patron->borrowernumber, + } } - }); + ); $subscription2->add_subscriber($patron); my @subscriptions = $patron->alert_subscriptions->as_list; @@ -2439,16 +2442,22 @@ subtest 'update_lastseen tests' => sub { my $mock_cache = Test::MockModule->new('Koha::Cache'); my %fake_cache; - $mock_cache->mock('set_in_cache', sub { - my ( $self, $key, $value ) = @_; - $fake_cache{$key} = $value; - return; - }); + $mock_cache->mock( + 'set_in_cache', + sub { + my ( $self, $key, $value ) = @_; + $fake_cache{$key} = $value; + return; + } + ); - $mock_cache->mock('get_from_cache', sub { - my ( $self, $key ) = @_; - return $fake_cache{$key}; - }); + $mock_cache->mock( + 'get_from_cache', + sub { + my ( $self, $key ) = @_; + return $fake_cache{$key}; + } + ); my $cache = Koha::Caches->get_instance(); @@ -2457,12 +2466,12 @@ subtest 'update_lastseen tests' => sub { 'creation,login,connection,check_in,check_out,renewal,hold,article' ); - my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); my $patron_info = $patron->unblessed; delete $patron_info->{borrowernumber}; $patron->delete(); $patron = Koha::Patron->new($patron_info)->store(); - $patron->update_lastseen({ activity => 'creation' }); + $patron->update_lastseen( { activity => 'creation' } ); $patron->discard_changes(); my $now = dt_from_string(); @@ -2486,20 +2495,19 @@ subtest 'update_lastseen tests' => sub { $patron_no_trigger->lastseen(undef)->store(); - $patron_no_trigger->update_lastseen({ activity => 'login' }); + $patron_no_trigger->update_lastseen( { activity => 'login' } ); $patron_no_trigger->discard_changes(); - is( $patron_no_trigger->lastseen, undef, + is( + $patron_no_trigger->lastseen, undef, 'Patron should have not last seen when newly created if trigger not set' ); - t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal,hold,article' ); - $now = dt_from_string(); Time::Fake->offset( $now->epoch ); diff --git a/tools/viewlog.pl b/tools/viewlog.pl index 2ea2feb359..caba48e5f1 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -234,6 +234,21 @@ if ($do_it) { } } } + + if ( $result->{module} eq 'MEMBERS' ) { + my $json_engine = JSON->new->utf8->canonical(1)->pretty(1); + + if ( $result->{info} && $result->{info} =~ /^[{\[]/ ) { + my $perl_info = $json_engine->decode( $result->{info} ); + $result->{info} = $json_engine->encode($perl_info); + } + + if ( $result->{diff} && $result->{diff} =~ /^[{\[]/ ) { + my $perl_diff = $json_engine->decode( $result->{diff} ); + $result->{diff} = $json_engine->encode($perl_diff); + } + } + push @data, $result; } if ( $output eq "screen" ) { -- 2.53.0