[Rt-commit] rt branch, 4.2/restore-queue-watcher-clauses, created. rt-4.1.6-153-g0dabe99

Thomas Sibley trs at bestpractical.com
Fri Feb 1 14:07:26 EST 2013


The branch, 4.2/restore-queue-watcher-clauses has been created
        at  0dabe99f8f2a24d89888b2a17803fbe084079f01 (commit)

- Log -----------------------------------------------------------------
commit 0dabe99f8f2a24d89888b2a17803fbe084079f01
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Jan 31 18:39:03 2013 -0800

    Restore QueueWatcher conditions to TicketSQL and the collection API
    
    The class on which we want to look for roles was lost during the
    refactoring of role limits and joins in commit 4b15643.  This commit
    restores the ability to tell RoleLimit that you're interested in roles
    on containing classes like RT::Queue.  It also allows the same logic to
    happen with arbitrary other record types using roles, removing the
    hardcoded "Queue or id" column choice.

diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm
index 122278c..13aa360 100644
--- a/lib/RT/SearchBuilder/Role/Roles.pm
+++ b/lib/RT/SearchBuilder/Role/Roles.pm
@@ -78,16 +78,26 @@ require RT::EmailParser;
 
 sub _RoleGroupsJoin {
     my $self = shift;
-    my %args = (New => 0, Class => 'Ticket', Type => '', @_);
-    $args{Class} =~ s/^RT:://;
+    my %args = (New => 0, Class => '', Type => '', @_);
+    my $item = $self->NewItem;
+
+    $args{'Class'} ||= blessed($item);
+
     return $self->{'_sql_role_group_aliases'}{ $args{'Class'} .'-'. $args{'Type'} }
         if $self->{'_sql_role_group_aliases'}{ $args{'Class'} .'-'. $args{'Type'} }
            && !$args{'New'};
 
-    # we always have watcher groups for ticket, so we use INNER join
+    # If we're looking at a role group on a class that "contains" this record
+    # (i.e. roles on queues for tickets), then we assume that the current
+    # record has a column named after the containing class (i.e.
+    # Tickets.Queue).
+    my $instance = blessed($item) eq $args{Class} ? "id" : $args{Class};
+       $instance =~ s/^RT:://;
+
+    # Watcher groups are always created for each record, so we use INNER join.
     my $groups = $self->Join(
         ALIAS1          => 'main',
-        FIELD1          => $args{'Class'} eq 'Queue'? 'Queue': 'id',
+        FIELD1          => $instance,
         TABLE2          => 'Groups',
         FIELD2          => 'Instance',
         ENTRYAGGREGATOR => 'AND',
@@ -96,7 +106,7 @@ sub _RoleGroupsJoin {
         LEFTJOIN        => $groups,
         ALIAS           => $groups,
         FIELD           => 'Domain',
-        VALUE           => 'RT::'. $args{'Class'} .'-Role',
+        VALUE           => $args{'Class'} .'-Role',
     );
     $self->Limit(
         LEFTJOIN        => $groups,
@@ -183,13 +193,14 @@ sub RoleLimit {
     my $self = shift;
     my %args = (
         TYPE => '',
+        CLASS => '',
         FIELD => undef,
         OPERATOR => '=',
         VALUE => undef,
         @_
     );
 
-    my $class = blessed($self->NewItem);
+    my $class = $args{CLASS} || blessed($self->NewItem);
 
     $args{FIELD} ||= 'id' if $args{VALUE} =~ /^\d+$/;
     my $type = delete $args{TYPE};
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 1052d5f..278dbea 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -900,6 +900,7 @@ sub _WatcherLimit {
 
     $self->RoleLimit(
         TYPE      => $type,
+        CLASS     => "RT::$class",
         FIELD     => $rest{SUBKEY},
         OPERATOR  => $op,
         VALUE     => $value,

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


More information about the Rt-commit mailing list