[Bps-public-commit] rt-extension-configindatabase branch, master, updated. 7cf16a8eaf7d8832a2eef8af5e6794f0422fc775

Shawn Moore shawn at bestpractical.com
Mon Aug 14 19:06:46 EDT 2017


The branch, master has been updated
       via  7cf16a8eaf7d8832a2eef8af5e6794f0422fc775 (commit)
       via  35bdee632d2b1b237634a07f007a6cf721af3f92 (commit)
       via  2c8ad06affcd107df93a21430dab836a0f143e6c (commit)
       via  47677ac63d6df5cff8e2ceb2bb355fb24a03b81d (commit)
       via  472ca26b5f1bc379ad35c91446c9ed92a6eaef37 (commit)
       via  536c923cf4b55a24f1d4f81f9373e2a637d8817a (commit)
       via  1e5c91914a68050bc9428bbbd348b24d6f2a6318 (commit)
       via  d89abdec97ba79429fab939fc1be86df37265a66 (commit)
       via  9b48d5c55e01324e09bb60307b7ce7574418c112 (commit)
       via  f8bbc092e6fe3098f81c4fa4651d34935008e9fd (commit)
       via  70e04660f904c3e40112b92b570f3930bf4cee56 (commit)
      from  45cfca5482a75d8e39eed5576edfba8acdbbc45b (commit)

Summary of changes:
 html/Admin/Tools/EditConfig.html     | 76 +++++++++++++++++++++++++++++-------
 html/Widgets/Form/Code               |  4 ++
 html/Widgets/Form/MultilineString    | 52 ++++++++++++++++++++++++
 lib/RT/DatabaseSetting.pm            | 13 +++++-
 lib/RT/Extension/ConfigInDatabase.pm | 61 +++++++++++++++++++++++++++--
 static/css/config-in-database.css    |  9 +++++
 6 files changed, 195 insertions(+), 20 deletions(-)
 create mode 100644 html/Widgets/Form/Code
 create mode 100644 html/Widgets/Form/MultilineString

- Log -----------------------------------------------------------------
commit 70e04660f904c3e40112b92b570f3930bf4cee56
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 21:35:36 2017 +0000

    Make DefaultSearchResultOrder a ASC/DESC dropdown

diff --git a/lib/RT/Extension/ConfigInDatabase.pm b/lib/RT/Extension/ConfigInDatabase.pm
index b18c7f8..a5b4476 100644
--- a/lib/RT/Extension/ConfigInDatabase.pm
+++ b/lib/RT/Extension/ConfigInDatabase.pm
@@ -73,6 +73,14 @@ for (qw/LogToSyslog LogToSTDERR LogToFile LogStackTraces StatementLog/) {
     )];
 }
 
+for (qw/DefaultSearchResultOrder/) {
+    next if !$RT::Config::META{$_};
+
+    $RT::Config::META{$_}{Widget} = '/Widgets/Form/Select';
+    $RT::Config::META{$_}{WidgetArguments}{Values} = [qw(
+        ASC DESC
+    )];
+}
 # special case due to being only for PostLoadCheck
 $RT::Config::META{RestrictReferrerLogin}{Invisible} = 1;
 

commit f8bbc092e6fe3098f81c4fa4651d34935008e9fd
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 21:36:34 2017 +0000

    Use widgets for MultilineString and Code

