[Rt-commit] rt branch, 4.6/log-view-db-config-change-history, created. rt-4.4.4-881-ge8aa05257

Aaron Trevena ast at bestpractical.com
Tue Mar 10 14:23:58 EDT 2020


The branch, 4.6/log-view-db-config-change-history has been created
        at  e8aa052571775de3552356a39537070e5b617586 (commit)

- Log -----------------------------------------------------------------
commit 4bd810170ccc0e50527b1c9b0decdb542c27c169
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..2f53b36a9 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 Configurations1 ON Configurations (LOWER(Name), Disabled);
 CREATE INDEX Configurations2 ON Configurations (Disabled);
-
diff --git a/etc/schema.Pg b/etc/schema.Pg
index eda93108d..330eacaa2 100644
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -189,7 +189,7 @@ 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,
@@ -793,6 +793,6 @@ CREATE TABLE Configurations (
     PRIMARY KEY (id)
 );
 
-CREATE UNIQUE INDEX Configurations1 ON Configurations (LOWER(Name));
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
 CREATE INDEX Configurations2 ON Configurations (Disabled);
 
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index b6e016634..c51070aa8 100644
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -121,7 +121,7 @@ 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  ,
@@ -582,6 +582,6 @@ CREATE TABLE Configurations (
     LastUpdated       timestamp                DEFAULT NULL
 );
 
-CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
 CREATE INDEX Configurations2 ON Configurations (Disabled);
 
diff --git a/etc/schema.mysql b/etc/schema.mysql
index b0b374c73..2bd075c65 100644
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -108,7 +108,7 @@ 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,
@@ -573,6 +573,6 @@ CREATE TABLE Configurations (
     PRIMARY KEY (id)
 ) ENGINE=InnoDB CHARACTER SET utf8mb4;
 
-CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
+CREATE INDEX Configurations1 ON Configurations (Name(128), Disabled);
 CREATE INDEX Configurations2 ON Configurations (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..689ebfcdd
--- /dev/null
+++ b/etc/upgrade/4.5.3/schema.Oracle
@@ -0,0 +1,5 @@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR2(255);
+
+DROP INDEX Configurations1;
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
\ No newline at end of file
diff --git a/etc/upgrade/4.5.3/schema.Pg b/etc/upgrade/4.5.3/schema.Pg
new file mode 100644
index 000000000..4e82b8d62
--- /dev/null
+++ b/etc/upgrade/4.5.3/schema.Pg
@@ -0,0 +1,5 @@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR(255) NULL;
+
+DROP INDEX IF EXISTS Configurations1;
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
\ No newline at end of file
diff --git a/etc/upgrade/4.5.3/schema.SQLite b/etc/upgrade/4.5.3/schema.SQLite
new file mode 100644
index 000000000..639ba63cd
--- /dev/null
+++ b/etc/upgrade/4.5.3/schema.SQLite
@@ -0,0 +1,5 @@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR(255) collate NOCASE NULL;
+
+DROP INDEX IF EXISTS Configurations1;
+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
\ No newline at end of file
diff --git a/etc/upgrade/4.5.3/schema.mysql b/etc/upgrade/4.5.3/schema.mysql
new file mode 100644
index 000000000..9ddd0d83b
--- /dev/null
+++ b/etc/upgrade/4.5.3/schema.mysql
@@ -0,0 +1,5 @@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR(255) CHARACTER SET ascii DEFAULT NULL;
+
+DROP INDEX IF EXISTS Configurations1;
+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
\ No newline at end of file
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..acda940c1 100644
--- a/share/html/Admin/Tools/EditConfig.html
+++ b/share/html/Admin/Tools/EditConfig.html
@@ -216,4 +216,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 dd73ca7707c0bb90d6b801e812291568a775e610
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..8ef3e2181 100644
--- a/lib/RT/Configuration.pm
+++ b/lib/RT/Configuration.pm
@@ -127,11 +127,6 @@ sub Create {
         $args{'ContentType'} = 'perl';
     }
 
-    my $old_value = RT->Config->Get($args{Name});
-    unless (defined($old_value) && length($old_value)) {
-        $old_value = $self->loc('(no value)');
-    }
-
     ( $id, $msg ) = $self->SUPER::Create(
         map { $_ => $args{$_} } grep {exists $args{$_}}
             qw(Name Content ContentType),
@@ -147,20 +142,17 @@ sub Create {
         $content = $self->loc('(no value)');
     }
 
-    if ( ref $old_value ) {
-        $old_value = $self->_SerializeContent($old_value);
-    }
-
-    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,
+        ReferenceType => ref($self),
+        NewReference => $self->id,
     );
-    return ( $id, $self->loc( '[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value // '', $content // '' ) );
+
+    RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
+    return ($id, $self->loc("[_1] changed", $self->Name));
 }
 
 =head2 CurrentUserCanSee
@@ -239,10 +231,20 @@ processes.
 sub Delete {
     my $self = shift;
     return (0, $self->loc("Permission Denied")) unless $self->CurrentUserCanSee;
-    my ($ok, $msg) = $self->SUPER::Delete(@_);
+    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,
+        ReferenceType => ref($self),
+        OldReference => $self->id,
+    );
+
     return ($ok, $self->loc("Database setting removed."));
 }
 
@@ -298,35 +300,43 @@ sub SetContent {
     }
 
     $RT::Handle->BeginTransaction;
-
-    ($ok, $msg) = $self->_Set( Field => 'Content', Value => $value );
-    if (!$ok) {
+    ( $ok, $msg ) = $self->SetDisabled( 1 );
+    unless ($ok) {
         $RT::Handle->Rollback;
-        return ($ok, $self->loc("Unable to update [_1]: [_2]", $self->Name, $msg));
+        return ($ok, $msg);
     }
 
-    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));
-        }
+    my ( $new_id, $new_msg ) = $self->SUPER::Create(
+        Name => $self->Name,
+        Content => $value,
+        ContentType => $content_type,
+        Disabled => 0,
+    );
+
+    unless ($new_id) {
+        $RT::Handle->Rollback;
+        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)) {
-        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 {
-        RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
-        return ($ok, $self->loc("[_1] changed", $self->Name));
-    }
+    my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
+        Type => 'SetConfig',
+        Field => $self->Name,
+        ObjectType => 'RT::Configuration',
+        ObjectId => $new_id,
+        ReferenceType => ref($self),
+        OldReference => $self->id,
+        NewReference => $new_id,
+    );
+
+    $RT::Handle->Commit;
+    RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
+    return( 1, $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value || '', $value || '') );
 }
 
 =head2 ValidateContent
