[Rt-commit] rt branch, 4.0/custom-fields-groups, updated. rt-4.0.4-232-g7b82f5c

Thomas Sibley trs at bestpractical.com
Fri Sep 7 17:33:56 EDT 2012


The branch, 4.0/custom-fields-groups has been updated
       via  7b82f5c85db5081b944e32d8800e34ea7d265130 (commit)
       via  234203c20e5f4cd4d769dffef185733b21be5cb7 (commit)
      from  132fd7cf8888a515736bf30c0a0915144c94699c (commit)

Summary of changes:
 lib/RT/Config.pm       | 28 ++++++++++++++++++++++++++++
 lib/RT/CustomField.pm  |  2 ++
 lib/RT/CustomFields.pm | 11 +++++++----
 3 files changed, 37 insertions(+), 4 deletions(-)

- Log -----------------------------------------------------------------
commit 234203c20e5f4cd4d769dffef185733b21be5cb7
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Fri Sep 7 14:03:20 2012 -0700

    Stricter checking for a valid CustomFieldGroups config when using it
    
    This avoids many broken pages due to a potentially common configuration
    error (such as I made when testing out the branch).

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 39860b4..210d36a 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1198,6 +1198,8 @@ sub Groups {
         if !$record_class && $self->id;
 
     my $config = RT->Config->Get('CustomFieldGroups');
+       $config = {} unless ref($config) eq 'HASH';
+
     my @groups;
     if ( $record_class ) {
         @groups = keys %{ $config->{$record_class} };
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index e7c0b23..ca24763 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -99,17 +99,20 @@ sub LimitToGroup {
     my $self = shift;
     my $group = shift;
 
+    my $config = RT->Config->Get('CustomFieldGroups');
+       $config = {} unless ref($config) eq 'HASH';
+
     if ( $group ) {
-        my $list = RT->Config->Get('CustomFieldGroups')->{'RT::Ticket'}{$group};
-        unless ( $list && @$list ) {
+        my $list = $config->{'RT::Ticket'}{$group};
+        unless ( $list and ref($list) eq 'ARRAY' and @$list ) {
             return $self->Limit( FIELD => 'id', VALUE => 0, ENTRYAGGREGATOR => 'AND' );
         }
         foreach ( @$list ) {
             $self->Limit( FIELD => 'Name', VALUE => $_ );
         }
     } else {
-        my @list = map {@$_} grep defined && ref $_,
-            values %{ RT->Config->Get('CustomFieldGroups')->{'RT::Ticket'} };
+        my @list = map {@$_} grep defined && ref($_) eq 'ARRAY',
+            values %{ $config->{'RT::Ticket'} };
 
         return unless @list;
         foreach ( @list ) {

commit 7b82f5c85db5081b944e32d8800e34ea7d265130
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Fri Sep 7 14:28:40 2012 -0700

    Validate the CustomFieldGroups config option after the config is loaded
    
    This doesn't help direct calls to RT->Config->Set() after load
    (extensions?), but it will avoid most common configuration errors.
    
    Sanity checking the structure would be so much nicer with Moose types...

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 548ba19..28c2478 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -783,6 +783,34 @@ lifecycle and add transition rules; see RT_Config.pm for documentation.
 EOT
         },
     },
+    CustomFieldGroups   => {
+        Type            => 'HASH',
+        PostLoadCheck   => sub {
+            my $config = shift;
+            # use scalar context intentionally to avoid not a hash error
+            my $groups = $config->Get('CustomFieldGroups') || {};
+
+            unless (ref($groups) eq 'HASH') {
+                RT->Logger->error("Config option %CustomFieldGroups is a @{[ref $groups]} not a HASH; ignoring");
+                $groups = {};
+            }
+
+            for my $class (keys %$groups) {
+                unless (ref($groups->{$class}) eq 'HASH') {
+                    RT->Logger->error("Config option \%CustomFieldGroups{$class} is not a HASH; ignoring");
+                    delete $groups->{$class};
+                    next;
+                }
+                for my $group (keys %{ $groups->{$class} }) {
+                    unless (ref($groups->{$class}{$group}) eq 'ARRAY') {
+                        RT->Logger->error("Config option \%CustomFieldGroups{$class}{$group} is not an ARRAY; ignoring");
+                        delete $groups->{$class}{$group};
+                    }
+                }
+            }
+            $config->Set( CustomFieldGroups => %$groups );
+        },
+    },
 );
 my %OPTIONS = ();
 

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


More information about the Rt-commit mailing list