diff --git a/html/Admin/Tools/EditConfig.html b/html/Admin/Tools/EditConfig.html
index 7409e9c..9200054 100644
--- a/html/Admin/Tools/EditConfig.html
+++ b/html/Admin/Tools/EditConfig.html
@@ -99,28 +99,22 @@ foreach my $key ( RT->Config->Options( Overridable => undef, Sorted => 0 ) ) {
 <&|/l_unsafe, "<a href=\"$meta->{EditLink}\">", loc($meta->{EditLinkLabel}), "</a>" &>Visit [_1][_2][_3] to manage this setting</&>
 % } elsif ( $meta->{Immutable} || $meta->{Obfuscate} || ($key =~ /Password/i and $key !~ /MinimumPasswordLength|AllowLoginPasswordAutoComplete/ )) {
 <em><% loc('Must modify in config file' ) %></em>\
-% } elsif ($meta->{Widget} && $meta->{Widget} ne '/Widgets/Form/Integer') {
-  <& $meta->{'Widget'},
+% } else {
+% my $widget = $meta->{'Widget'} || '/Widgets/Form/Code';
+% my $args   = $meta->{'WidgetArguments'} || {};
+% my $current_value = $widget eq '/Widgets/Form/Code' ? $val : $raw_value;
+  <& $widget,
     Default      => 1,
     DefaultValue => '',
     DefaultLabel => '(no value)',
 
-    %{ $m->comp('/Widgets/FinalizeWidgetArguments', WidgetArguments =>
-            $meta->{'WidgetArguments'} ) },
+    %{ $m->comp('/Widgets/FinalizeWidgetArguments', WidgetArguments => $args ) },
     Name         => $key,
-    CurrentValue => $raw_value,
+    CurrentValue => $current_value,
     Description  => '',
     Hints        => '',
   &>
-<input type="hidden" name="<% $key %>-Current" value="<% $raw_value %>"></input>
-% } else {
-% my $rows = 1;
-% $rows += scalar @{[ $val =~ /\n/g ]};    # each newline adds a row
-% $rows += scalar @{[ $val =~ /.{79}/g ]}; # each very long line adds a row, e.g. UserSearchResultFormat
-% $rows++ if $rows > 1;                    # buffer
-% $rows = 6 if $rows > 6;
-<textarea name="<% $key %>" cols="80" rows="<% $rows %>"><% $val %></textarea>
-<textarea name="<% $key %>-Current" class="hidden"><% $val %></textarea>
+<textarea class="hidden" name="<% $key %>-Current"><% $current_value %></textarea>
 % }
 </td>
 </tr>
diff --git a/html/Widgets/Form/Code b/html/Widgets/Form/Code
new file mode 100644
index 0000000..d2365b4
--- /dev/null
+++ b/html/Widgets/Form/Code
@@ -0,0 +1,4 @@
+<& /Widgets/Form/MultilineString, Class => 'code', %ARGS &>
+<%METHOD InputOnly>
+<& /Widgets/Form/MultilineString:InputOnly, %ARGS &>
+</%METHOD>
diff --git a/html/Widgets/Form/MultilineString b/html/Widgets/Form/MultilineString
new file mode 100644
index 0000000..d724040
--- /dev/null
+++ b/html/Widgets/Form/MultilineString
@@ -0,0 +1,52 @@
+<div id="form-box-<% lc $Name %>" class="widget <% $Class %>">
+<span class="description label"><% $Description %></span>
+<span class="value"><& SELF:InputOnly, %ARGS &></span>
+% if ( $Default ) {
+<span class="comment"><% $DefaultLabel %></span>
+% }
+<span class="hints"><% $Hints %></span>
+</div>
+<%ARGS>
+$Name
+
+$Class        => ''
+$Description  => undef,
+$Hints        => ''
+
+$CurrentValue => '',
+
+$Default        => 0,
+$DefaultValue   => '',
+$DefaultLabel   => loc( 'Default: [_1]', $DefaultValue ),
+</%ARGS>
+
+<%METHOD InputOnly>
+<textarea name="<% $Name %>" cols="<% $Cols %>" rows="<% $Rows %>"><% $CurrentValue %></textarea>
+<%ARGS>
+$Name
+$Cols => 80
+$Rows => 6
+$CurrentValue => '',
+</%ARGS>
+</%METHOD>
+
+<%METHOD Process>
+<%ARGS>
+$Name
+
+$Arguments    => {},
+
+$Default      => 0,
+$DefaultValue => '',
+</%ARGS>
+<%INIT>
+my $value = $Arguments->{ $Name };
+$value = '' unless defined $value;
+
+if ( $value eq '' ) {
+    return $DefaultValue unless $Default;
+    return undef;
+}
+return $value;
+</%INIT>
+</%METHOD>

commit 9b48d5c55e01324e09bb60307b7ce7574418c112
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 21:36:53 2017 +0000

    Organize remaining options as Integer, String, MultilineString

diff --git a/lib/RT/Extension/ConfigInDatabase.pm b/lib/RT/Extension/ConfigInDatabase.pm
index a5b4476..65e8de7 100644
--- a/lib/RT/Extension/ConfigInDatabase.pm
+++ b/lib/RT/Extension/ConfigInDatabase.pm
@@ -64,6 +64,43 @@ for (qw/AllowUserAutocompleteForUnprivileged AlwaysDownloadAttachments
     $RT::Config::META{$_}{WidgetArguments} = {};
 }
 
