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

Thomas Sibley trs at bestpractical.com
Mon Oct 15 21:10:22 EDT 2012


The branch, 4.0/custom-fields-groups has been updated
       via  6fd71d6e63319ea4090836457a5464102cbffaa4 (commit)
       via  43cd7a43fbd909ad5408e951e59cb60f77374932 (commit)
       via  ea1f5226f46d9ad921ab4566397d2c99e95a4baa (commit)
       via  fab12f3a536a88a3d7a3d8236af7682f9fc234f3 (commit)
       via  7dc0985ef9781af62b84c6085b0754f2bb1bb24c (commit)
       via  3bfa15a5932108fe1ea054c6c75fe41623e96c74 (commit)
       via  aceceed89220a652b4b4e7d5a9fd8e09943e1504 (commit)
       via  e4a59e89d16953bd810bc83e4159e536868f4935 (commit)
       via  cff78cddedd05f7cfea56d08db9fbd9c35f28846 (commit)
       via  5908b994a39fbb7f3eca32ae163ae8808188f391 (commit)
      from  92604f04d1740e856ba05c2d2d8a3acadcea6da4 (commit)

Summary of changes:
 etc/RT_Config.pm.in                                | 48 +++++++----
 lib/RT/Config.pm                                   | 12 +--
 lib/RT/CustomField.pm                              | 92 +++++++++++++++++-----
 lib/RT/CustomFields.pm                             | 29 +++++--
 share/html/Admin/Users/Modify.html                 | 10 +--
 ...CustomGroups => EditCustomFieldCustomGroupings} |  6 +-
 share/html/Elements/EditCustomFields               |  4 +-
 share/html/Elements/EditLinks                      |  2 +-
 ...CustomGroups => ShowCustomFieldCustomGroupings} |  4 +-
 share/html/Elements/ShowCustomFields               |  4 +-
 share/html/Elements/ShowLinks                      |  2 +-
 share/html/Ticket/Create.html                      | 10 +--
 share/html/Ticket/Elements/EditDates               |  2 +-
 share/html/Ticket/Elements/EditPeople              |  2 +-
 share/html/Ticket/Elements/ShowBasics              |  2 +-
 share/html/Ticket/Elements/ShowDates               |  2 +-
 share/html/Ticket/Elements/ShowPeople              |  2 +-
 share/html/Ticket/Elements/ShowSummary             |  2 +-
 share/html/Ticket/Modify.html                      |  4 +-
 share/html/Ticket/ModifyAll.html                   |  4 +-
 t/web/cf_groups.t                                  |  4 +-
 t/web/cf_groups_users.t                            |  4 +-
 22 files changed, 169 insertions(+), 82 deletions(-)
 rename share/html/Elements/{EditCustomFieldCustomGroups => EditCustomFieldCustomGroupings} (71%)
 rename share/html/Elements/{ShowCustomFieldCustomGroups => ShowCustomFieldCustomGroupings} (76%)

- Log -----------------------------------------------------------------
commit 5908b994a39fbb7f3eca32ae163ae8808188f391
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 13:59:17 2012 -0700

    Refactor built-in custom field grouping registration into a method
    
    Allows for easier extensibility of built-in groupings by extensions,
    particularly ones which add new objects for CFs to apply to.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 5c60668..9ce5e33 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -201,6 +201,11 @@ RT::CustomField->_ForObjectType( 'RT::User'  => "Users", );
 RT::CustomField->_ForObjectType( 'RT::Queue'  => "Queues", );                         #loc
 RT::CustomField->_ForObjectType( 'RT::Group' => "Groups", );                          #loc
 
