[Rt-commit] rt branch, 4.6/log-view-db-config-change-history, repushed
Aaron Trevena
ast at bestpractical.com
Thu Mar 26 16:17:51 EDT 2020
The branch 4.6/log-view-db-config-change-history was deleted and repushed:
was b33406d3f291f9551dac64310645ffe94aa0ee68
now 635e497a3071d2c176c9e8ed937347ac144f0945
1: 039be68775 = 1: 039be68775 Schema updates for tracking db configuration changes in transactions
2: 9599eb692d ! 2: f5de477e2b Log DB config changes as transactions
@@ -21,26 +21,42 @@
--- a/lib/RT/Configuration.pm
+++ b/lib/RT/Configuration.pm
@@
- my ( $id, $msg ) = $self->ValidateName( $args{'Name'} );
- return ( 0, $msg ) unless $id;
-
+ return (0, $self->loc("Permission Denied"))
+ unless $self->CurrentUserHasRight('SuperUser');
+
+- unless ( $args{'Name'} ) {
+- return ( 0, $self->loc("Must specify 'Name' attribute") );
++ if ( $args{'Name'} ) {
++ my ( $ok, $msg ) = $self->ValidateName( $args{'Name'} );
++ unless ($ok) {
++ return ($ok, $msg);
++ }
+ }
+-
+- my ( $id, $msg ) = $self->ValidateName( $args{'Name'} );
+- return ( 0, $msg ) unless $id;
+-
- my $meta = RT->Config->Meta($args{'Name'});
- if ($meta->{Immutable}) {
- return ( 0, $self->loc("You cannot update [_1] using database config; you must edit your site config", $args{'Name'}) );
-- }
--
++ else {
++ return ( 0, $self->loc("Must specify 'Name' attribute") );
+ }
+
- ( $id, $msg ) = $self->ValidateContent( Name => $args{'Name'}, Content => $args{'Content'} );
- return ( 0, $msg ) unless $id;
--
+
- if (ref ($args{'Content'}) ) {
- ($args{'Content'}, my $error) = $self->_SerializeContent($args{'Content'}, $args{'Name'});
- if ($error) {
- return (0, $error);
- }
- $args{'ContentType'} = 'perl';
-+ ( $id, $msg ) = $self->_Create(%args);
++ $RT::Handle->BeginTransaction;
++ my ( $id, $msg ) = $self->_Create(%args);
+ unless ($id) {
-+ return (0, $msg);
++ $RT::Handle->Rollback;
++ return ($id, $msg);
}
- my $old_value = RT->Config->Get($args{Name});
@@ -68,6 +84,7 @@
+ return (0, $self->loc("Setting [_1] to [_2] failed: [_3]", $args{Name}, $content, $tx_msg));
}
++ $RT::Handle->Commit;
RT->Config->ApplyConfigChangeToAllServerProcesses;
- my ($content, $error) = $self->Content;
@@ -94,6 +111,17 @@
}
@@
+
+ return ( 0, $self->loc('empty name') ) unless defined $name && length $name;
+
+- my $TempSetting = RT::Configuration->new( RT->SystemUser );
+- $TempSetting->Load($name);
++ my $TempSetting = RT::Configuration->new( RT->SystemUser );
++ $TempSetting->Load(Name => $name, Disabled => 0);
+
+ if ( $TempSetting->id && ( !$self->id || $TempSetting->id != $self->id ) ) {
+ return ( 0, $self->loc('Name in use') );
+@@
sub Delete {
my $self = shift;
return (0, $self->loc("Permission Denied")) unless $self->CurrentUserCanSee;
@@ -156,7 +184,9 @@
}
- $RT::Handle->BeginTransaction;
-+ my ( $new_id, $new_msg, $value ) = $self->_Create(
++ my ($old_value, $error) = $self->Content;
++ my $old_id = $self->id;
++ my ( $new_id, $new_msg ) = $self->_Create(
+ Name => $self->Name,
+ Content => $raw_value,
+ ContentType => $content_type,
@@ -165,6 +195,7 @@
- ($ok, $msg) = $self->_Set( Field => 'Content', Value => $value );
- if (!$ok) {
++ my $value = $self->Content;
+ unless ($new_id) {
$RT::Handle->Rollback;
- return ($ok, $self->loc("Unable to update [_1]: [_2]", $self->Name, $msg));
@@ -187,7 +218,7 @@
+ ObjectType => 'RT::Configuration',
+ ObjectId => $new_id,
+ ReferenceType => ref($self),
-+ OldReference => $self->id,
++ OldReference => $old_id,
+ NewReference => $new_id,
+ );
+ unless ($Trans) {
@@ -200,7 +231,7 @@
- unless (defined($value) && length($value)) {
- $value = $self->loc('(no value)');
-+ my ($old_value, $error) = $self->Content;
++ RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
+ unless (defined($old_value) && length($old_value)) {
+ $old_value = $self->loc('(no value)');
}
@@ -212,7 +243,6 @@
- RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
- return ($ok, $self->loc("[_1] changed", $self->Name));
- }
-+ RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
+ return( 1, $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value // '', $value // '') );
+
}
@@ -251,7 +281,7 @@
+
+ if ($args{'_Replace'}) {
+ if ($self->Content eq $args{'Content'}) {
-+ return (1, $self->loc("[_1] update: Nothing changed", ucfirst($args{'Name'})));
++ return (0, $self->loc("[_1] update: Nothing changed", ucfirst($args{'Name'})));
+ }
+ }
+
@@ -262,7 +292,7 @@
+ return (0, $self->loc("Setting [_1] to [_2] failed: [_3]", $args{Name}, $args{Content}, $msg));
+ }
+
-+ return ($id, $msg, $args{'Content'});
++ return ($id, $msg);
+}
+
+
3: 1d4c3d4e4d = 3: e348355d09 Remove unused stringify function in configuration edit page
4: fee61e2cc9 ! 4: 2ec4d0a035 Page to view DB config transaction history
@@ -15,9 +15,9 @@
- $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" );
++ $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
@@ -120,11 +120,11 @@
+$Transactions->OrderBy(FIELD => 'Created', ORDER => 'DESC');
+</%INIT>
+<& /Admin/Elements/Header, Title => $title &>
-+ <& /Elements/Tabs &>
-+ <div class="configuration history">
-+ <& /Admin/Elements/ConfigHelp &>
-+ <&|/Widgets/TitleBox, title => loc('History') &>
-+ <div class="history-container">
++<& /Elements/Tabs &>
++<div class="configuration history">
++<& /Admin/Elements/ConfigHelp &>
++<&|/Widgets/TitleBox, title => loc('History') &>
++<div class="history-container">
+% my $i = 1;
+% while (my $tx = $Transactions->Next()) {
+ <& /Elements/ShowTransaction,
@@ -139,7 +139,7 @@
+% $i++;
+% }
+</div>
-+ </&>
-+ </div>
++</&>
++</div>
+
5: b33406d3f2 ! 5: 635e497a30 Tests for DB config transactions and history
@@ -41,15 +41,6 @@
my %args = @_;
@@
- # 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.
-@@
cmp_deeply( $rt_config_value, $args{new_value}, 'value from RT->Config->Get matches new value' );
}
More information about the rt-commit
mailing list