+for (qw/AttachmentListCount AutoLogoff BcryptCost DefaultSummaryRows
+        ExternalStorageCutoffSize LogoImageHeight LogoImageWidth LogoutRefresh
+        MaxAttachmentSize MaxFulltextAttachmentSize MessageBoxRichTextHeight
+        MinimumPasswordLength MoreAboutRequestorGroupsLimit TicketsItemMapSize
+       /) {
+    next if !$RT::Config::META{$_};
+
+    $RT::Config::META{$_}{Widget} = '/Widgets/Form/Integer';
+    $RT::Config::META{$_}{WidgetArguments} = {};
+}
+
+for (qw/CommentAddress CorrespondAddress DashboardAddress DashboardSubject
+        DefaultErrorMailPrecedence DefaultMailPrecedence
+        DefaultSearchResultOrderBy EmailOutputEncoding FriendlyFromLineFormat
+        FriendlyToLineFormat HTMLFormatter LogDir LogToFileNamed LogoAltText
+        LogoLinkURL LogoURL MailCommand OwnerEmail
+        RedistributeAutoGeneratedMessages SendmailArguments
+        SendmailBounceArguments SendmailPath SetOutgoingMailFrom Timezone
+        WebImagesURL
+       /) {
+    next if !$RT::Config::META{$_};
+
+    $RT::Config::META{$_}{Widget} = '/Widgets/Form/String';
+    $RT::Config::META{$_}{WidgetArguments} = {};
+}
+
+for (qw/AssetSearchFormat AssetSummaryFormat AssetSummaryRelatedTicketsFormat
+        DefaultSearchResultFormat DefaultSelfServiceSearchResultFormat
+        MoreAboutRequestorExtraInfo MoreAboutRequestorTicketListFormat
+        UserSearchResultFormat UserSummaryExtraInfo UserSummaryTicketListFormat
+       /) {
+    next if !$RT::Config::META{$_};
+
+    $RT::Config::META{$_}{Widget} = '/Widgets/Form/MultilineString';
+    $RT::Config::META{$_}{WidgetArguments} = {};
+}
+
 for (qw/LogToSyslog LogToSTDERR LogToFile LogStackTraces StatementLog/) {
     next if !$RT::Config::META{$_};
 

commit d89abdec97ba79429fab939fc1be86df37265a66
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 21:37:10 2017 +0000

    Use fixed-width font for code

diff --git a/static/css/config-in-database.css b/static/css/config-in-database.css
index 3ce92e7..9f7187d 100644
--- a/static/css/config-in-database.css
+++ b/static/css/config-in-database.css
@@ -4,3 +4,7 @@ body#comp-Admin-Tools-EditConfig div.widget .label {
     float: none;
 }
 
+body#comp-Admin-Tools-EditConfig .widget.code textarea {
+    font-family: Consolas, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace;
+}
+

commit 1e5c91914a68050bc9428bbbd348b24d6f2a6318
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 22:07:02 2017 +0000

    Don't allow editing code unless user has ExecuteCode

diff --git a/html/Admin/Tools/EditConfig.html b/html/Admin/Tools/EditConfig.html
index 9200054..abf8b1c 100644
--- a/html/Admin/Tools/EditConfig.html
+++ b/html/Admin/Tools/EditConfig.html
@@ -103,6 +103,10 @@ foreach my $key ( RT->Config->Options( Overridable => undef, Sorted => 0 ) ) {
 % my $widget = $meta->{'Widget'} || '/Widgets/Form/Code';
 % my $args   = $meta->{'WidgetArguments'} || {};
 % my $current_value = $widget eq '/Widgets/Form/Code' ? $val : $raw_value;
+
+% if ($widget eq '/Widgets/Form/Code' && !$session{CurrentUser}->HasRight(Right => 'ExecuteCode', Object => RT->System)) {
+<em><% loc('Must modify in config file' ) %></em>
+% } else {
   <& $widget,
     Default      => 1,
     DefaultValue => '',
@@ -116,6 +120,7 @@ foreach my $key ( RT->Config->Options( Overridable => undef, Sorted => 0 ) ) {
   &>
 <textarea class="hidden" name="<% $key %>-Current"><% $current_value %></textarea>
 % }
+% }
 </td>
 </tr>
 % }

commit 536c923cf4b55a24f1d4f81f9373e2a637d8817a
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 22:07:44 2017 +0000

    Forbid changing DisallowExecuteCode
    
    Otherwise it has no point, because you can simply re-enable editing code

