Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cf on transactions querybuilder #325

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion share/html/Elements/RT__Transaction/ColumnMap
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ my $get_ticket_value = sub {
return sub { return $_[0]->ObjectType eq 'RT::Ticket' ? $sub->(@_) : '' };
};

my $COLUMN_MAP = {
my ($COLUMN_MAP, $WCOLUMN_MAP);
$WCOLUMN_MAP = $COLUMN_MAP = {
ObjectType => {
title => 'Object Type', # loc
attribute => 'ObjectType',
Expand Down Expand Up @@ -186,6 +187,53 @@ my $COLUMN_MAP = {
title => 'Ticket FinalPriority', # loc
value => $get_ticket_value->( @_, sub { $_[0]->Object->FinalPriority } ),
},
TicketCustomFieldView => {
attribute => sub { return shift @_ },
title => sub { return pop @_ },
value => sub {
my $self = $WCOLUMN_MAP->{TicketCustomFieldView};
my $cf = $self->{load}->(@_);
return unless $cf->Id;
return $self->{render}->( $cf, $cf->ValuesForObject($_[0]->Object)->ItemsArrayRef );
},
load => sub {
# Cache the CF object on a per-request basis, to avoid
# having to load it for every row
my $key = join("-","CF",
$_[0]->Object->CustomFieldLookupType,
$_[0]->Object->CustomFieldLookupId,
$_[-1]);

my $cf = $m->notes($key);
unless ($cf) {
$cf = $_[0]->Object->LoadCustomFieldByIdentifier($_[-1]);
RT->Logger->debug("Unable to load $_[-1] for ".$_[0]->Object->CustomFieldLookupType." ".$_[0]->Object->CustomFieldLookupId)
unless $cf->Id;
$m->notes($key, $cf);
}
return $cf;
},
render => sub {
my ($cf, $ocfvs) = @_;
my $comp = $m->comp_exists("/Elements/ShowCustomField".$cf->Type)
? "/Elements/ShowCustomField".$cf->Type
: undef;

my @values = map {
$comp
? \($m->scomp( $comp, Object => $_ ))
: $_->Content
} @$ocfvs;

if (@values > 1) {
for my $value (splice @values) {
push @values, \"<li>", $value, \"</li> \n";
}
@values = (\"<ul class='cf-values'>", @values, \"</ul>");
}
return @values;
},
},
};


Expand Down
32 changes: 30 additions & 2 deletions share/html/Search/Elements/BuildFormatString
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ if ( $Class eq 'RT::Transactions' ) {
my $queue = RT::Queue->new( $session{'CurrentUser'} );
$queue->Load($id);
next unless $queue->Id;
$CustomFields->LimitToQueue( $queue->Id );
$CustomFields->SetContextObject($queue) if keys %queues == 1;
# Do not use ->LimitToQueue here because it hardcodes a LookupType of 'RT::Queue-RT::Ticket'
$CustomFields->Limit (ALIAS => $CustomFields->_OCFAlias,
ENTRYAGGREGATOR => 'OR',
FIELD => 'ObjectId',
VALUE => $queue->Id,
);
}
$CustomFields->Limit(
ALIAS => $CustomFields->_OCFAlias,
Expand All @@ -108,6 +112,30 @@ if ( $Class eq 'RT::Transactions' ) {
push @fields, "CustomField.{" . $CustomField->Name . "}";
push @fields, "CustomFieldView.{" . $CustomField->Name . "}";
}
my $TicketCustomFields = RT::CustomFields->new( $session{'CurrentUser'} );
foreach my $id ( keys %queues ) {

# Gotta load up the $queue object, since queues get stored by name now.
my $queue = RT::Queue->new( $session{'CurrentUser'} );
$queue->Load($id);
next unless $queue->Id;
$TicketCustomFields->Limit (ALIAS => $CustomFields->_OCFAlias,
ENTRYAGGREGATOR => 'OR',
FIELD => 'ObjectId',
VALUE => $queue->Id,
);
}
$TicketCustomFields->Limit(
ALIAS => $TicketCustomFields->_OCFAlias,
ENTRYAGGREGATOR => 'OR',
FIELD => 'ObjectId',
VALUE => 0,
);
$TicketCustomFields->LimitToLookupType('RT::Queue-RT::Ticket');

while ( my $TicketCustomField = $TicketCustomFields->Next ) {
push @fields, "TicketCustomFieldView.{" . $TicketCustomField->Name . "}";
}
}
elsif ( $Class eq 'RT::Assets' ) {
$Format ||= RT->Config->Get('AssetDefaultSearchResultFormat');
Expand Down