[Rt-commit] rt branch, 4.2/restore-queue-watcher-clauses, updated. rt-4.1.6-155-g3deb81d
Thomas Sibley
trs at bestpractical.com
Fri Feb 8 18:42:03 EST 2013
The branch, 4.2/restore-queue-watcher-clauses has been updated
via 3deb81d2e5fae40395d138bd8b218eaab5e95cac (commit)
via 57f258aa2fb7e0c228abd59830c7b3118b85a24b (commit)
from 0dabe99f8f2a24d89888b2a17803fbe084079f01 (commit)
Summary of changes:
lib/RT/Report/Tickets.pm | 6 +++++-
lib/RT/SearchBuilder/Role/Roles.pm | 30 +++++++++++++++++++++++-------
lib/RT/Tickets.pm | 7 ++++---
3 files changed, 32 insertions(+), 11 deletions(-)
- Log -----------------------------------------------------------------
commit 57f258aa2fb7e0c228abd59830c7b3118b85a24b
Author: Thomas Sibley <trs at bestpractical.com>
Date: Fri Feb 8 14:43:56 2013 -0800
Support ordering tickets by queue watchers
Previously OrderByCols accepted FIELD => "QueueCc" but treated it as
FIELD => "Cc", that is, as the ticket watchers instead of queue
watchers. Resolve this inconsistency by passing the target role group
class as an argument to _WatcherJoin, which percolates into
_RolesGroupsJoin. This matches the behaviour of the RoleLimit method,
which handles limits on ticket and queue watchers.
diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index 0922dbb..56fcde7 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -267,7 +267,7 @@ sub _FieldToFunction {
my $u_alias = $self->{"_sql_report_watcher_users_alias_$type"};
unless ( $u_alias ) {
my ($g_alias, $gm_alias);
- ($g_alias, $gm_alias, $u_alias) = $self->_WatcherJoin( $type );
+ ($g_alias, $gm_alias, $u_alias) = $self->_WatcherJoin( Type => $type );
$self->{"_sql_report_watcher_users_alias_$type"} = $u_alias;
}
@args{qw(ALIAS FIELD)} = ($u_alias, $column);
diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm
index 13aa360..6da13e0 100644
--- a/lib/RT/SearchBuilder/Role/Roles.pm
+++ b/lib/RT/SearchBuilder/Role/Roles.pm
@@ -159,10 +159,8 @@ and for ordering.
sub _WatcherJoin {
my $self = shift;
- my $type = shift || '';
-
- my $groups = $self->_RoleGroupsJoin( Type => $type );
+ my $groups = $self->_RoleGroupsJoin(@_);
my $group_members = $self->_GroupMembersJoin( GroupsAlias => $groups );
# XXX: work around, we must hide groups that
# are members of the role group we search in,
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 278dbea..6c81505 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -1663,10 +1663,11 @@ sub OrderByCols {
my $meta = $FIELD_METADATA{$field};
if ( defined $meta->[0] && $meta->[0] eq 'WATCHERFIELD' ) {
# cache alias as we want to use one alias per watcher type for sorting
- my $users = $self->{_sql_u_watchers_alias_for_sort}{ $meta->[1] };
+ my $cache_key = join "-", map { $_ || "" } @$meta[1,2];
+ my $users = $self->{_sql_u_watchers_alias_for_sort}{ $cache_key };
unless ( $users ) {
- $self->{_sql_u_watchers_alias_for_sort}{ $meta->[1] }
- = $users = ( $self->_WatcherJoin( $meta->[1] ) )[2];
+ $self->{_sql_u_watchers_alias_for_sort}{ $cache_key }
+ = $users = ( $self->_WatcherJoin( Type => $meta->[1], Class => "RT::" . ($meta->[2] || 'Ticket') ) )[2];
}
push @res, { %$row, ALIAS => $users, FIELD => $subkey };
} elsif ( defined $meta->[0] && $meta->[0] eq 'CUSTOMFIELD' ) {
commit 3deb81d2e5fae40395d138bd8b218eaab5e95cac
Author: Thomas Sibley <trs at bestpractical.com>
Date: Fri Feb 8 15:05:58 2013 -0800
Encapsulate the role group class into a method
This enables overriding of the default of blessed($self->NewItem).
NewItem may return a subclass of RT::Ticket, which doesn't match the
database values and confuses the role limits. An example is
RT::Reports::Tickets which uses a NewItem of RT::Reports::Tickets::Entry
but cares about role groups on RT::Ticket.
The method is provided by the Roles role, so most consumers need not
worry about this implementation detail unless they're doing something
wonky.
diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index 56fcde7..c39fa90 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -301,6 +301,10 @@ sub NewItem {
return RT::Report::Tickets::Entry->new(RT->SystemUser); # $self->CurrentUser);
}
+# This is necessary since normally NewItem (above) is used to intuit the
+# correct class. However, since we're abusing a subclass, it's incorrect.
+sub _RoleGroupClass { "RT::Ticket" }
+
=head2 AddEmptyRows
diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm
index 6da13e0..ea538e1 100644
--- a/lib/RT/SearchBuilder/Role/Roles.pm
+++ b/lib/RT/SearchBuilder/Role/Roles.pm
@@ -74,14 +74,32 @@ require RT::EmailParser;
=head1 PROVIDES
+=head2 _RoleGroupClass
+
+Returns the class name on which role searches should be based. This relates to
+the internal L<RT::Group/Domain> and distinguishes between roles on the objects
+being searched and their counterpart roles on containing classes. For example,
+limiting on L<RT::Queue> roles while searching for L<RT::Ticket>s.
+
+The default implementation is:
+
+ blessed($self->NewItem)
+
+which is the class that this collection object searches and instatiates objects
+for. If you're doing something hinky, you may need to override this method.
+
=cut
+sub _RoleGroupClass {
+ my $self = shift;
+ return blessed($self->NewItem);
+}
+
sub _RoleGroupsJoin {
my $self = shift;
my %args = (New => 0, Class => '', Type => '', @_);
- my $item = $self->NewItem;
- $args{'Class'} ||= blessed($item);
+ $args{'Class'} ||= $self->_RoleGroupClass;
return $self->{'_sql_role_group_aliases'}{ $args{'Class'} .'-'. $args{'Type'} }
if $self->{'_sql_role_group_aliases'}{ $args{'Class'} .'-'. $args{'Type'} }
@@ -91,7 +109,7 @@ sub _RoleGroupsJoin {
# (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};
+ my $instance = $self->_RoleGroupClass eq $args{Class} ? "id" : $args{Class};
$instance =~ s/^RT:://;
# Watcher groups are always created for each record, so we use INNER join.
@@ -198,7 +216,7 @@ sub RoleLimit {
@_
);
- my $class = $args{CLASS} || blessed($self->NewItem);
+ my $class = $args{CLASS} || $self->_RoleGroupClass;
$args{FIELD} ||= 'id' if $args{VALUE} =~ /^\d+$/;
my $type = delete $args{TYPE};
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list