From 23353f9d2356306a871c743cb54ab98dc1297be7 Mon Sep 17 00:00:00 2001 From: Sam Lau Date: Wed, 10 Jul 2024 14:36:14 +0000 Subject: [PATCH] Bug 35630: Add ability to log creation, modification, and deletion of authorized values These patches enable librarians to log any changes to authorized values. The feature is dependent on the new 'AuthorizedValuesLog' system preference. To test: 1) Apply patch, updatedatabase, restart_all 2) In Administration->System preferences, search for 'AuthorizedValuesLog' and change to 'Log'. Save your changes. 3) Now go to Administration->Authorized values. Keep this tab open 4) In a new tab, go to Tools -> Log viewer. Ensure that "Authorized values" is checked. 5) Now in AV, click on a category and create a new authorized value. 6) Refresh your log viewer, and the creation should be logged appropiately. 7) Modify an authroized value, this should also be logged correctly. 8) Now delete and authorized value, ensure the logging is correct here as well. 9) Now turn off the system preferece. 10) In the log viewer, 'Authorized values' should have a black triangle next to it, indicating the preference is turned off. 11) Change an AV, this should not be logged. Signed-off-by: Roman Dolny --- Koha/AuthorisedValue.pm | 14 ++++++++++++++ admin/authorised_values.pl | 2 +- .../intranet-tmpl/prog/en/modules/tools/viewlog.tt | 5 ++++- tools/viewlog.pl | 13 +++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm index 5669ab6086..d096f17a7f 100644 --- a/Koha/AuthorisedValue.pm +++ b/Koha/AuthorisedValue.pm @@ -19,6 +19,8 @@ package Koha::AuthorisedValue; use Modern::Perl; +use C4::Log qw(logaction); + use Koha::Caches; use Koha::Database; use Koha::Exceptions; @@ -53,6 +55,8 @@ sub store { my $flush = 0; + my $new_authorized_value = !$self->in_storage; + if ( !$self->in_storage ) { $flush = 1; } @@ -70,6 +74,11 @@ sub store { $self = $self->SUPER::store; + if ( C4::Context->preference("AuthorizedValuesLog") ) { + my $action = $new_authorized_value ? 'CREATE' : 'MODIFY'; + logaction( 'AUTHORIZEDVALUE', $action, $self->id, $self ); + } + if ($flush) { my $key = "AV_descriptions:".$self->category; $cache->clear_from_cache($key); @@ -86,6 +95,11 @@ AuthorisedValue specific C to clear relevant caches on delete. sub delete { my $self = shift @_; + + if ( C4::Context->preference("AuthorizedValuesLog") ) { + logaction( 'AUTHORIZEDVALUE', "DELETE", $self->id, $self ); + } + my $key = "AV_descriptions:".$self->category; $cache->clear_from_cache($key); $self->SUPER::delete(@_); diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index 9513ce7eda..7809a24cdd 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -138,7 +138,7 @@ if ( $op eq 'add_form' or $op eq 'edit_form' ) { lib_opac => scalar $input->param('lib_opac') || undef, imageurl => $imageurl, } - )->store; + ); $av->replace_library_limits( \@branches ); $av->store; }; 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 10b65cfdb3..dda7dd54eb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -102,6 +102,7 @@ [% CASE 'NEWS' %]News[% UNLESS Koha.Preference('NewsLog') %] [% END %] [% CASE 'RECALLS' %]Recalls[% UNLESS Koha.Preference('RecallsLog') %] [% END %] [% CASE 'SUGGESTION' %]Suggestions[% UNLESS Koha.Preference('SuggestionsLog') %] [% END %] +[% CASE 'AUTHORIZEDVALUE' %]Authorized values[% UNLESS Koha.Preference('AuthorizedValuesLog') %] [% END %] [% CASE %][% module | html %] [% END %] @@ -222,7 +223,7 @@ [% ELSE %] [% END %] - [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'CLAIMS' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE', 'NOTICES', 'NEWS', 'RECALLS', 'SUGGESTION' ] %] + [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'CLAIMS' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE', 'NOTICES', 'NEWS', 'RECALLS', 'SUGGESTION', 'AUTHORIZEDVALUE' ] %] [% IF modules.grep(modx).size %] [% ELSE %] @@ -390,6 +391,8 @@ [% END %] [% ELSIF ( loopro.module == "SUGGESTION" ) %] [% loopro.object | html %] + [% ELSIF ( loopro.module == "AUTHORIZEDVALUE" ) %] + [% loopro.object| html %] [% ELSE %] [% loopro.object | html %] [% END %] diff --git a/tools/viewlog.pl b/tools/viewlog.pl index 91cd65df25..60936d3aeb 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -29,6 +29,7 @@ use C4::Serials qw( CountSubscriptionFromBiblionumber ); use C4::Search qw( enabled_staff_search_views ); use Koha::ActionLogs; +use Koha::AuthorisedValues; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Items; @@ -202,6 +203,18 @@ if ($do_it) { } } } + + if ( $log->module eq "AUTHORIZEDVALUE" ) { + if ( $log->object ) { + my $av = Koha::AuthorisedValues->find( $log->object ); + if ( $av && $output eq 'screen' ) { + my $category = $av->category; + $result->{av} = { + category => $category, + }; + } + } + } push @data, $result; } if ( $output eq "screen" ) { -- 2.39.2