diff --git a/lib/RT/Extension/ConfigInDatabase.pm b/lib/RT/Extension/ConfigInDatabase.pm
index 65e8de7..5253185 100644
--- a/lib/RT/Extension/ConfigInDatabase.pm
+++ b/lib/RT/Extension/ConfigInDatabase.pm
@@ -16,7 +16,7 @@ for (qw/DatabaseAdmin DatabaseExtraDSN DatabaseHost DatabaseName
 
         Organization rtname Plugins MailPlugins
 
-        RecordBaseClass WebSessionClass DevelMode
+        RecordBaseClass WebSessionClass DevelMode DisallowExecuteCode
 
         ExternalAuthPriority ExternalInfoPriority
         ExternalSettings/) {
@@ -34,7 +34,7 @@ for (qw/AllowUserAutocompleteForUnprivileged AlwaysDownloadAttachments
         ArticleOnTicketCreate AutocompleteOwnersForSearch
         CanonicalizeRedirectURLs CanonicalizeURLsInFeeds
         ChartsTimezonesInDB CheckMoreMSMailHeaders DateDayBeforeMonth
-        DisableGD DisableGraphViz DisallowExecuteCode
+        DisableGD DisableGraphViz
         DontSearchFileAttachments DropLongAttachments
         EditCustomFieldsSingleColumn EnableReminders
         ExternalStorageDirectLink ForceApprovalsView ForwardFromUser

commit 472ca26b5f1bc379ad35c91446c9ed92a6eaef37
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 22:49:15 2017 +0000

    Forbid sneakily changing Immutable config options

diff --git a/html/Admin/Tools/EditConfig.html b/html/Admin/Tools/EditConfig.html
index abf8b1c..82d0d6e 100644
--- a/html/Admin/Tools/EditConfig.html
+++ b/html/Admin/Tools/EditConfig.html
@@ -28,11 +28,20 @@ if (delete $ARGS{Update}) {
 
     for my $key (keys %ARGS) {
         next if $key =~ /-Current$/;
+
+        my $meta = RT->Config->Meta( $key );
+
         my $val = $ARGS{$key};
         $val = '' if $val eq '__empty_value__';
         my $prev = $ARGS{$key . '-Current'};
         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;
+        }
+
         my $setting = RT::DatabaseSetting->new($session{CurrentUser});
         $setting->Load($key);
         if ($setting->Id) {

commit 47677ac63d6df5cff8e2ceb2bb355fb24a03b81d
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 22:49:55 2017 +0000

    Display immutable or uneditable values with disabled input field

diff --git a/html/Admin/Tools/EditConfig.html b/html/Admin/Tools/EditConfig.html
index 82d0d6e..1e677ac 100644
--- a/html/Admin/Tools/EditConfig.html
+++ b/html/Admin/Tools/EditConfig.html
@@ -107,14 +107,18 @@ foreach my $key ( RT->Config->Options( Overridable => undef, Sorted => 0 ) ) {
 % if ( $meta->{EditLink} ) {
 <&|/l_unsafe, "<a href=\"$meta->{EditLink}\">", loc($meta->{EditLinkLabel}), "</a>" &>Visit [_1][_2][_3] to manage this setting</&>
 % } elsif ( $meta->{Immutable} || $meta->{Obfuscate} || ($key =~ /Password/i and $key !~ /MinimumPasswordLength|AllowLoginPasswordAutoComplete/ )) {
-<em><% loc('Must modify in config file' ) %></em>\
+% unless ($key =~ /Password/i and $key !~ /MinimumPasswordLength|AllowLoginPasswordAutoComplete/ ) {
+<input type="text" disabled width="80" value="<% $val %>"></input><br>
+% }
+<em><% loc('Must modify in config file' ) %></em>
 % } else {
 % my $widget = $meta->{'Widget'} || '/Widgets/Form/Code';
 % my $args   = $meta->{'WidgetArguments'} || {};
 % my $current_value = $widget eq '/Widgets/Form/Code' ? $val : $raw_value;
 
 % if ($widget eq '/Widgets/Form/Code' && !$session{CurrentUser}->HasRight(Right => 'ExecuteCode', Object => RT->System)) {
-<em><% loc('Must modify in config file' ) %></em>
+<textarea disabled rows="6" cols="80"><% $val %></textarea>
+<br><em><% loc('Must modify in config file' ) %></em>
 % } else {
   <& $widget,
     Default      => 1,
diff --git a/static/css/config-in-database.css b/static/css/config-in-database.css
index 9f7187d..623cac5 100644
--- a/static/css/config-in-database.css
+++ b/static/css/config-in-database.css
@@ -4,6 +4,11 @@ body#comp-Admin-Tools-EditConfig div.widget .label {
     float: none;
 }
 
+body#comp-Admin-Tools-EditConfig textarea:disabled,
+body#comp-Admin-Tools-EditConfig input:disabled {
+    background-color: #EEE;
+}
+
 body#comp-Admin-Tools-EditConfig .widget.code textarea {
     font-family: Consolas, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace;
 }

commit 2c8ad06affcd107df93a21430dab836a0f143e6c
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 22:50:29 2017 +0000

    Compile-check and execute code config options
    
    Otherwise we store them incorrectly as strings in the database, but we
    need to execute them to produce the data structure to store it in the
    database with storable or json

diff --git a/html/Admin/Tools/EditConfig.html b/html/Admin/Tools/EditConfig.html
index 1e677ac..6cfe68c 100644
--- a/html/Admin/Tools/EditConfig.html
+++ b/html/Admin/Tools/EditConfig.html
@@ -30,6 +30,8 @@ if (delete $ARGS{Update}) {
         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__';
@@ -42,6 +44,38 @@ if (delete $ARGS{Update}) {
             next;
         }
 
+        if ($is_code) {
+            if (!$session{CurrentUser}->HasRight(Right => 'ExecuteCode', Object => RT->System)) {
+                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) {

commit 35bdee632d2b1b237634a07f007a6cf721af3f92
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 22:51:31 2017 +0000

    Avoid Active_MakeClicky changed from ARRAY(0x…) to ARRAY(0x…)

diff --git a/lib/RT/DatabaseSetting.pm b/lib/RT/DatabaseSetting.pm
index 974a011..e603f56 100644
--- a/lib/RT/DatabaseSetting.pm
+++ b/lib/RT/DatabaseSetting.pm
@@ -96,7 +96,12 @@ sub Create {
         $content = $self->loc('(no value)');
     }
 
-    return ($id, $self->loc("[_1] changed from [_2] to [_3]", $self->Name, $old_value, $content));
+    if (!ref($content) && !ref($old_value)) {
+        return ($id, $self->loc("[_1] changed from [_2] to [_3]", $self->Name, $old_value, $content));
+    }
+    else {
+        return ($id, $self->loc("[_1] changed", $self->Name));
+    }
 }
 
 =head2 CurrentUserCanSee
@@ -250,7 +255,11 @@ sub SetContent {
         $value = $self->loc('(no value)');
     }
 
-    return ($ok, $self->loc("[_1] changed from [_2] to [_3]", $self->Name, $old_value, $value));
+    if (!ref($value) && !ref($old_value)) {
+        return ($ok, $self->loc("[_1] changed from [_2] to [_3]", $self->Name, $old_value, $value));
+    } else {
+        return ($ok, $self->loc("[_1] changed", $self->Name));
+    }
 }
 
 =head1 PRIVATE METHODS

commit 7cf16a8eaf7d8832a2eef8af5e6794f0422fc775
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Aug 14 22:51:51 2017 +0000

    Improve setting config options to data structures

diff --git a/lib/RT/Extension/ConfigInDatabase.pm b/lib/RT/Extension/ConfigInDatabase.pm
index 5253185..1cdaa5c 100644
--- a/lib/RT/Extension/ConfigInDatabase.pm
+++ b/lib/RT/Extension/ConfigInDatabase.pm
@@ -144,9 +144,19 @@ sub LoadConfigFromDatabase {
             RT->Logger->warning("Change of config option '$name' at $source{File} line $source{Line} has been overridden by the config setting from the database. Please remove it from $source{File} or from the database to avoid confusion.");
         }
 
+        # hashes combine, but we don't want that behavior because the previous
+        # config settings will shadow any change that the database config makes
+        if ($meta->{Type} eq 'HASH') {
+            RT->Config->Set($name, ());
+        }
+
+        my $val = $meta->{Type} eq 'ARRAY' ? $value
+                : $meta->{Type} eq 'HASH'  ? [ %$value ]
+                                           : [ $value ];
+
         RT->Config->SetFromConfig(
             Option     => \$name,
-            Value      => [$value],
+            Value      => $val,
             Package    => 'N/A',
             File       => 'database',
             Line       => 'N/A',

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


More information about the Bps-public-commit mailing list