[Rt-commit] rt branch, 5.0/delete-db-configs-web-ui, created. rt-5.0.1-437-g54cf84a271
? sunnavy
sunnavy at bestpractical.com
Tue Jun 8 16:36:29 EDT 2021
The branch, 5.0/delete-db-configs-web-ui has been created
at 54cf84a271ff7d07810e0dc258edbd51be0d1a00 (commit)
- Log -----------------------------------------------------------------
commit 54cf84a271ff7d07810e0dc258edbd51be0d1a00
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 6372e60527..5ea0239c4b 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -2823,6 +2823,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/Tools/Config/Elements/Option b/share/html/Admin/Tools/Config/Elements/Option
index 054102cac9..0b090765f6 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 = (
@@ -158,6 +172,15 @@ my $row_end = qq{</div></div>};
%{ $m->comp('/Widgets/FinalizeWidgetArguments', WidgetArguments =>
$meta->{'WidgetArguments'} ) },
&>
+% if ( $name ne 'CustomDateRanges' ) {
+ <div class="form-row mb-3 mt-0 file-config">
+ <div class="col-8 offset-4">
+ <& /Widgets/Form/Boolean:InputOnly, Name => "$name-file", CurrentValue => !$db_config->Id, DefaultLabel => loc('Use default in config files') &>
+ <input type="hidden" name="<% $name %>-file-Current" value="<% $current_file_value %>" />
+ </div>
+ </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..a25c6a9293 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -826,6 +826,41 @@ jQuery(function() {
});
});
}
+
+ // 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 + ']').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