[Rt-commit] [rtir] 01/05: Create HasRight subclass and remove RT::Queue::HasRight from LexWrap

Jim Brandt jbrandt at bestpractical.com
Fri Mar 21 17:18:35 EDT 2014


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

jbrandt pushed a commit to branch 3.2/remove-lexwrap
in repository rtir.

commit ad051987bdb208c695457ed5ff3dcfcdd1e2aef4
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Mar 21 13:22:57 2014 -0400

    Create HasRight subclass and remove RT::Queue::HasRight from LexWrap
    
    In RT 4.2, HasRight was generalized and moved up to RT::Record.
    This caused an error because Hook::LexWrap could no longer wrap
    RT::Queue::HasRight because it wasn't there. However, this also
    made it easier to create a HasRight subclass without using
    Hook::LexWrap.
---
 lib/RT/IR.pm | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 34f8855..bf80ca9 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -699,31 +699,39 @@ if ( RT::IR->HasConstituency ) {
         return;
     };
 
-    wrap 'RT::Queue::HasRight', pre => sub {
-        return unless $_[0]->id;
-        return if $_[0]->{'disable_constituency_right_check'};
-        return if $_[0]->{'_for_ticket'};
-        return unless $_[0]->__Value('Name') =~
-            /^(Incidents|Incident Reports|Investigations|Blocks)$/i;
+    require RT::Queue;
+    package RT::Queue;
+
+    sub HasRight {
+        my $self = shift;
+        my %args = @_;
+
+        return $self->SUPER::HasRight(%args)
+            if ( $self->{'disable_constituency_right_check'}
+                 or $self->{'_for_ticket'}
+                 or not $self->__Value('Name') =~
+                     /^(Incidents|Incident Reports|Investigations|Blocks)$/i );
 
         my $name = $1;
-        my %args = (@_[1..(@_-2)]);
-        $args{'Principal'} ||= $_[0]->CurrentUser;
+        $args{'Principal'} ||= $self->CurrentUser;
 
         my $queues = RT::Queues->new( RT->SystemUser );
-        $queues->Limit( FIELD => 'Name', OPERATOR => 'STARTSWITH', VALUE => "$name - " );
+        $queues->Limit(
+            FIELD => 'Name',
+            OPERATOR => 'STARTSWITH',
+            VALUE => "$name - ",
+            CASESENSITIVE => 1 );
         my $has_right = $args{'Principal'}->HasRight(
             %args,
-            Object => $_[0],
+            Object => $self,
             EquivObjects => $queues->ItemsArrayRef,
         );
-        $_[-1] = $has_right;
-        return;
-    };
 
+        # Short circuit and return if we already got a true result
+        return $has_right if $has_right;
 
-    require RT::Queue;
-    package RT::Queue;
+        return $self->SUPER::HasRight(%args);
+    }
 
     sub CorrespondAddress { GetQueueAttribute(shift, 'CorrespondAddress') }
     sub CommentAddress { GetQueueAttribute(shift, 'CommentAddress') }

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


More information about the rt-commit mailing list