<%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 $has_execute_code = $session{CurrentUser}->HasRight(Right => 'ExecuteCode', Object => RT->System); my @results; my $doc_version = $RT::VERSION; $doc_version =~ s/rc\d+//; # 4.4.2rc1 -> 4.4.2 $doc_version =~ s/\.\d+-\d+-g\w+$//; # 4.4.3-1-g123 -> 4.4 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::Extension::ConfigInDatabase->BeginConfigChanges; $RT::Handle->BeginTransaction; my $has_error; eval { for my $key (keys %ARGS) { next if $key =~ /-Current$/; my $meta = RT->Config->Meta( $key ); my $widget = $meta->{Widget} || '/Widgets/Form/Code'; my $is_code = $widget eq '/Widgets/Form/Code'; my $val = $ARGS{$key}; $val = '' if $val eq '__empty_value__'; my $prev = $ARGS{$key . '-Current'}; next if $val eq $prev; # for bools, check for truthiness since 0, '', and undef are equivalent if ($widget eq '/Widgets/Form/Boolean') { next if !!$val eq !!$prev; } if ( $meta->{Immutable} || $meta->{Obfuscate} || ($key =~ /Password/i and $key !~ /MinimumPasswordLength|AllowLoginPasswordAutoComplete/ )) { push @results, loc("Cannot change [_1]: Permission Denied", $key); $has_error++; next; } if ($is_code) { if (!$has_execute_code) { push @results, loc("Cannot change [_1]: Permission Denied", $key); $has_error++; next; } my $code = $val; my $coderef; # similar to RT::Scrip::CompileCheck do { no strict 'vars'; $coderef = eval "sub { $code \n }"; }; if ($@) { my $error = $@; push @results, loc("Couldn't compile [_1] codeblock '[_2]': [_3]", $key, $code, $error); $has_error++; next; } if ($coderef) { $val = eval { $coderef->() }; if ($@) { my $error = $@; push @results, loc("Couldn't execute [_1] codeblock '[_2]': [_3]", $key, $code, $error); $has_error++; next; } } } my $setting = RT::DatabaseSetting->new($session{CurrentUser}); $setting->Load($key); if ($setting->Id) { if ($setting->Disabled) { $setting->SetDisabled(0); } my ($ok, $msg) = $setting->SetContent($val); push @results, $msg; $has_error++ if !$ok; } else { my ($ok, $msg) = $setting->Create( Name => $key, Content => $val, ); push @results, $msg; $has_error++ if !$ok; } } }; if ($@) { push @results, $@; $has_error++; } if ($has_error) { push @results, loc("No changes made."); $RT::Handle->Rollback; } else { $RT::Handle->Commit; } RT::Extension::ConfigInDatabase->EndConfigChanges; } <& /Admin/Elements/Header, Title => $title &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>
<&|/Widgets/TitleBox, title => loc("RT Configuration") &> <%PERL> my $index_conf; foreach my $key ( RT->Config->Options( Overridable => undef, Sorted => 0 ) ) { my $meta = RT->Config->Meta( $key ); next if $meta->{Invisible}; my $raw_value = RT->Config->Get( $key ); my $val = $stringify->($raw_value); $index_conf++; my $doc_url = "https://docs.bestpractical.com/rt/$doc_version/RT_Config.html#$key"; my $widget = $meta->{'Widget'} || '/Widgets/Form/Code'; my $is_code = $widget eq '/Widgets/Form/Code'; my $is_password = ($key =~ /Password/i and $key !~ /MinimumPasswordLength|AllowLoginPasswordAutoComplete/ ); my $is_immutable = $meta->{Immutable} || $meta->{Obfuscate} || ($is_code && $val =~ s/sub { "DUMMY" }/sub { ... }/g) || ($is_code && !$has_execute_code); my $current_value = $is_code ? $val : $raw_value; my $args = $meta->{'WidgetArguments'} || {}; # RadioStyle was added to 4.4.3, and so if we are on an older version we # can't specify Default => 0, since then we revert to just a checkbox if ($widget eq '/Widgets/Form/Boolean' && RT::Handle::cmp_version($RT::VERSION,'4.4.3') >= 0 ) { %$args = ( Default => 0, RadioStyle => 1, %$args, ); } elsif ($widget eq '/Widgets/Form/String' || $widget eq '/Widgets/Form/Integer') { %$args = ( Size => 60, %$args, ); } % }
<&|/l&>Option <&|/l&>Value
<% $key %> % if ( $meta->{EditLink} ) { <&|/l_unsafe, "{EditLink}\">", loc($meta->{EditLinkLabel}), "" &>Visit [_1][_2][_3] to manage this setting % } elsif ( $key =~ /Plugins/) {
<% loc('Must modify in config file' ) %> % } elsif ( $is_password ) { <% loc('Must modify in config file' ) %> % } elsif ( $is_immutable ) { % if ($widget eq '/Widgets/Form/MultilineString' || $widget eq '/Widgets/Form/Code') { % } else { % }
<% loc('Must modify in config file' ) %> % } else { <& $widget, Default => 1, DefaultValue => '', DefaultLabel => '(no value)', %{ $m->comp('/Widgets/FinalizeWidgetArguments', WidgetArguments => $args ) }, Name => $key, CurrentValue => $current_value, Description => '', Hints => '', &> % }
<& /Elements/Submit, Label => loc('Save Changes') &>