[Rt-commit] [rtir] 02/09: Override of _GroupingClass to implement RTIR::Ticket

Kevin Falcone falcone at bestpractical.com
Fri Jul 25 15:16:01 EDT 2014


This is an automated email from the git hooks/post-receive script.

falcone pushed a commit to branch 3.2/customfieldgroupings
in repository rtir.

commit 01246588214630aa872a6088e81bb5d562b879b7
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Fri Jul 25 14:28:43 2014 -0400

    Override of _GroupingClass to implement RTIR::Ticket
    
    Register RTIR::Ticket 'core' groupings of Basics, Dates and People.
    RTIR never shows a Links box, so we don't register that.
    
    The rest of this code is essentially a complicated trawl to get a Queue
    so we can call OurQueue and find out if this ticket is RTIR or not.
    
    If we have a ticket, great, use the QueueObj.  If not, try to find a
    Queue hanging off the CustomField.  Worst case, rely on
    RT::CustomFields->LimitToGrouping passing a ContextObj which is
    generally going to be a Queue we can use.  If all that fails, we just
    return what core returns, which is just ref $record.
    
    RTIR primarily uses Ticket and ContextObj (during Creation when there is
    no $self or $record).
---
 lib/RT/IR.pm | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 5ec8ffa..067ee13 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -746,6 +746,56 @@ require RT::Action::AutoOpenInactive;
     };
 }
 
+# Because you can't (easily/cleanly/prettily) merge two
+# RT::Ticket entries in %CustomFieldGroupings, add a new
+# RTIR::Ticket option.
+require RT::CustomField;
+{
+    RT::CustomField->RegisterBuiltInGroupings(
+            'RTIR::Ticket'    => [ qw(Basics Dates People) ],
+    );
+
+    no warnings 'redefine';
+    my $orig_GroupingClass = RT::CustomField->can('_GroupingClass');
+    *RT::CustomField::_GroupingClass = sub {
+        my $self        = shift;
+        my $record      = shift;
+        my $context_obj = shift;
+
+        my $record_class = $orig_GroupingClass->($self,$record);
+
+        # we're only doing shenanigans on Tickets, which might be RTIR::Ticket
+        unless ($record_class eq 'RT::Ticket') {
+            return $record_class;
+        }
+
+        my $queue = undef;
+        # on Create we can get an empty RT::Ticket here
+        if ( ref $record && $record->Id ) {
+            $queue = $record->QueueObj->Name;
+        # if we have an empty ticket, but a real CustomField,
+        # we can pull the Queue out of the ACLEquivalenceObjects
+        } elsif ( ref $self && $self->id ) {
+            for my $obj ($self->ACLEquivalenceObjects) {
+                next unless (ref $obj eq 'RT::Queue');
+                $queue = $obj->Name;
+                last;
+            }
+        # RT::CustomFields->LimitToGrouping uses a class method call, and during
+        # creation, it passes an empty RT::Ticket, so it also passes its ContextObject
+        # which is generally a Queue we can use here.
+        } elsif ( ref $context_obj eq 'RT::Queue' ) {
+            $queue = $context_obj->Name;
+        }
+
+        if (RT::IR->OurQueue($queue)) {
+            return 'RTIR::Ticket';
+        } else {
+            return $record_class;
+        }
+    };
+}
+
 if ( RT::IR->HasConstituency ) {
     # Queue {Comment,Correspond}Address for multiple constituencies
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the rt-commit mailing list