+__PACKAGE__->RegisterBuiltInGroups(
+    'RT::Ticket'    => [ qw(Basics Dates Links People) ],
+    'RT::User'      => [ 'Identity', 'Access control', 'Location', 'Phones' ],
+);
+
 our $RIGHTS = {
     SeeCustomField            => 'View custom fields',                                    # loc_pair
     AdminCustomField          => 'Create, modify and delete custom fields',               # loc_pair
@@ -1214,11 +1219,17 @@ sub Groups {
         @groups;
 }
 
-our %BUILTIN_GROUPS = (
-    'RT::Ticket' => { map { $_ => 1 } qw(Basics Dates Links People) },
-    'RT::User' => { map { $_ => 1 } 'Identity', 'Access control', 'Location', 'Phones' },
-);
-$BUILTIN_GROUPS{''} = { map { %$_ } values %BUILTIN_GROUPS  };
+my %BUILTIN_GROUPS;
+sub RegisterBuiltInGroups {
+    my $self = shift;
+    my %new  = @_;
+
+    while (my ($k,$v) = each %new) {
+        $v = [$v] unless ref($v) eq 'ARRAY';
+        $BUILTIN_GROUPS{$k} = { map { $_ => 1 } @$v };
+    }
+    $BUILTIN_GROUPS{''} = { map { %$_ } values %BUILTIN_GROUPS  };
+}
 
 sub CustomGroups {
     my $self = shift;

commit cff78cddedd05f7cfea56d08db9fbd9c35f28846
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 14:08:03 2012 -0700

    Extend rather than override existing built-in groupings for an object class
    
    Now adding another grouping to an existing object class is possible with
    an extension:
    
        RT::CustomField->RegisterBuiltInGroups( "RT::Ticket" => ["Foo"] );
    
    and the "Foo" grouping will be left alone to be handled by the
    extension.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 9ce5e33..213c31e 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1226,7 +1226,10 @@ sub RegisterBuiltInGroups {
 
     while (my ($k,$v) = each %new) {
         $v = [$v] unless ref($v) eq 'ARRAY';
-        $BUILTIN_GROUPS{$k} = { map { $_ => 1 } @$v };
+        $BUILTIN_GROUPS{$k} = {
+            %{$BUILTIN_GROUPS{$k} || {}},
+            map { $_ => 1 } @$v
+        };
     }
     $BUILTIN_GROUPS{''} = { map { %$_ } values %BUILTIN_GROUPS  };
 }

commit e4a59e89d16953bd810bc83e4159e536868f4935
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 14:59:38 2012 -0700

    Remove unimplemented Group method
    
    We can implement the method as needed in the future.  The method will
    need to account for CFs appearing in multiple groupings.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 213c31e..b442015 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1188,12 +1188,6 @@ sub CollectionClassFromLookupType {
     return $collection_class;
 }
 
-
-sub Group {
-
-
-}
-
 sub Groups {
     my $self = shift;
     my $record = shift;

commit aceceed89220a652b4b4e7d5a9fd8e09943e1504
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 15:18:53 2012 -0700

    Rename custom field "group" concept to "groupings"
    
    Grouping conveys the simple organizational intent better and clarifies
    the relationship (none!) to RT::Group.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index d51874a..5b13b9e 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2597,7 +2597,7 @@ with L</Lifecycles> (see L</Labeling and defining actions>).
 
 =cut
 
-Set(%CustomFieldGroups,
+Set(%CustomFieldGroupings,
     'RT::Ticket' => {
         Basics => [],
         Dates => [],
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 28c2478..41a4c71 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -783,32 +783,32 @@ lifecycle and add transition rules; see RT_Config.pm for documentation.
 EOT
         },
     },
-    CustomFieldGroups   => {
+    CustomFieldGroupings => {
         Type            => 'HASH',
         PostLoadCheck   => sub {
             my $config = shift;
             # use scalar context intentionally to avoid not a hash error
-            my $groups = $config->Get('CustomFieldGroups') || {};
+            my $groups = $config->Get('CustomFieldGroupings') || {};
 
             unless (ref($groups) eq 'HASH') {
-                RT->Logger->error("Config option %CustomFieldGroups is a @{[ref $groups]} not a HASH; ignoring");
+                RT->Logger->error("Config option %CustomFieldGroupings 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");
+                    RT->Logger->error("Config option \%CustomFieldGroupings{$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");
+                        RT->Logger->error("Config option \%CustomFieldGroupings{$class}{$group} is not an ARRAY; ignoring");
                         delete $groups->{$class}{$group};
                     }
                 }
             }
-            $config->Set( CustomFieldGroups => %$groups );
+            $config->Set( CustomFieldGroupings => %$groups );
         },
     },
 );
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index b442015..eaa9e72 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -201,7 +201,7 @@ RT::CustomField->_ForObjectType( 'RT::User'  => "Users", );
 RT::CustomField->_ForObjectType( 'RT::Queue'  => "Queues", );                         #loc
 RT::CustomField->_ForObjectType( 'RT::Group' => "Groups", );                          #loc
 
-__PACKAGE__->RegisterBuiltInGroups(
+__PACKAGE__->RegisterBuiltInGroupings(
     'RT::Ticket'    => [ qw(Basics Dates Links People) ],
     'RT::User'      => [ 'Identity', 'Access control', 'Location', 'Phones' ],
 );
@@ -1188,7 +1188,7 @@ sub CollectionClassFromLookupType {
     return $collection_class;
 }
 
-sub Groups {
+sub Groupings {
     my $self = shift;
     my $record = shift;
 
@@ -1196,7 +1196,7 @@ sub Groups {
     $record_class = $self->RecordClassFromLookupType
         if !$record_class && $self->id;
 
-    my $config = RT->Config->Get('CustomFieldGroups');
+    my $config = RT->Config->Get('CustomFieldGroupings');
        $config = {} unless ref($config) eq 'HASH';
 
     my @groups;
@@ -1213,22 +1213,22 @@ sub Groups {
         @groups;
 }
 
-my %BUILTIN_GROUPS;
-sub RegisterBuiltInGroups {
+my %BUILTIN_GROUPINGS;
+sub RegisterBuiltInGroupings {
     my $self = shift;
     my %new  = @_;
 
     while (my ($k,$v) = each %new) {
         $v = [$v] unless ref($v) eq 'ARRAY';
-        $BUILTIN_GROUPS{$k} = {
-            %{$BUILTIN_GROUPS{$k} || {}},
+        $BUILTIN_GROUPINGS{$k} = {
+            %{$BUILTIN_GROUPINGS{$k} || {}},
             map { $_ => 1 } @$v
         };
     }
-    $BUILTIN_GROUPS{''} = { map { %$_ } values %BUILTIN_GROUPS  };
+    $BUILTIN_GROUPINGS{''} = { map { %$_ } values %BUILTIN_GROUPINGS  };
 }
 
-sub CustomGroups {
+sub CustomGroupings {
     my $self = shift;
     my $record = shift;
 
@@ -1236,7 +1236,7 @@ sub CustomGroups {
     $record_class = $self->RecordClassFromLookupType
         if !$record_class && $self->id;
 
-    return grep !$BUILTIN_GROUPS{$record_class}{$_}, $self->Groups( $record_class );
+    return grep !$BUILTIN_GROUPINGS{$record_class}{$_}, $self->Groupings( $record_class );
 }
 
 =head1 ApplyGlobally
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index b04f9ef..1afb3ca 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -95,17 +95,17 @@ sub _Init {
     return ( $self->SUPER::_Init(@_) );
 }
 
-sub LimitToGroup {
+sub LimitToGrouping {
     my $self = shift;
     my $obj = shift;
-    my $group = shift;
+    my $grouping = shift;
 
-    my $config = RT->Config->Get('CustomFieldGroups');
+    my $config = RT->Config->Get('CustomFieldGroupings');
        $config = {} unless ref($config) eq 'HASH';
        $config = $config->{ref($obj) || $obj} || {};
 
-    if ( $group ) {
-        my $list = $config->{$group};
+    if ( $grouping ) {
+        my $list = $config->{$grouping};
         unless ( $list and ref($list) eq 'ARRAY' and @$list ) {
             return $self->Limit( FIELD => 'id', VALUE => 0, ENTRYAGGREGATOR => 'AND' );
         }
diff --git a/share/html/Admin/Users/Modify.html b/share/html/Admin/Users/Modify.html
index f63a458..7b7668b 100755
--- a/share/html/Admin/Users/Modify.html
+++ b/share/html/Admin/Users/Modify.html
@@ -98,7 +98,7 @@
 </td><td>
 <textarea name="FreeformContactInfo" cols="20" rows="5"><%$UserObj->FreeformContactInfo||$FreeformContactInfo||''%></textarea>
 </td></tr>
-<& /Elements/EditCustomFields, Object => $UserObj, Group => 'Identity', InTable => 1 &>
+<& /Elements/EditCustomFields, Object => $UserObj, Grouping => 'Identity', InTable => 1 &>
 </table>
 </&>
 
@@ -117,7 +117,7 @@
     Name => [qw(CurrentPass Pass1 Pass2)],
 &>
 
-<& /Elements/EditCustomFields, Object => $UserObj, Group => 'Access control' &>
+<& /Elements/EditCustomFields, Object => $UserObj, Grouping => 'Access control' &>
 
 </&>
 % $m->callback( %ARGS, CallbackName => 'LeftColumnBottom', UserObj => $UserObj );
@@ -164,7 +164,7 @@
 <input name="Country" value="<%$UserObj->Country||$Country||''%>" />
 </td></tr>
 
-<& /Elements/EditCustomFields, Object => $UserObj, Group => 'Location', InTable => 1 &>
+<& /Elements/EditCustomFields, Object => $UserObj, Grouping => 'Location', InTable => 1 &>
 
 </table>
 </&>
@@ -193,13 +193,13 @@
 </td>
 </tr>
 
-<& /Elements/EditCustomFields, Object => $UserObj, Group => 'Phones', InTable => 1 &>
+<& /Elements/EditCustomFields, Object => $UserObj, Grouping => 'Phones', InTable => 1 &>
 
 </table>
 </&>
 <br />
 
-<& /Elements/EditCustomFieldCustomGroups, Object => $UserObj &>
+<& /Elements/EditCustomFieldCustomGroupings, Object => $UserObj &>
 
 % $m->callback( %ARGS, CallbackName => 'RightColumnBottom', UserObj => $UserObj );
 </td></tr>
diff --git a/share/html/Elements/EditCustomFieldCustomGroups b/share/html/Elements/EditCustomFieldCustomGroupings
similarity index 71%
rename from share/html/Elements/EditCustomFieldCustomGroups
rename to share/html/Elements/EditCustomFieldCustomGroupings
index 17b1b44..8ff7797 100644
--- a/share/html/Elements/EditCustomFieldCustomGroups
+++ b/share/html/Elements/EditCustomFieldCustomGroupings
@@ -1,10 +1,10 @@
-% foreach my $group ( RT::CustomField->CustomGroups( $Object ), '' ) {
+% foreach my $group ( RT::CustomField->CustomGroupings( $Object ), '' ) {
 <&| /Widgets/TitleBox,
     title => $group? loc($group) : loc('Custom Fields'),
     class => $css_class .' '. ($group? CSSClass("$css_class-$group") : ''),
     hide_empty => 1,
 &>
-<& EditCustomFields, %ARGS, Object => $Object, Group => $group &>
+<& EditCustomFields, %ARGS, Object => $Object, Grouping => $group &>
 </&>
 % }
 <%ARGS>
@@ -16,4 +16,4 @@ $css_class =~ s/^rt:://;
 $css_class =~ s/::/-/g;
 $css_class = CSSClass($css_class);
 $css_class .= '-info-cfs';
-</%INIT>
\ No newline at end of file
+</%INIT>
diff --git a/share/html/Elements/EditCustomFields b/share/html/Elements/EditCustomFields
index cc4bf91..41fe1c2 100644
--- a/share/html/Elements/EditCustomFields
+++ b/share/html/Elements/EditCustomFields
@@ -35,7 +35,7 @@
 $NamePrefix   ||= join '-', 'Object', ref($Object), ($Object->Id || ''), 'CustomField', '';
 $CustomFields ||= $Object->CustomFields;
 
-$CustomFields->LimitToGroup( $Object => $Group ) if defined $Group;
+$CustomFields->LimitToGrouping( $Object => $Grouping ) if defined $Grouping;
 
 $m->callback( %ARGS, CallbackName => 'MassageCustomFields', $CustomFields => $CustomFields );
 
@@ -58,7 +58,7 @@ if ( $AsTable ) {
 $Object
 $CustomFields => undef
 $NamePrefix   => ''
-$Group        => undef
+$Grouping     => undef
 $AsTable => 1
 $InTable => 0
 </%ARGS>
diff --git a/share/html/Elements/EditLinks b/share/html/Elements/EditLinks
index 34e4140..14b5042 100755
--- a/share/html/Elements/EditLinks
+++ b/share/html/Elements/EditLinks
@@ -158,7 +158,7 @@
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Referred to by'), Relation => 'ReferredToBy' &>:</td>
     <td class="entry"> <input name="RefersTo-<%$id%>" /></td>
   </tr>
-  <& /Elements/EditCustomFields, Object => $Object, Group => 'Links', InTable => 1 &>
+  <& /Elements/EditCustomFields, Object => $Object, Grouping => 'Links', InTable => 1 &>
 % $m->callback( CallbackName => 'NewLink' );
 </table>
 </td>
diff --git a/share/html/Elements/ShowCustomFieldCustomGroups b/share/html/Elements/ShowCustomFieldCustomGroupings
similarity index 76%
rename from share/html/Elements/ShowCustomFieldCustomGroups
rename to share/html/Elements/ShowCustomFieldCustomGroupings
index 598fa5f..a54ffdc 100644
--- a/share/html/Elements/ShowCustomFieldCustomGroups
+++ b/share/html/Elements/ShowCustomFieldCustomGroupings
@@ -1,11 +1,11 @@
-% foreach my $group ( RT::CustomField->CustomGroups( $Object ), '' ) {
+% foreach my $group ( RT::CustomField->CustomGroupings( $Object ), '' ) {
 <&| /Widgets/TitleBox,
     title => $group? loc($group) : loc('Custom Fields'),
     class => $css_class .' '. ($group? CSSClass("$css_class-$group") : ''),
     hide_empty => 1,
     %$TitleBoxARGS,
 &>
-<& ShowCustomFields, %ARGS, Object => $Object, Group => $group &>
+<& ShowCustomFields, %ARGS, Object => $Object, Grouping => $group &>
 </&>
 % }
 <%ARGS>
diff --git a/share/html/Elements/ShowCustomFields b/share/html/Elements/ShowCustomFields
index 2212007..c00c285 100644
--- a/share/html/Elements/ShowCustomFields
+++ b/share/html/Elements/ShowCustomFields
@@ -83,7 +83,7 @@ $m->callback(
     CustomFields => $CustomFields,
 );
 
-$CustomFields->LimitToGroup( $Object => $Group ) if defined $Group;
+$CustomFields->LimitToGrouping( $Object => $Grouping ) if defined $Grouping;
 
 # don't print anything if there is no custom fields
 return unless $CustomFields->First;
@@ -129,6 +129,6 @@ my $print_value = sub {
 <%ARGS>
 $Object => undef
 $CustomFields => $Object->CustomFields
-$Group => undef
+$Grouping => undef
 $Table => 1
 </%ARGS>
diff --git a/share/html/Elements/ShowLinks b/share/html/Elements/ShowLinks
index 0958a32..30ccffe 100755
--- a/share/html/Elements/ShowLinks
+++ b/share/html/Elements/ShowLinks
@@ -138,7 +138,7 @@ while ( my $link = $depends_on->Next ) {
 </ul>
     </td>
   </tr>
-  <& /Ticket/Elements/ShowCustomFields, Ticket => $Ticket, Group => 'Links', Table => 0 &>
+  <& /Ticket/Elements/ShowCustomFields, Ticket => $Ticket, Grouping => 'Links', Table => 0 &>
 % # Allow people to add more rows to the table
 % $m->callback( %ARGS );
 </table>
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 2cf40b9..d113186 100755
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -105,7 +105,7 @@
           %ARGS,
           Object => $ticket,
           CustomFields => $QueueObj->TicketCustomFields,
-          Group => 'Basics',
+          Grouping => 'Basics',
           InTable => 1,
       &>
       <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &>
@@ -113,7 +113,7 @@
   </&>
 % $m->callback( CallbackName => 'AfterBasics', QueueObj => $QueueObj );
 
-<& /Elements/EditCustomFieldCustomGroups,
+<& /Elements/EditCustomFieldCustomGroupings,
     %ARGS,
     Object => $ticket,
     CustomFields => $QueueObj->TicketCustomFields,
@@ -170,7 +170,7 @@
     %ARGS,
     Object => $ticket,
     CustomFields => $QueueObj->TicketCustomFields,
-    Group => 'People',
+    Grouping => 'People',
     InTable => 1,
 &>
 
@@ -264,7 +264,7 @@
     %ARGS,
     Object => $ticket,
     CustomFields => $QueueObj->TicketCustomFields,
-    Group => 'Dates',
+    Grouping => 'Dates',
     InTable => 1,
 &>
 </table>
@@ -290,7 +290,7 @@
     %ARGS,
     Object => $ticket,
     CustomFields => $QueueObj->TicketCustomFields,
-    Group => 'Links',
+    Grouping => 'Links',
     InTable => 1,
 &>
 </table>
diff --git a/share/html/Ticket/Elements/EditDates b/share/html/Ticket/Elements/EditDates
index f2d83fd..8d21d64 100755
--- a/share/html/Ticket/Elements/EditDates
+++ b/share/html/Ticket/Elements/EditDates
@@ -70,7 +70,7 @@
       <& /Elements/SelectDate, menu_prefix => 'Due', current => 0 &> (<% $TicketObj->DueObj->AsString %>)
     </td>
   </tr>
-  <& /Elements/EditCustomFields, Object => $TicketObj, Group => 'Dates', InTable => 1 &>
+  <& /Elements/EditCustomFields, Object => $TicketObj, Grouping => 'Dates', InTable => 1 &>
 % $m->callback( %ARGS, CallbackName => 'EndOfList', Ticket => $TicketObj );
 </table>
 <%ARGS>
diff --git a/share/html/Ticket/Elements/EditPeople b/share/html/Ticket/Elements/EditPeople
index 0673fba..8c83ec1 100755
--- a/share/html/Ticket/Elements/EditPeople
+++ b/share/html/Ticket/Elements/EditPeople
@@ -85,7 +85,7 @@
   <td class="value"><& EditWatchers, TicketObj => $Ticket, Watchers => $Ticket->AdminCc &></td>
 </tr>
 
-<& /Elements/EditCustomFields, Object => $Ticket, Group => 'People', InTable => 1 &>
+<& /Elements/EditCustomFields, Object => $Ticket, Grouping => 'People', InTable => 1 &>
 
 </table>
 
diff --git a/share/html/Ticket/Elements/ShowBasics b/share/html/Ticket/Elements/ShowBasics
index 4a86366..5cda9d2 100755
--- a/share/html/Ticket/Elements/ShowBasics
+++ b/share/html/Ticket/Elements/ShowBasics
@@ -83,7 +83,7 @@
     <td class="value"><& ShowQueue, Ticket => $Ticket, QueueObj => $Ticket->QueueObj &></td>
   </tr>
 % }
-  <& /Ticket/Elements/ShowCustomFields, Ticket => $Ticket, Group => 'Basics', Table => 0 &>
+  <& /Ticket/Elements/ShowCustomFields, Ticket => $Ticket, Grouping => 'Basics', Table => 0 &>
 % $m->callback( %ARGS, CallbackName => 'EndOfList', TicketObj => $Ticket );
 </table>
 <%ARGS>
diff --git a/share/html/Ticket/Elements/ShowDates b/share/html/Ticket/Elements/ShowDates
index de18e1d..2cb973f 100755
--- a/share/html/Ticket/Elements/ShowDates
+++ b/share/html/Ticket/Elements/ShowDates
@@ -84,7 +84,7 @@
     <td class="value"><% $UpdatedString | n %></td>
 % }
   </tr>
-  <& /Ticket/Elements/ShowCustomFields, Ticket => $Ticket, Group => 'Dates', Table => 0 &>
+  <& /Ticket/Elements/ShowCustomFields, Ticket => $Ticket, Grouping => 'Dates', Table => 0 &>
 % $m->callback( %ARGS, CallbackName => 'EndOfList', TicketObj => $Ticket );
 </table>
 <%ARGS>
diff --git a/share/html/Ticket/Elements/ShowPeople b/share/html/Ticket/Elements/ShowPeople
index af55efd..dadf613 100755
--- a/share/html/Ticket/Elements/ShowPeople
+++ b/share/html/Ticket/Elements/ShowPeople
@@ -66,7 +66,7 @@
     <td class="labeltop"><&|/l&>AdminCc</&>:</td>
     <td class="value"><& ShowGroupMembers, Group => $Ticket->AdminCc, Ticket => $Ticket &></td>
   </tr>
-  <& /Ticket/Elements/ShowCustomFields, Ticket => $Ticket, Group => 'People', Table => 0 &>
+  <& /Ticket/Elements/ShowCustomFields, Ticket => $Ticket, Grouping => 'People', Table => 0 &>
 </table>
 <%INIT>
 </%INIT>
diff --git a/share/html/Ticket/Elements/ShowSummary b/share/html/Ticket/Elements/ShowSummary
index de94323..a64a883 100755
--- a/share/html/Ticket/Elements/ShowSummary
+++ b/share/html/Ticket/Elements/ShowSummary
@@ -54,7 +54,7 @@
         class => 'ticket-info-basics',
     &><& /Ticket/Elements/ShowBasics, Ticket => $Ticket &></&>
 
-    <& /Elements/ShowCustomFieldCustomGroups,
+    <& /Elements/ShowCustomFieldCustomGroupings,
         Object       => $Ticket,
         TitleBoxARGS => {
             (($can_modify || $can_modify_cf)
diff --git a/share/html/Ticket/Modify.html b/share/html/Ticket/Modify.html
index 5e9c418..ba8e52d 100755
--- a/share/html/Ticket/Modify.html
+++ b/share/html/Ticket/Modify.html
@@ -57,11 +57,11 @@
 
 <&| /Widgets/TitleBox, title => loc('Modify ticket #[_1]',$TicketObj->Id), class=>'ticket-info-basics' &>
 <& Elements/EditBasics, TicketObj => $TicketObj &>
-<& /Elements/EditCustomFields, Object => $TicketObj, DefaultsFromTopArguments => 0, Group => 'Basics' &>
+<& /Elements/EditCustomFields, Object => $TicketObj, DefaultsFromTopArguments => 0, Grouping => 'Basics' &>
 </&>
 % $m->callback( CallbackName => 'AfterBasics', Ticket => $TicketObj );
 
-<& /Elements/EditCustomFieldCustomGroups, Object => $TicketObj, DefaultsFromTopArguments => 0 &>
+<& /Elements/EditCustomFieldCustomGroupings, Object => $TicketObj, DefaultsFromTopArguments => 0 &>
 
 <& /Elements/Submit, Name => 'SubmitTicket', Label => loc('Save Changes'), Caption => loc("If you've updated anything above, be sure to"), color => "#993333" &>
 </form>
diff --git a/share/html/Ticket/ModifyAll.html b/share/html/Ticket/ModifyAll.html
index 6c67d42..40c31ab 100755
--- a/share/html/Ticket/ModifyAll.html
+++ b/share/html/Ticket/ModifyAll.html
@@ -57,12 +57,12 @@
 
 <&| /Widgets/TitleBox, title => loc('Modify ticket # [_1]', $Ticket->Id), class=>'ticket-info-basics' &>
 <& Elements/EditBasics, TicketObj => $Ticket &>
-<& /Elements/EditCustomFields, Object => $Ticket, Group => 'Basics' &>
+<& /Elements/EditCustomFields, Object => $Ticket, Grouping => 'Basics' &>
 </&>
 
 % $m->callback(CallbackName => 'AfterBasics', Ticket => $Ticket);
 
-<& /Elements/EditCustomFieldCustomGroups, Object => $Ticket &>
+<& /Elements/EditCustomFieldCustomGroupings, Object => $Ticket &>
 
 <&| /Widgets/TitleBox, title => loc('Dates'), class=>'ticket-info-dates'&>
 <& Elements/EditDates, TicketObj => $Ticket &>
diff --git a/t/web/cf_groups.t b/t/web/cf_groups.t
index d7062a5..7f09e6d 100644
--- a/t/web/cf_groups.t
+++ b/t/web/cf_groups.t
@@ -5,7 +5,7 @@ use warnings;
 
 use RT::Test tests => 67;
 
-RT->Config->Set( 'CustomFieldGroups',
+RT->Config->Set( 'CustomFieldGroupings',
     'RT::Ticket' => {
         Basics => ['TestBasics'],
         Dates  => ['TestDates'],
@@ -17,7 +17,7 @@ RT->Config->Set( 'CustomFieldGroups',
 
 my %CF;
 
-foreach my $name ( map { @$_ } values %{ RT->Config->Get('CustomFieldGroups')->{'RT::Ticket'} } ) {
+foreach my $name ( map { @$_ } values %{ RT->Config->Get('CustomFieldGroupings')->{'RT::Ticket'} } ) {
     my $cf = RT::CustomField->new( RT->SystemUser );
     my ($id, $msg) = $cf->Create(
         Name => $name,
diff --git a/t/web/cf_groups_users.t b/t/web/cf_groups_users.t
index 755344f..9f69034 100644
--- a/t/web/cf_groups_users.t
+++ b/t/web/cf_groups_users.t
@@ -5,7 +5,7 @@ use warnings;
 
 use RT::Test tests => 49;
 
-RT->Config->Set( 'CustomFieldGroups',
+RT->Config->Set( 'CustomFieldGroupings',
     'RT::User' => {
         Identity         => ['TestIdentity'],
         'Access control' => ['TestAccessControl'],
@@ -17,7 +17,7 @@ RT->Config->Set( 'CustomFieldGroups',
 
 my %CF;
 
-foreach my $name ( map { @$_ } values %{ RT->Config->Get('CustomFieldGroups')->{'RT::User'} } ) {
+foreach my $name ( map { @$_ } values %{ RT->Config->Get('CustomFieldGroupings')->{'RT::User'} } ) {
     my $cf = RT::CustomField->new( RT->SystemUser );
     my ($id, $msg) = $cf->Create(
         Name => $name,

commit 3bfa15a5932108fe1ea054c6c75fe41623e96c74
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 15:21:50 2012 -0700

    Typo caused intepolation of non-existent variable

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 41a4c71..26eb47a 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -791,7 +791,7 @@ EOT
             my $groups = $config->Get('CustomFieldGroupings') || {};
 
             unless (ref($groups) eq 'HASH') {
-                RT->Logger->error("Config option %CustomFieldGroupings is a @{[ref $groups]} not a HASH; ignoring");
+                RT->Logger->error("Config option \%CustomFieldGroupings is a @{[ref $groups]} not a HASH; ignoring");
                 $groups = {};
             }
 

commit 7dc0985ef9781af62b84c6085b0754f2bb1bb24c
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 16:49:12 2012 -0700

    Document the new CF grouping config and methods

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 5b13b9e..0a3abc0 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -843,6 +843,39 @@ custom field values from external sources at runtime.
 
 Set(@CustomFieldValuesSources, ());
 
+=item C<%CustomFieldGroupings>
+
+This option affects the display of ticket and user custom fields in the web
+interface.  A nested datastructure defines how to group together custom fields
+under a mix of built-in and arbitrary headings ("groupings").
+
+Set C<%CustomFieldGroupings> to a nested hash similar to the following:
+
+    Set(%CustomFieldGroupings,
+        'RT::Ticket' => {
+            'Grouping Name'     => ['CF Name', 'Another CF'],
+            'Another Grouping'  => ['Some CF'],
+            'Dates'             => ['Shipped date'],
+        },
+        'RT::User' => {
+            'Phones' => ['Fax number'],
+        },
+    );
+
+The first level keys are record types for which CFs may be used, and the values
+are hashrefs.  The second level keys are the grouping names and the values are
+array refs containing a list of CF names.
+
+There are several special built-in groupings which RT displays in specific
+places (usually the collapsible box of the same title).
+
+For C<RT::Ticket>, these groupings are: C<Basics>, C<Dates>, C<Links>, C<People>
+
+For C<RT::User>: C<Identity>, C<Access control>, C<Location>, C<Phones>
+
+Extensions may also add their own built-in groupings, refer to the individual
+extension documentation for those.
+
 =item C<$CanonicalizeRedirectURLs>
 
 Set C<$CanonicalizeRedirectURLs> to 1 to use C<$WebURL> when
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index eaa9e72..67a6792 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1188,6 +1188,21 @@ sub CollectionClassFromLookupType {
     return $collection_class;
 }
 
+=head2 Groupings
+
+Returns a (sorted and lowercased) list of the groupings in which this custom
+field appears.
+
+If called on a loaded object, the returned list is limited to groupings which
+apply to the record class this CF applies to (L</RecordClassFromLookupType>).
+
+If passed a loaded object or a class name, the returned list is limited to
+groupings which apply to the class of the object or the specified class.
+
+If called on an unloaded object, all potential groupings are returned.
+
+=cut
+
 sub Groupings {
     my $self = shift;
     my $record = shift;
@@ -1213,6 +1228,22 @@ sub Groupings {
         @groups;
 }
 
+=head2 RegisterBuiltInGroupings
+
+Registers groupings to be considered a fundamental part of RT, either via use
+in core RT or via an extension.  These groupings must be rendered explicitly in
+Mason by specific calls to F</Elements/ShowCustomFields> and
+F</Elements/EditCustomFields>.  They will not show up automatically on normal
+display pages like configured custom groupings.
+
+Takes a set of key-value pairs of class names (valid L<RT::Record> subclasses)
+and array refs of grouping names to consider built-in.
+
+If a class already contains built-in groupings (such as L<RT::Ticket> and
+L<RT::User>), new groupings are appended.
+
+=cut
+
 my %BUILTIN_GROUPINGS;
 sub RegisterBuiltInGroupings {
     my $self = shift;
@@ -1228,6 +1259,13 @@ sub RegisterBuiltInGroupings {
     $BUILTIN_GROUPINGS{''} = { map { %$_ } values %BUILTIN_GROUPINGS  };
 }
 
+=head2 CustomGroupings
+
+Identical to L</Groupings> but filters out built-in groupings from the the
+returned list.
+
+=cut
+
 sub CustomGroupings {
     my $self = shift;
     my $record = shift;
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index 1afb3ca..55e5720 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -95,6 +95,25 @@ sub _Init {
     return ( $self->SUPER::_Init(@_) );
 }
 
+=head2 LimitToGrouping
+
+Limits this collection object to custom fields which appear under a
+specified grouping by calling L</Limit> for each CF name as appropriate.
+
+Requires an L<RT::Record> object or class name as the first argument and
+accepts a grouping name as the second.  If the grouping name is false
+(usually via the empty string), limits to custom fields which appear in no
+grouping.
+
+I<Caveat:> While the record object or class name is used to find the
+available groupings, no automatic limit is placed on the lookup type of
+the custom fields.  It's highly suggested you limit the collection by
+queue or another lookup type first.  This is already done for you if
+you're creating the collection via the L</CustomFields> method on an
+L<RT::Record> object.
+
+=cut
+
 sub LimitToGrouping {
     my $self = shift;
     my $obj = shift;

commit fab12f3a536a88a3d7a3d8236af7682f9fc234f3
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 16:51:21 2012 -0700

    Refactor calculation of the grouping record class to use

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 67a6792..35194f9 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1205,11 +1205,7 @@ If called on an unloaded object, all potential groupings are returned.
 
 sub Groupings {
     my $self = shift;
-    my $record = shift;
-
-    my $record_class = ref($record) || $record || '';
-    $record_class = $self->RecordClassFromLookupType
-        if !$record_class && $self->id;
+    my $record_class = $self->_GroupingClass(shift);
 
     my $config = RT->Config->Get('CustomFieldGroupings');
        $config = {} unless ref($config) eq 'HASH';
@@ -1268,13 +1264,19 @@ returned list.
 
 sub CustomGroupings {
     my $self = shift;
-    my $record = shift;
+    my $record_class = $self->_GroupingClass(shift);
+    return grep !$BUILTIN_GROUPINGS{$record_class}{$_}, $self->Groupings( $record_class );
+}
+
+sub _GroupingClass {
+    my $self    = shift;
+    my $record  = shift;
 
     my $record_class = ref($record) || $record || '';
     $record_class = $self->RecordClassFromLookupType
         if !$record_class && $self->id;
 
-    return grep !$BUILTIN_GROUPINGS{$record_class}{$_}, $self->Groupings( $record_class );
+    return $record_class;
 }
 
 =head1 ApplyGlobally

commit ea1f5226f46d9ad921ab4566397d2c99e95a4baa
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 16:52:31 2012 -0700

    Move CustomGroupings closer to Groupings so the documentation is adjacent

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 35194f9..f4b5b0c 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1224,6 +1224,30 @@ sub Groupings {
         @groups;
 }
 
+=head2 CustomGroupings
+
+Identical to L</Groupings> but filters out built-in groupings from the the
+returned list.
+
+=cut
+
+sub CustomGroupings {
+    my $self = shift;
+    my $record_class = $self->_GroupingClass(shift);
+    return grep !$BUILTIN_GROUPINGS{$record_class}{$_}, $self->Groupings( $record_class );
+}
+
+sub _GroupingClass {
+    my $self    = shift;
+    my $record  = shift;
+
+    my $record_class = ref($record) || $record || '';
+    $record_class = $self->RecordClassFromLookupType
+        if !$record_class && $self->id;
+
+    return $record_class;
+}
+
 =head2 RegisterBuiltInGroupings
 
 Registers groupings to be considered a fundamental part of RT, either via use
@@ -1255,30 +1279,6 @@ sub RegisterBuiltInGroupings {
     $BUILTIN_GROUPINGS{''} = { map { %$_ } values %BUILTIN_GROUPINGS  };
 }
 
-=head2 CustomGroupings
-
-Identical to L</Groupings> but filters out built-in groupings from the the
-returned list.
-
-=cut
-
-sub CustomGroupings {
-    my $self = shift;
-    my $record_class = $self->_GroupingClass(shift);
-    return grep !$BUILTIN_GROUPINGS{$record_class}{$_}, $self->Groupings( $record_class );
-}
-
-sub _GroupingClass {
-    my $self    = shift;
-    my $record  = shift;
-
-    my $record_class = ref($record) || $record || '';
-    $record_class = $self->RecordClassFromLookupType
-        if !$record_class && $self->id;
-
-    return $record_class;
-}
-
 =head1 ApplyGlobally
 
 Certain custom fields (users, groups) should only be applied globally

commit 43cd7a43fbd909ad5408e951e59cb60f77374932
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 17:42:22 2012 -0700

    RT::CustomField->Groupings should always return built-in groupings
    
    Even if they're not specified in the config.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 0a3abc0..5859bd0 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2630,19 +2630,4 @@ with L</Lifecycles> (see L</Labeling and defining actions>).
 
 =cut
 
-Set(%CustomFieldGroupings,
-    'RT::Ticket' => {
-        Basics => [],
-        Dates => [],
-        People => [],
-        Links   => [],
-    },
-    'RT::User' => {
-        Identity => [],
-        'Access control' => [],
-        Location => [],
-        Phones   => [],
-    },
-);
-
 1;
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index f4b5b0c..bdb040b 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -192,6 +192,7 @@ our %FieldTypes = (
 );
 
 
+my %BUILTIN_GROUPINGS;
 our %FRIENDLY_OBJECT_TYPES =  ();
 
 RT::CustomField->_ForObjectType( 'RT::Queue-RT::Ticket' => "Tickets", );    #loc
@@ -1212,9 +1213,11 @@ sub Groupings {
 
     my @groups;
     if ( $record_class ) {
-        @groups = keys %{ $config->{$record_class} };
+        push @groups, keys %{ $config->{$record_class} || {} };
+        push @groups, keys %{ $BUILTIN_GROUPINGS{$record_class} || {} };
     } else {
-        @groups = map { keys %$_ } values %$config;
+        push @groups, map { keys %$_ } values %$config;
+        push @groups, map { keys %$_ } values %BUILTIN_GROUPINGS;
     }
 
     my %seen;
@@ -1264,7 +1267,6 @@ L<RT::User>), new groupings are appended.
 
 =cut
 
-my %BUILTIN_GROUPINGS;
 sub RegisterBuiltInGroupings {
     my $self = shift;
     my %new  = @_;

commit 6fd71d6e63319ea4090836457a5464102cbffaa4
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 15 17:46:34 2012 -0700

    Allow Groupings and CustomGroupings to be called as class methods

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index bdb040b..46736fa 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -57,7 +57,7 @@ use base 'RT::Record';
 
 sub Table {'CustomFields'}
 
-
+use Scalar::Util qw(blessed);
 use RT::CustomFieldValues;
 use RT::ObjectCustomFields;
 use RT::ObjectCustomFieldValues;
@@ -1246,7 +1246,7 @@ sub _GroupingClass {
 
     my $record_class = ref($record) || $record || '';
     $record_class = $self->RecordClassFromLookupType
-        if !$record_class && $self->id;
+        if !$record_class and blessed($self) and $self->id;
 
     return $record_class;
 }

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


More information about the Rt-commit mailing list