diff --git a/share/html/Admin/Tools/EditConfig.html b/share/html/Admin/Tools/EditConfig.html
index acda940c1..7ec998fd9 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;

commit 985d5440226f381b75f0aae202f1fb871fa12f4b
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Fri Feb 14 11:02:44 2020 +0000

    Page to view DB config transaction history
    
    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..dfe625e19 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1380,6 +1380,31 @@ sub _CanonicalizeRoleName {
         my $self = shift;
         return "Attachment content modified";
     },
+    SetConfig => sub  {
+        my $self = shift;
+        my ($new_value, $old_value);
+
+        # pull in old value from reference if exists
+        if ( $self->OldReference ) {
+            my $oldobj = RT::Configuration->new($self->CurrentUser);
+            $oldobj->Load($self->OldReference);
+            $old_value = $oldobj->Content;
+        }
+
+        # pull in new value from reference if exists
+        if ( $self->NewReference ) {
+            my $newobj = RT::Configuration->new($self->CurrentUser);
+            $newobj->Load($self->NewReference);
+            $new_value = $newobj->Content;
+        }
+        my $description .= $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Field, $old_value || '', $new_value || '');
+        return $description;
+    },
+    DeleteConfig => sub  {
+        my $self = shift;
+        my $description = $self->loc('[_1] Deleted"', $self->Field);
+        return $description;
+    }
 );
 
 
@@ -1629,12 +1654,13 @@ be passed to RT::CustomField->Create() via the 'LookupType' hash key.
 
 =cut
 
+# Note this will cause errors in /Transaction/Display.html for some non-ticket objects
+# such as RT::Configuration, pass DisplayPath => '#' to not link to /Transaction/Display.html
 
 sub CustomFieldLookupType {
-    "RT::Queue-RT::Ticket-RT::Transaction";
+    "RT::Queue-RT::Ticket-RT::Transaction"
 }
 
-
 =head2 SquelchMailTo
 
 Similar to Ticket class SquelchMailTo method - returns a list of
diff --git a/share/html/Admin/Tools/ConfigHistory.html b/share/html/Admin/Tools/ConfigHistory.html
new file mode 100644
index 000000000..25869c427
--- /dev/null
+++ b/share/html/Admin/Tools/ConfigHistory.html
@@ -0,0 +1,78 @@
+%# 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'));
+}
+
+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">
+  <& /Admin/Elements/ConfigHelp &>
+  <&|/Widgets/TitleBox, title => loc('History'), class => 'fullwidth' &>
+% my $i = 1;
+% while (my $tx = $Transactions->Next()) {
+    <& /Elements/ShowTransaction,
+    Transaction => $tx,
+    ShowHeaders => 1,
+    ShowDisplayModes => 0,
+    ShowActions => 1,
+    DisplayPath => '#',
+    HasTxnCFs => 0,
+    RowNum => $i
+     &>
+% $i++;
+% }
+    </&>
+  </div>
+

commit e8aa052571775de3552356a39537070e5b617586
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Fri Feb 14 11:03:15 2020 +0000

    Tests for DB config transactions and history
    
    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..0f6324292 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,22 @@ 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 = sprintf('#?id=%d#txn-%d', $tx->ObjectId,$tx->id);
+    ok($m->find_link(url => $link), 'found tx link in history');
+    $m->content_contains(stringify($change->{new_value}), 'fetched tx has new value');
+    $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