%# BEGIN BPS TAGGED BLOCK {{{ %# %# COPYRIGHT: %# %# This software is Copyright (c) 1996-2026 Best Practical Solutions, LLC %# <sales@bestpractical.com> %# %# (Except where explicitly superseded by other copyright notices) %# %# %# LICENSE: %# %# This work is made available to you under the terms of Version 2 of %# the GNU General Public License. A copy of that license should have %# been provided with this software, but in any event can be snarfed %# from www.gnu.org. %# %# This work is distributed in the hope that it will be useful, but %# WITHOUT ANY WARRANTY; without even the implied warranty of %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %# General Public License for more details. %# %# You should have received a copy of the GNU General Public License %# along with this program; if not, write to the Free Software %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA %# 02110-1301 or visit their web page on the internet at %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. %# %# %# CONTRIBUTION SUBMISSION POLICY: %# %# (The following paragraph is not intended to limit the rights granted %# to you to modify and distribute this software under the terms of %# the GNU General Public License and is only of importance to you if %# you choose to contribute your changes and enhancements to the %# community by submitting them to Best Practical Solutions, LLC.) %# %# By intentionally submitting any modifications, corrections or %# derivatives to this work, or any other work intended for use with %# Request Tracker, to Best Practical Solutions, LLC, you confirm that %# you are the copyright holder for those contributions and you grant %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, %# royalty-free, perpetual, license to use, copy, create derivative %# works based on those contributions, and sublicense and distribute %# those contributions and any derivatives thereof. %# %# END BPS TAGGED BLOCK }}} <%INIT> Abort( loc( 'Permission Denied' ) ) unless RT->Config->Get('ShowEditSystemConfig'); 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 $options = RT->Config->LoadSectionMap(); my $active_context = { tab => CSSClass( $ARGS{tab} || $options->[0]->{Name}) , section => CSSClass( $ARGS{section} || $options->[0]->{Content}->[0]->{Name}) , subsection => CSSClass( $ARGS{subsection} || $options->[0]->{Content}->[0]->{Content}->[0]->{Name}) , }; my @option_list; for my $tab ( @$options ) { for my $section ( @{$tab->{Content}} ) { for my $subsection ( @{$section->{Content}} ) { for my $name ( map { $_->{Name} } @{$subsection->{Content}} ) { my $meta = RT->Config->Meta( $name ); next if $meta->{Invisible} || $meta->{Deprecated} || $meta->{Obfuscate}; push @option_list, $name; } } } } @option_list = sort { lc $a cmp lc $b } @option_list; my @results; if (delete $ARGS{Update}) { RT->Config->BeginDatabaseConfigChanges; $RT::Handle->BeginTransaction; my $has_error; if ( delete $ARGS{CustomDateRanges} ) { push @results, ProcessCustomDateRanges( ARGSRef => \%ARGS ); } eval { for my $key (keys %ARGS) { 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' || $meta->{IsJSON}; 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} ) { push @results, loc("Cannot change [_1]: Permission Denied", $key); $has_error++; next; } if ($is_json) { my $json = $val; ($val) = RT::Configuration->new( $session{CurrentUser} )->_DeJSONContent($json); if (!defined $val) { my $error = $@; push @results, loc("Couldn't decode [_1] JSON '[_2]': [_3]", $key, $json, $error); $has_error++; next; } } elsif ( $widget eq '/Widgets/Form/SearchFormat' ) { # Unquote wrongly quoted values like 'id, Name' if ( $val =~ /^\s*(['"])([^']+,[^']*)\1\s*$/ ) { $val = $2; } } if ( $meta->{Type} eq 'HASH' ) { my $old_value = RT->Config->_GetFromFilesOnly($key) || {}; for my $item ( sort keys %$old_value ) { if ( !exists $val->{$item} ) { my @file_sources = grep { !$_->{Database} && exists $_->{Value}{$item} } @{ $meta->{Sources} }; push @results, loc( "To delete this entry, you must remove '[_1]' in %[_2] from the following config file: [_3]", $item, $key, join ', ', map {"$_->{File} line $_->{Line}"} @file_sources ); } } } if ($setting->Id) { 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++; } @results = map { s/^Stack:.*//ms; $_ } @results; if ($has_error) { push @results, loc("No changes made."); $RT::Handle->Rollback; } else { $RT::Handle->Commit; } RT->Config->EndDatabaseConfigChanges; } my $nav_type='pill'; # 'tab' or 'pill' <& /Admin/Elements/Header, Title => $title &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>
<& /Admin/Elements/ConfigHelp &>
% my @tab_names = map { $_->{Name} } @$options;
% foreach my $tab ( @$options) { % my $tab_id = CSSClass( $tab->{Name} ); % $current_context->{tab} = $tab_id; % my $active = $tab_id eq $active_context->{tab} ? ' show active' : ''; % my $nav_id = join '-', 'nav', $current_context->{tab}; % my $content_id = join '-', 'content', $current_context->{tab};
<& /Admin/Tools/Config/Elements/Tab, tab => $tab, active_context => $active_context, current_context => $current_context &>
% }