[Rt-commit] rt branch, 5.0/delete-db-configs-web-ui, created. rt-5.0.1-544-g90104b7083

? sunnavy sunnavy at bestpractical.com
Tue Jun 22 18:38:05 EDT 2021


The branch, 5.0/delete-db-configs-web-ui has been created
        at  90104b708378e92810446ed7b02eae8f3e0ed91f (commit)

- Log -----------------------------------------------------------------
commit 90104b708378e92810446ed7b02eae8f3e0ed91f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jun 9 01:23:46 2021 +0800

    Support to delete configs in database from web UI

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index c03bc2fffd..9a5348a096 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -2828,6 +2828,11 @@ sub LoadConfigFromDatabase {
     }
 }
 
+sub _GetFromFilesOnly {
+    my ( $self, $name ) = @_;
+    return $original_setting_from_files{$name} ? $original_setting_from_files{$name}[0] : undef;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/share/html/Admin/Elements/ConfigHelp b/share/html/Admin/Elements/ConfigHelp
index 2c164eecf1..4ace280b08 100644
--- a/share/html/Admin/Elements/ConfigHelp
+++ b/share/html/Admin/Elements/ConfigHelp
@@ -48,6 +48,6 @@
 <div class="help" id="rt-help-text">
 <&| /Widgets/TitleBox, title => loc('RT Configuration') &>
 <p>RT has dozens of configuration options to allow you to modify RT to meet your needs. You can view details about each configuration option online in the <a href="https://docs.bestpractical.com/rt/latest/RT_Config.html" target="_blank">RT documentation</a> or in the file <code>etc/RT_Config.pm</code> on your RT server. You can set global configuration options in the file <code>etc/RT_SiteConfig.pm</code> or right in the browser by clicking the Edit link.</p>
-<p>Changes made in the web interface take precedence over customizations in server configuration files. Some core settings can only be changed in configuration files.</p>
+<p>Changes made in the web interface take precedence over customizations in server configuration files. Some core settings can only be changed in configuration files. Check "Reset" to switch to the corresponding value in configuration files.</p>
 </&>
 </div>
diff --git a/share/html/Admin/Tools/Config/Elements/Option b/share/html/Admin/Tools/Config/Elements/Option
index 054102cac9..1d372ff309 100644
--- a/share/html/Admin/Tools/Config/Elements/Option
+++ b/share/html/Admin/Tools/Config/Elements/Option
@@ -92,6 +92,20 @@ my $is_immutable = $meta->{Immutable}
                 || ( $format eq 'code' && $widget ne '/Widgets/Form/CustomDateRanges' );
 
 my $current_value = $format ? $val : $raw_value;
+
+my $current_file_value;
+
+my $db_config = RT::Configuration->new($session{CurrentUser});
+$db_config->LoadByCols(Name => $name, Disabled => 0);
+if ( $db_config->Id ) {
+    my $raw_value = RT->Config->_GetFromFilesOnly($name);
+    my ( $val, $format ) = $stringify->($raw_value);
+    $current_file_value = $format ? $val : $raw_value;
+}
+else {
+    $current_file_value = $current_value;
+}
+
 my $args   = $meta->{'WidgetArguments'} || {};
 if ($widget eq '/Widgets/Form/Boolean') {
     %$args = (
@@ -153,11 +167,18 @@ my $row_end = qq{</div></div>};
     Description  => $name,
     Hints        => $meta->{WidgetArguments}->{Hints} || '',
     LabelCols    => 4,
-    ValueCols    => 8,
+    ValueCols    => 6,
     %$args,
     %{ $m->comp('/Widgets/FinalizeWidgetArguments', WidgetArguments =>
             $meta->{'WidgetArguments'} ) },
   &>
+% if ( $name ne 'CustomDateRanges' ) {
+  <div class="col-2 file-config mt-1">
+    <& /Widgets/Form/Boolean:InputOnly, Name => "$name-file", CurrentValue => !$db_config->Id, DefaultLabel => loc('Reset') &>
+    <input type="hidden" name="<% $name %>-file-Current" value="<% $current_file_value %>" />
+  </div>
+% }
+
 <textarea class="hidden" name="<% $name %>-Current"><% $current_value %></textarea>
 % }
 <!-- end option <% $name %> -->
diff --git a/share/html/Admin/Tools/EditConfig.html b/share/html/Admin/Tools/EditConfig.html
index d49ede8245..bafaf8d405 100644
--- a/share/html/Admin/Tools/EditConfig.html
+++ b/share/html/Admin/Tools/EditConfig.html
@@ -73,11 +73,22 @@ if (delete $ARGS{Update}) {
 
     eval {
         for my $key (keys %ARGS) {
-            next if $key =~ /-Current$/;
+            next if $key =~ /-(?:Current|file)$/;
             next if $key eq 'tab' || $key eq 'section' || $key eq 'subsection';
             # Get rid of extra arguments like in CustomDateRanges
             next if !exists $ARGS{$key . '-Current'};
 
+            my $setting = RT::Configuration->new($session{CurrentUser});
+            $setting->LoadByCols(Name => $key, Disabled => 0);
+            if ( $ARGS{"$key-file"} ) {
+                if ( $setting->Id ) {
+                    my ( $ok, $msg ) = $setting->Delete;
+                    push @results, $msg;
+                    $has_error++ if !$ok;
+                }
+                next;
+            }
+
             my $meta = RT->Config->Meta( $key );
             my $widget = $meta->{Widget} || '/Widgets/Form/JSON';
             my $is_json = $widget eq '/Widgets/Form/JSON';
@@ -108,8 +119,6 @@ if (delete $ARGS{Update}) {
                     next;
                 }
             }
-            my $setting = RT::Configuration->new($session{CurrentUser});
-            $setting->LoadByCols(Name => $key, Disabled => 0);
             if ($setting->Id) {
                 my ($ok, $msg) = $setting->SetContent($val);
                 push @results, $msg;
diff --git a/share/static/js/util.js b/share/static/js/util.js
index bd9cc01a5a..d0eef36742 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -826,6 +826,47 @@ jQuery(function() {
             });
         });
     }
+
+    // Move reset col to the corresponding edit row
+    jQuery('form[name=EditConfig] div.file-config').each(function () {
+        var prev_row = jQuery(this).prev('div.form-row');
+        jQuery(this).detach().appendTo(prev_row);
+    });
+
+    // Automatically sync to set input values to ones in config files.
+    jQuery('form[name=EditConfig] input[name$="-file"]').change(function (e) {
+        var file_input = jQuery(this);
+        var form = file_input.closest('form');
+        var file_name = file_input.attr('name');
+        var file_value = form.find('input[name=' + file_name + '-Current]').val();
+        var checked = jQuery(this).is(':checked') ? 1 : 0;
+        if ( !checked ) return;
+
+        var db_name = file_name.replace(/-file$/, '');
+        var db_input = form.find(':input[name=' + db_name + ']');
+        var db_input_type = db_input.attr('type') || db_input.prop('tagName').toLowerCase();
+        if ( db_input_type == 'radio' ) {
+            db_input.filter('[value=' + (file_value || 0) + ']').prop('checked', true);
+        }
+        else if ( db_input_type == 'select' ) {
+            db_input.selectpicker('val', file_value.length ? file_value : '__empty_value__');
+        }
+        else {
+            db_input.val(file_value);
+        }
+    });
+
+    // Automatically sync to uncheck use file config checkbox
+    jQuery('form[name=EditConfig] input[name$="-file"]').each(function () {
+        var file_input = jQuery(this);
+        var form = file_input.closest('form');
+        var file_name = file_input.attr('name');
+        var db_name = file_name.replace(/-file$/, '');
+        var db_input = form.find(':input[name=' + db_name + ']');
+        db_input.change(function() {
+            file_input.prop('checked', false);
+        });
+    });
 });
 
 /* inline edit */
diff --git a/t/web/admin_tools_editconfig.t b/t/web/admin_tools_editconfig.t
index 2182411a4b..0b3addbd71 100644
--- a/t/web/admin_tools_editconfig.t
+++ b/t/web/admin_tools_editconfig.t
@@ -82,9 +82,10 @@ sub run_test {
 
     diag $args{name} if $ENV{TEST_VERBOSE};
 
+    $m->form_id( $args{form_id} );
+    $m->untick( "$args{setting}-file", 1 );
     $m->submit_form_ok(
         {
-            form_id => $args{form_id},
             fields  => {
                 $args{setting} => $args{new_value},
             },

-----------------------------------------------------------------------


More information about the rt-commit mailing list