Bugzilla – Attachment 194878 Details for
Bug 36698
Display 'diff' nicely in action logs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36698: (20956 follow-up) Fix display of permission logs [ALTERNATIVE]
e53efc7.patch (text/plain), 5.94 KB, created by
Martin Renvoize (ashimema)
on 2026-03-06 17:35:25 UTC
(
hide
)
Description:
Bug 36698: (20956 follow-up) Fix display of permission logs [ALTERNATIVE]
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-03-06 17:35:25 UTC
Size:
5.94 KB
patch
obsolete
>From e53efc7f6ae931530c9f1fba5856f1efc4fb91d1 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Fri, 6 Mar 2026 17:34:13 +0000 >Subject: [PATCH] Bug 36698: (20956 follow-up) Fix display of permission logs > [ALTERNATIVE] > >This is an alternative to attachment 194534 on bug 20956. >Depends on Bug 20956. > >For MEMBERS/MODIFY log entries, pretty-print the JSON stored in the >info and diff columns (viewlog.pl), and render them in <pre> blocks >in the log viewer template (viewlog.tt). > >The diff block additionally receives a 'permissions-diff' CSS class >which triggers a JavaScript colorizer that annotates Struct::Diff >output with human-readable Added/Removed/Modifications/Old/New labels >and color highlights. >--- > .../prog/en/modules/tools/viewlog.tt | 50 ++++++++++++++++++- > tools/viewlog.pl | 15 ++++++ > 2 files changed, 63 insertions(+), 2 deletions(-) > >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 42634a034e8..60aff8d6862 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 @@ > > > </div> > [% ELSE %] >- <div class="loginfo" id="loginfo[% loopro.action_id | html %]"> [% loopro.info | html %] </div> >+ <div class="loginfo" id="loginfo[% loopro.action_id | html %]"> >+ [% IF ( loopro.module == 'MEMBERS' ) %] >+ <pre>[% loopro.info | html %]</pre> >+ [% ELSE %] >+ [% loopro.info | html %] >+ [% END %] >+ </div> > [% END %] > </td> > <td>[% PROCESS translate_log_interface log_interface=loopro.interface %]</td> >- <td>[% loopro.diff | html %]</td> >+ <td> >+ [% IF ( loopro.module == 'MEMBERS' ) %] >+ <pre class="permissions-diff">[% loopro.diff | html %]</pre> >+ [% ELSE %] >+ [% loopro.diff | html %] >+ [% END %] >+ </td> > </tr> > [% END %] > </tbody> >@@ -474,6 +486,40 @@ > <script> > var table_settings = [% TablesSettings.GetTableSettings('tools', 'logviewer', 'logst', 'json') | $raw %]; > var CAN_user_parameters_manage_sysprefs = "[% CAN_user_parameters_manage_sysprefs | html %]"; >+ $(document).ready(function() { >+ $("pre.permissions-diff").each(function() { >+ let text = $(this).html(); >+ let dCounter = 0; >+ >+ let added_label = _("Added "); >+ let removed_label = _("Removed "); >+ >+ let all_label = _("-- All --"); >+ >+ >+ text = text.replace(/^(\s{0,8}"[^"]+"\s*:\s*)\{\s*"A"\s*:\s*1\s*\}/gm, '$1<span style="color:#2ea44f; font-weight:bold;">' + added_label + all_label + '</span>'); >+ text = text.replace(/^(\s{0,8}"[^"]+"\s*:\s*)\{\s*"R"\s*:\s*1\s*\}/gm, '$1<span style="color:#cf222e; font-weight:bold;">' + removed_label + all_label + '</span>'); >+ >+ text = text.replace(/^(\s*"[^"]+"\s*:\s*)\{\s*"A"\s*:\s*1\s*\}/gm, '$1<span style="color:#2ea44f; font-weight:bold;">' + added_label + 'â</span>'); >+ text = text.replace(/^(\s*"[^"]+"\s*:\s*)\{\s*"R"\s*:\s*1\s*\}/gm, '$1<span style="color:#cf222e; font-weight:bold;">' + removed_label + 'â</span>'); >+ >+ text = text.replace(/"D"/g, function() { >+ dCounter++; >+ var label = (dCounter === 1) ? _("Modifications") : " â³"; >+ var color = (dCounter === 1) ? "#0056b3" : "#6e7781"; >+ return '<span style="color:' + color + '; font-weight:bold;">' + label + '</span>'; >+ }); >+ >+ text = text.replace(/"A"/g, '<span style="color:#2ea44f; font-weight:bold;">' + _("Added ") + 'â' + '</span>'); >+ text = text.replace(/"R"/g, '<span style="color:#cf222e; font-weight:bold;">' + _("Removed ") + 'â' + '</span>'); >+ text = text.replace(/"O"/g, '<span style="color:#6e7781; font-weight:bold;">' + _("Old value") + '</span>'); >+ text = text.replace(/"N"/g, '<span style="color:#0969da; font-weight:bold;">' + _("New value") + '</span>'); >+ >+ text = text.replace(/,\s*$/gm, ""); >+ >+ $(this).html(text); >+ }); >+ }); > </script> > [% Asset.js("js/viewlog.js") | $raw %] > [% END %] >diff --git a/tools/viewlog.pl b/tools/viewlog.pl >index 2ea2feb3592..caba48e5f13 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 >
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 36698
:
194566
|
194745
|
194752
|
194772
|
194773
|
194873
|
194874
|
194878
|
194900
|
194901