[Rt-commit] rt branch, 5.0-trunk, updated. rt-5.0.1-552-g4a8142d3eb
? sunnavy
sunnavy at bestpractical.com
Mon Jun 28 16:47:44 EDT 2021
The branch, 5.0-trunk has been updated
via 4a8142d3ebbc4378be6392eb8f32b47314e8d5a0 (commit)
via aa22c6aa22e62f09daf0a26f1ef10cf3ae26305b (commit)
from 5b8dae2f92f59ff49af9842403167f05395a9cdc (commit)
Summary of changes:
lib/RT/Config.pm | 5 ++++
share/html/Admin/Elements/ConfigHelp | 2 +-
share/html/Admin/Tools/Config/Elements/Option | 25 ++++++++++++++++++-
share/html/Admin/Tools/EditConfig.html | 15 +++++++++---
share/html/Widgets/Form/Boolean | 4 +++
share/html/Widgets/Form/Integer | 3 +++
share/html/Widgets/Form/MultilineString | 3 +++
share/html/Widgets/Form/Select | 3 +++
share/html/Widgets/Form/String | 3 +++
share/static/js/util.js | 35 +++++++++++++++++++++++++++
t/web/admin_tools_editconfig.t | 3 ++-
11 files changed, 95 insertions(+), 6 deletions(-)
- Log -----------------------------------------------------------------
commit aa22c6aa22e62f09daf0a26f1ef10cf3ae26305b
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..19fd10c40e 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. If you need to undo a change, check "Reset" and Save to completely clear the value set in the web UI.</p>
</&>
</div>
diff --git a/share/html/Admin/Tools/Config/Elements/Option b/share/html/Admin/Tools/Config/Elements/Option
index 054102cac9..862a394772 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,20 @@ my $row_end = qq{</div></div>};
Description => $name,
Hints => $meta->{WidgetArguments}->{Hints} || '',
LabelCols => 4,
- ValueCols => 8,
+ ValueCols => 6,
+ CloseRowDiv => 0, # this doesn't have affect CustomDateRange
%$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 => 0, DefaultLabel => loc('Reset') &>
+ <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/html/Widgets/Form/Boolean b/share/html/Widgets/Form/Boolean
index 7e6c3a45ba..ff8c60eb19 100644
--- a/share/html/Widgets/Form/Boolean
+++ b/share/html/Widgets/Form/Boolean
@@ -60,7 +60,10 @@ see docs/extending/using_forms_widgets.pod
<& SELF:InputOnly, %ARGS &>
<span class="hints"><% $Hints %></span>
</div>
+
+% if ( $CloseRowDiv ) {
</div>
+% }
<%ARGS>
$Name => undef,
$Description => undef,
@@ -68,6 +71,7 @@ $Hints => ''
$LabelLink => ''
$LabelCols => 3
$ValueCols => 9
+$CloseRowDiv => 1
</%ARGS>
<%METHOD InputOnly>
diff --git a/share/html/Widgets/Form/Integer b/share/html/Widgets/Form/Integer
index a0e3d2dc8a..8e02fd2bb4 100644
--- a/share/html/Widgets/Form/Integer
+++ b/share/html/Widgets/Form/Integer
@@ -63,7 +63,9 @@ see docs/extending/using_forms_widgets.pod
% }
<span class="hints"><% $Hints %></span>
</div>
+% if ( $CloseRowDiv ) {
</div>
+% }
<%INIT>
$_ = '' foreach grep !defined, $CurrentValue, $DefaultValue;
$DefaultLabel ||= loc( 'Default: [_1]', $DefaultValue );
@@ -82,6 +84,7 @@ $DefaultLabel => undef
$LabelLink => ''
$LabelCols => 3
$ValueCols => 9
+$CloseRowDiv => 1
</%ARGS>
<%METHOD InputOnly>
diff --git a/share/html/Widgets/Form/MultilineString b/share/html/Widgets/Form/MultilineString
index be929c7428..925795b5d5 100644
--- a/share/html/Widgets/Form/MultilineString
+++ b/share/html/Widgets/Form/MultilineString
@@ -62,7 +62,9 @@ see docs/extending/using_forms_widgets.pod
% }
<span class="hints"><% $Hints %></span>
</div>
+% if ( $CloseRowDiv ) {
</div>
+% }
<%ARGS>
$Name
@@ -78,6 +80,7 @@ $DefaultLabel => loc( 'Default: [_1]', $DefaultValue ),
$LabelLink => ''
$LabelCols => 3
$ValueCols => 9
+$CloseRowDiv => 1
</%ARGS>
<%METHOD InputOnly>
diff --git a/share/html/Widgets/Form/Select b/share/html/Widgets/Form/Select
index 2dad26da57..0d89ab4c97 100644
--- a/share/html/Widgets/Form/Select
+++ b/share/html/Widgets/Form/Select
@@ -60,7 +60,9 @@ see docs/extending/using_forms_widgets.pod
<& SELF:InputOnly, %ARGS &>
<span class="hints"><% $Hints %></span>
</div>
+% if ( $CloseRowDiv ) {
</div>
+% }
<%ARGS>
$Name
$Description => undef,
@@ -68,6 +70,7 @@ $Hints => ''
$LabelLink => ''
$LabelCols => 3
$ValueCols => 9
+$CloseRowDiv => 1
</%ARGS>
<%METHOD InputOnly>
diff --git a/share/html/Widgets/Form/String b/share/html/Widgets/Form/String
index 84539505b8..45de209bd4 100644
--- a/share/html/Widgets/Form/String
+++ b/share/html/Widgets/Form/String
@@ -63,7 +63,9 @@ see docs/extending/using_forms_widgets.pod
% }
<span class="hints"><% $Hints %></span>
</div>
+% if ( $CloseRowDiv ) {
</div>
+% }
<%ARGS>
$Name
@@ -78,6 +80,7 @@ $DefaultLabel => loc( 'Default: [_1]', $DefaultValue ),
$LabelLink => '',
$LabelCols => 3
$ValueCols => 9
+$CloseRowDiv => 1
</%ARGS>
<%METHOD InputOnly>
diff --git a/share/static/js/util.js b/share/static/js/util.js
index bd9cc01a5a..3a576a16d0 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 || 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},
},
commit 4a8142d3ebbc4378be6392eb8f32b47314e8d5a0
Merge: 5b8dae2f92 aa22c6aa22
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Jun 29 04:43:22 2021 +0800
Merge branch '5.0/delete-db-configs-web-ui' into 5.0-trunk
-----------------------------------------------------------------------
More information about the rt-commit
mailing list