[Rt-commit] rt branch, 4.6/log-view-db-config-change-history, created. rt-4.4.4-881-g9a3386b62
Aaron Trevena
ast at bestpractical.com
Fri Feb 14 09:15:04 EST 2020
The branch, 4.6/log-view-db-config-change-history has been created
at 9a3386b6274453585987412442d471b3a109f14a (commit)
- Log -----------------------------------------------------------------
commit a624e2b4a58506e9fcb453792c9b575041e40593
Author: Aaron Trevena <ast at bestpractical.com>
Date: Tue Jan 14 18:24:45 2020 +0000
Schema updates for tracking db configuration changes in transactions
diff --git a/etc/schema.Oracle b/etc/schema.Oracle
index b71b41d9d..16b01eda6 100644
--- a/etc/schema.Oracle
+++ b/etc/schema.Oracle
@@ -112,7 +112,7 @@ CREATE TABLE Transactions (
ObjectId NUMBER(11,0) DEFAULT 0 NOT NULL,
TimeTaken NUMBER(11,0) DEFAULT 0 NOT NULL,
Type VARCHAR2(20),
- Field VARCHAR2(40),
+ Field VARCHAR2(255),
OldValue VARCHAR2(255),
NewValue VARCHAR2(255),
ReferenceType VARCHAR2(255),
@@ -552,6 +552,5 @@ CREATE TABLE Configurations (
LastUpdated DATE
);
-CREATE UNIQUE INDEX Configurations1 ON Configurations (LOWER(Name));
-CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
diff --git a/etc/schema.Pg b/etc/schema.Pg
index eda93108d..6f35902fc 100644
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -189,18 +189,16 @@ CREATE TABLE Transactions (
ObjectId integer NOT NULL DEFAULT 0 ,
TimeTaken integer NOT NULL DEFAULT 0 ,
Type varchar(20) NULL ,
- Field varchar(40) NULL ,
+ Field varchar(255) NULL ,
OldValue varchar(255) NULL ,
NewValue varchar(255) NULL ,
ReferenceType varchar(255) NULL,
OldReference integer NULL ,
NewReference integer NULL ,
Data varchar(255) NULL ,
-
Creator integer NOT NULL DEFAULT 0 ,
- Created TIMESTAMP NULL ,
+ Created TIMESTAMP NULL,
PRIMARY KEY (id)
-
);
CREATE INDEX Transactions1 ON Transactions (ObjectType, ObjectId);
@@ -793,6 +791,5 @@ CREATE TABLE Configurations (
PRIMARY KEY (id)
);
-CREATE UNIQUE INDEX Configurations1 ON Configurations (LOWER(Name));
-CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index b6e016634..9cd81d15f 100644
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -121,17 +121,15 @@ CREATE TABLE Transactions (
ObjectId integer NULL DEFAULT 0 ,
TimeTaken integer NULL DEFAULT 0 ,
Type varchar(20) collate NOCASE NULL ,
- Field varchar(40) collate NOCASE NULL ,
+ Field varchar(255) collate NOCASE NULL ,
OldValue varchar(255) collate NOCASE NULL ,
NewValue varchar(255) collate NOCASE NULL ,
ReferenceType varchar(255) collate NOCASE NULL ,
OldReference integer NULL ,
NewReference integer NULL ,
Data varchar(255) collate NOCASE NULL ,
-
Creator integer NULL DEFAULT 0 ,
- Created DATETIME NULL
-
+ Created DATETIME NULL
) ;
CREATE INDEX Transactions1 ON Transactions (ObjectType, ObjectId);
@@ -582,6 +580,5 @@ CREATE TABLE Configurations (
LastUpdated timestamp DEFAULT NULL
);
-CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
-CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
diff --git a/etc/schema.mysql b/etc/schema.mysql
index b0b374c73..df8f5042a 100644
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -108,14 +108,13 @@ CREATE TABLE Transactions (
ObjectId integer NOT NULL DEFAULT 0 ,
TimeTaken integer NOT NULL DEFAULT 0 ,
Type varchar(20) CHARACTER SET ascii NULL,
- Field varchar(40) CHARACTER SET ascii NULL,
+ Field varchar(255) CHARACTER SET ascii NULL,
OldValue varchar(255) NULL ,
NewValue varchar(255) NULL ,
ReferenceType varchar(255) CHARACTER SET ascii NULL,
OldReference integer NULL ,
NewReference integer NULL ,
Data varchar(255) NULL ,
-
Creator integer NOT NULL DEFAULT 0 ,
Created DATETIME NULL ,
PRIMARY KEY (id)
@@ -573,6 +572,5 @@ CREATE TABLE Configurations (
PRIMARY KEY (id)
) ENGINE=InnoDB CHARACTER SET utf8mb4;
-CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
-CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
diff --git a/etc/upgrade/4.5.1/schema.Oracle b/etc/upgrade/4.5.1/schema.Oracle
index d275ae92b..a73d19bb1 100644
--- a/etc/upgrade/4.5.1/schema.Oracle
+++ b/etc/upgrade/4.5.1/schema.Oracle
@@ -11,5 +11,6 @@ CREATE TABLE Configurations (
LastUpdated DATE
);
-CREATE UNIQUE INDEX Configurations1 ON Configurations (LOWER(Name));
-CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
+
+
diff --git a/etc/upgrade/4.5.1/schema.Pg b/etc/upgrade/4.5.1/schema.Pg
index eecba576b..7cd39e860 100644
--- a/etc/upgrade/4.5.1/schema.Pg
+++ b/etc/upgrade/4.5.1/schema.Pg
@@ -12,5 +12,6 @@ CREATE TABLE Configurations (
PRIMARY KEY (id)
);
-CREATE UNIQUE INDEX Configurations1 ON Configurations (LOWER(Name));
-CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
+
+
diff --git a/etc/upgrade/4.5.1/schema.SQLite b/etc/upgrade/4.5.1/schema.SQLite
index a8f280d33..403c89219 100644
--- a/etc/upgrade/4.5.1/schema.SQLite
+++ b/etc/upgrade/4.5.1/schema.SQLite
@@ -10,6 +10,5 @@ CREATE TABLE Configurations (
LastUpdated timestamp DEFAULT NULL
);
-CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
-CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
diff --git a/etc/upgrade/4.5.1/schema.mysql b/etc/upgrade/4.5.1/schema.mysql
index 80eda8113..69ebc68ae 100644
--- a/etc/upgrade/4.5.1/schema.mysql
+++ b/etc/upgrade/4.5.1/schema.mysql
@@ -11,5 +11,4 @@ CREATE TABLE Configurations (
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
-CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
diff --git a/etc/upgrade/4.5.3/schema.Oracle b/etc/upgrade/4.5.3/schema.Oracle
new file mode 100644
index 000000000..2f61d6a0a
--- /dev/null
+++ b/etc/upgrade/4.5.3/schema.Oracle
@@ -0,0 +1,2 @@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR2(255);
diff --git a/etc/upgrade/4.5.3/schema.Pg b/etc/upgrade/4.5.3/schema.Pg
new file mode 100644
index 000000000..c2e7764c3
--- /dev/null
+++ b/etc/upgrade/4.5.3/schema.Pg
@@ -0,0 +1,2 @@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR(255) NULL;
diff --git a/etc/upgrade/4.5.3/schema.SQLite b/etc/upgrade/4.5.3/schema.SQLite
new file mode 100644
index 000000000..16c0fb543
--- /dev/null
+++ b/etc/upgrade/4.5.3/schema.SQLite
@@ -0,0 +1,2 @@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR(255) collate NOCASE NULL;
diff --git a/etc/upgrade/4.5.3/schema.mysql b/etc/upgrade/4.5.3/schema.mysql
new file mode 100644
index 000000000..2cd4d554d
--- /dev/null
+++ b/etc/upgrade/4.5.3/schema.mysql
@@ -0,0 +1,2 @@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR(255) CHARACTER SET ascii DEFAULT NULL;
\ No newline at end of file
commit 0fef3f1d2b17441ad2b84eb1ec7761edd3de8d6b
Author: Aaron Trevena <ast at bestpractical.com>
Date: Fri Feb 14 11:00:36 2020 +0000
Log DB config changes as transactions
Implementation of storing Configuration change history in transactions
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 9362e2a66..8630974ff 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -2542,7 +2542,7 @@ sub LoadConfigFromDatabase {
$database_config_cache_time = time;
my $settings = RT::Configurations->new(RT->SystemUser);
- $settings->UnLimit;
+ $settings->LimitToEnabled;
my %seen;
diff --git a/lib/RT/Configuration.pm b/lib/RT/Configuration.pm
index 0d7c3ddf6..6e12df309 100644
--- a/lib/RT/Configuration.pm
+++ b/lib/RT/Configuration.pm
@@ -147,20 +147,30 @@ sub Create {
$content = $self->loc('(no value)');
}
+ my $old_content_type;
if ( ref $old_value ) {
$old_value = $self->_SerializeContent($old_value);
+ $old_content_type = 'perl';
}
- RT->Logger->info(
- sprintf(
- '%s changed %s from "%s" to "%s"',
- $self->CurrentUser->Name,
- $self->Name,
- $old_value // '',
- $content // ''
- )
+ my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
+ Type => 'SetConfig',
+ Field => $self->Name,
+ ObjectType => 'RT::Configuration',
+ ObjectId => $self->id,
+ NewValue => ( $args{content_type} ) ? sprintf('%s value', $args{content_type}) : $content,
+ OldValue => ( $old_content_type ) ? sprintf('%s value', $old_content_type) : $old_value,
+ ReferenceType => ref($self),
+ NewReference => $self->id,
);
- return ( $id, $self->loc( '[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value // '', $content // '' ) );
+
+ if (not ($old_content_type || $args{content_type}) ) {
+ RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name . " from " . $old_value . " to " . $content);
+ return ($id, $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value // '', $content // ''));
+ } else {
+ RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
+ return ($id, $self->loc("[_1] changed", $self->Name));
+ }
}
=head2 CurrentUserCanSee
@@ -239,10 +249,23 @@ processes.
sub Delete {
my $self = shift;
return (0, $self->loc("Permission Denied")) unless $self->CurrentUserCanSee;
- my ($ok, $msg) = $self->SUPER::Delete(@_);
+ my $old_value = ( ref $self->Content ) ? sprintf('%s value', $self->ContentType) : $self->Content;
+ my ( $ok, $msg ) = $self->SetDisabled( 1 );
return ($ok, $msg) if !$ok;
RT->Config->ApplyConfigChangeToAllServerProcesses;
RT->Logger->info($self->CurrentUser->Name . " removed database setting for " . $self->Name);
+
+ my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
+ Type => 'DeleteConfig',
+ Field => $self->Name,
+ ObjectType => 'RT::Configuration',
+ ObjectId => $self->Id,
+ NewValue => $self->loc("Deleted"),
+ ReferenceType => ref($self),
+ OldReference => $self->id,
+ OldValue => $old_value,
+ );
+
return ($ok, $self->loc("Database setting removed."));
}
@@ -297,30 +320,39 @@ sub SetContent {
$content_type = 'perl';
}
- $RT::Handle->BeginTransaction;
+ ( $ok, $msg ) = $self->SetDisabled( 1 );
+ return ($ok, $msg) if !$ok;
- ($ok, $msg) = $self->_Set( Field => 'Content', Value => $value );
- if (!$ok) {
- $RT::Handle->Rollback;
- return ($ok, $self->loc("Unable to update [_1]: [_2]", $self->Name, $msg));
- }
+ my ( $new_id, $new_msg ) = $self->SUPER::Create(
+ Name => $self->Name,
+ Content => $value,
+ ContentType => $content_type,
+ Disabled => 0,
+ );
- if ($self->ContentType ne $content_type) {
- ($ok, $msg) = $self->_Set( Field => 'ContentType', Value => $content_type );
- if (!$ok) {
- $RT::Handle->Rollback;
- return ($ok, $self->loc("Unable to update [_1]: [_2]", $self->Name, $msg));
- }
+ unless ($new_id) {
+ return (0, $self->loc("Setting [_1] to [_2] failed: [_3]", $self->Name, $value, $new_msg));
}
- $RT::Handle->Commit;
RT->Config->ApplyConfigChangeToAllServerProcesses;
unless (defined($value) && length($value)) {
$value = $self->loc('(no value)');
}
- if (!ref($value) && !ref($old_value)) {
+ my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
+ Type => 'SetConfig',
+ Field => $self->Name,
+ ObjectType => 'RT::Configuration',
+ ObjectId => $new_id,
+ NewValue => ( $content_type ) ? sprintf('%s value', $content_type) : $value,
+ OldValue => ( $self->ContentType ) ? sprintf('%s value', $self->ContentType) : $self->Content,
+ ReferenceType => ref($self),
+ OldReference => $self->id,
+ NewReference => $new_id,
+ );
+
+ if ( not ($self->ContentType || $content_type) ) {
RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name . " from " . $old_value . " to " . $value);
return ($ok, $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value, $value));
} else {
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 914fe51ca..84297f47b 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1999,7 +1999,7 @@ sub _CoreAccessible {
Type =>
{read => 1, write => 1, sql_type => 12, length => 20, is_blob => 0, is_numeric => 0, type => 'varchar(20)', default => ''},
Field =>
- {read => 1, write => 1, sql_type => 12, length => 40, is_blob => 0, is_numeric => 0, type => 'varchar(40)', default => ''},
+ {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
OldValue =>
{read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
NewValue =>
diff --git a/share/html/Admin/Tools/EditConfig.html b/share/html/Admin/Tools/EditConfig.html
index 603c46ce8..a974e274e 100644
--- a/share/html/Admin/Tools/EditConfig.html
+++ b/share/html/Admin/Tools/EditConfig.html
@@ -62,19 +62,6 @@ my $active_context = {
my @results;
-use Data::Dumper;
-my $stringify = sub {
- my $value = shift;
- return "" if !defined($value);
-
- local $Data::Dumper::Terse = 1;
- local $Data::Dumper::Indent = 2;
- local $Data::Dumper::Sortkeys = 1;
- my $output = Dumper $value;
- chomp $output;
- return $output;
-};
-
if (delete $ARGS{Update}) {
RT->Config->BeginDatabaseConfigChanges;
$RT::Handle->BeginTransaction;
@@ -140,14 +127,6 @@ if (delete $ARGS{Update}) {
my $setting = RT::Configuration->new($session{CurrentUser});
$setting->Load($key);
if ($setting->Id) {
- if ($setting->Disabled) {
- my ($ok, $msg) = $setting->SetDisabled(0);
- if (!$ok) {
- push @results, $msg;
- $has_error++;
- }
- }
-
my ($ok, $msg) = $setting->SetContent($val);
push @results, $msg;
$has_error++ if !$ok;
@@ -178,6 +157,7 @@ if (delete $ARGS{Update}) {
$RT::Handle->Commit;
}
RT->Config->EndDatabaseConfigChanges;
+ RT->Config->ApplyConfigChangeToAllServerProcesses unless ($has_error);
}
my $nav_type='tab'; # 'tab' or 'pill'
@@ -216,4 +196,4 @@ my $nav_type='tab'; # 'tab' or 'pill'
% }
</div><!-- content-all -->
</div><!-- titlebox-content -->
-</div><!-- configuration -->
\ No newline at end of file
+</div><!-- configuration -->
commit c0379d022523d0dec34056658f51bea546312bec
Author: Aaron Trevena <ast at bestpractical.com>
Date: Fri Feb 14 11:02:44 2020 +0000
Log DB config changes as transactions
Added page to view transaction log or configurations
diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 5ce829c46..9dd2f8d5b 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -701,9 +701,10 @@ sub BuildMainNav {
$page->child( edit => raw_html => q[<a id="page-edit" class="menu-item" href="] . RT->Config->Get('WebPath') . qq[/Prefs/MyRT.html"><span class="fas fa-cog" alt="$alt" data-toggle="tooltip" data-placement="top" data-original-title="$alt"></span></a>] );
}
- if ( $request_path =~ m{^/Admin/Tools/(Configuration|EditConfig)} ) {
- $page->child( display => title => loc('View'), path => "/Admin/Tools/Configuration.html" );
- $page->child( history => title => loc('Edit'), path => "/Admin/Tools/EditConfig.html" );
+ if ( $request_path =~ m{^/Admin/Tools/(Configuration|EditConfig|ConfigHistory)} ) {
+ $page->child( "display", title => loc('View'), path => "/Admin/Tools/Configuration.html" );
+ $page->child( "modify", title => loc('Edit'), path => "/Admin/Tools/EditConfig.html" );
+ $page->child( "history", title => loc('History'), path => "/Admin/Tools/ConfigHistory.html" );
}
# due to historical reasons of always having been in /Elements/Tabs
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 5b2b8d2d3..066843652 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1880,6 +1880,7 @@ sub CustomFieldLookupId {
return $self->Id unless @classes;
my $object = $self;
+ return $self->Id if (ref($object) eq 'RT::Configuration');
# Save a ->Load call by not calling ->FooObj->Id, just ->Foo
my $final = shift @classes;
foreach my $class (reverse @classes) {
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 84297f47b..7f5019533 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -135,8 +135,6 @@ sub Create {
return ( 0, $self->loc( "Transaction->Create couldn't, as you didn't specify an object type and id"));
}
-
-
#lets create our transaction
my %params = (
Type => $args{'Type'},
@@ -1380,6 +1378,43 @@ sub _CanonicalizeRoleName {
my $self = shift;
return "Attachment content modified";
},
+ SetConfig => sub {
+ my $self = shift;
+ my $new_value = $self->NewValue;
+ my $old_value = $self->OldValue;
+
+ # pull in old value from reference if data structure
+ if ($old_value =~ m/^(perl|json).value$/) {
+ my $oldobj = RT::Configuration->new($self->CurrentUser);
+ $oldobj->Load($self->OldReference);
+ $old_value = $oldobj->Content;
+ }
+
+ # pull in new value from reference if data structure
+ if ($new_value =~ m/^(perl|json).value$/) {
+ my $newobj = RT::Configuration->new($self->CurrentUser);
+ $newobj->Load($self->NewReference);
+ $new_value = $newobj->Content;
+ }
+
+ my $description = sprintf('<b>%s updated %s</b><br/>%s', $self->CreatorObj->Name, $self->Field, "\n");
+ $description .= $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Field, $old_value || '', $new_value || '');
+ return $description;
+ },
+ DeleteConfig => sub {
+ my $self = shift;
+ my $description = sprintf('<b>%s deleted %s</b><br/>%s', $self->CreatorObj->Name, $self->Field,"\n");
+ my $old_value = $self->OldValue;
+ # pull in old value from reference if data structure
+ if ($old_value =~ m/^(perl|json).value$/) {
+ my $oldobj = RT::Configuration->new($self->CurrentUser);
+ $oldobj->Load($self->OldReference);
+ $old_value = $oldobj->Content;
+ }
+
+ $description .= $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Field, $old_value, $self->loc("Deleted"));
+ return $description;
+ }
);
@@ -1631,7 +1666,15 @@ be passed to RT::CustomField->Create() via the 'LookupType' hash key.
sub CustomFieldLookupType {
- "RT::Queue-RT::Ticket-RT::Transaction";
+ my $self = shift;
+
+ # skip if it's a table/class with no custom fields
+ if (ref($self) && ($self->ObjectType =~ m/RT::(Configuration)/)) {
+ return "";
+ }
+ else {
+ return "RT::Queue-RT::Ticket-RT::Transaction";
+ }
}
diff --git a/share/html/Admin/Tools/ConfigHistory.html b/share/html/Admin/Tools/ConfigHistory.html
new file mode 100644
index 000000000..6cb6f325a
--- /dev/null
+++ b/share/html/Admin/Tools/ConfigHistory.html
@@ -0,0 +1,86 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<%INIT>
+my $title = loc('System Configuration');
+unless ($session{'CurrentUser'}->HasRight( Object=> $RT::System, Right => 'SuperUser')) {
+ Abort(loc('This feature is only available to system administrators'));
+}
+
+# get the transactions?
+# start off just getting all of them!
+
+my $Transactions = RT::Transactions->new($session{CurrentUser});
+$Transactions->Limit(FIELD => 'ObjectType', VALUE => 'RT::Configuration');
+$Transactions->OrderBy(FIELD => 'Created', ORDER => 'DESC');
+</%INIT>
+<& /Admin/Elements/Header, Title => $title &>
+<& /Elements/Tabs &>
+ <div class="configuration">
+ <div class="history configurations" id="configurations">
+ <& /Widgets/TitleBoxStart, title => $title, class => 'fullwidth' &>
+ </div>
+<div class="history-container">
+% my $i = 1;
+% while (my $tx = $Transactions->Next()) {
+<& /Elements/ShowTransaction,
+ Transaction => $tx,
+ ShowHeaders => 1,
+ ShowDisplayModes => 0,
+ ShowActions => 1,
+ HasTxnCFs => 0,
+ RowNum => $i
+&>
+% $i++;
+% }
+</div>
+ </div>
+</div>
+<hr class="clear">
+</div>
+</div>
+
commit 9a3386b6274453585987412442d471b3a109f14a
Author: Aaron Trevena <ast at bestpractical.com>
Date: Fri Feb 14 11:03:15 2020 +0000
Log DB config changes as transactions
Added unit tests for storing and viewing Configuration change history in transactions
diff --git a/t/web/admin_tools_editconfig.t b/t/web/admin_tools_editconfig.t
index 5b4cbd43a..a2ea9b3a7 100644
--- a/t/web/admin_tools_editconfig.t
+++ b/t/web/admin_tools_editconfig.t
@@ -10,6 +10,7 @@ my ( $url, $m ) = RT::Test->started_ok;
ok( $m->login(), 'logged in' );
$m->follow_link_ok( { text => 'System Configuration' }, 'followed link to "System Configuration"' );
+$m->follow_link_ok( { text => 'History' }, 'followed link to History page' );
$m->follow_link_ok( { text => 'Edit' }, 'followed link to Edit page' );
my $tests = [
@@ -41,6 +42,24 @@ my $tests = [
run_test( %{$_} ) for @{$tests};
+# check tx log for configuration
+my $transactions = RT::Transactions->new(RT->SystemUser);
+$transactions->Limit(FIELD => 'ObjectType', VALUE => 'RT::Configuration');
+$transactions->OrderBy(FIELD => 'Created', ORDER => 'ASC');
+my $tx_items = $transactions->ItemsArrayRef;
+
+my $i = 0;
+foreach my $change (@{$tests}) {
+ check_transaction( $tx_items->[$i++], $change );
+}
+
+# check config history page
+$m->get_ok( $url . '/Admin/Tools/ConfigHistory.html');
+$i = 0;
+foreach my $change (@{$tests}) {
+ check_history_page_item($tx_items->[$i++], $change );
+}
+
sub run_test {
my %args = @_;
@@ -60,7 +79,7 @@ sub run_test {
# ensure the config object in the test is up to date with the changes.
RT->Config->LoadConfigFromDatabase();
- $m->content_like( qr/$args{setting} changed from/, 'UI indicated the value was changed' );
+ $m->content_like( qr/$args{setting} changed/, 'UI indicated the value was changed' );
# RT::Configuration->Content returns the value as string.
# in the test below we need to also ensure the new value is string.
@@ -74,6 +93,26 @@ sub run_test {
cmp_deeply( $rt_config_value, $args{new_value}, 'value from RT->Config->Get matches new value' );
}
+sub check_transaction {
+ my ($tx, $change) = @_;
+ is($tx->ObjectType, 'RT::Configuration', 'tx is config change');
+ is($tx->Field, $change->{setting}, 'tx matches field changed');
+ is($tx->NewValue, stringify($change->{new_value}), 'tx value matches');
+ $change->{tx_id} = $tx->id;
+}
+
+sub check_history_page_item {
+ my ($tx, $change) = @_;
+ my $link = "/Transaction/Display.html?id=".$tx->id;
+ ok($m->find_link(url => $link), 'found tx link in history');
+
+ my $link_m = $m->clone;
+ $link_m->get_ok($link, 'fetched tx link in history ok');
+ $link_m->content_contains(stringify($change->{new_value}), 'fetched tx has new value');
+ $link_m->content_contains( "$change->{setting} changed from", 'fetched tx has changed field');
+}
+
+
sub stringify {
my $value = shift;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list