X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FCustomFields.pm;h=ba3b01cfbac7f84b7fda9f9cbe8b1243f15037fc;hp=017018ef429690fce0c05ca0a2cf7a93f760fb5e;hb=919e930aa9279b3c5cd12b593889cd6de79d67bf;hpb=7588a4ac90a9b07c08a3107cd1107d773be1c991 diff --git a/rt/lib/RT/CustomFields.pm b/rt/lib/RT/CustomFields.pm index 017018ef4..ba3b01cfb 100644 --- a/rt/lib/RT/CustomFields.pm +++ b/rt/lib/RT/CustomFields.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -68,8 +68,6 @@ package RT::CustomFields; use strict; use warnings; -use DBIx::SearchBuilder::Unique; - use RT::CustomField; use base 'RT::SearchBuilder'; @@ -121,8 +119,7 @@ sub LimitToChildType { my $self = shift; my $lookup = shift; - $self->Limit( FIELD => 'LookupType', VALUE => "$lookup" ); - $self->Limit( FIELD => 'LookupType', ENDSWITH => "$lookup" ); + $self->Limit( FIELD => 'LookupType', VALUE => "$lookup", OPERATOR => "ENDSWITH" ); } @@ -137,10 +134,28 @@ sub LimitToParentType { my $self = shift; my $lookup = shift; - $self->Limit( FIELD => 'LookupType', VALUE => "$lookup" ); - $self->Limit( FIELD => 'LookupType', STARTSWITH => "$lookup" ); + $self->Limit( FIELD => 'LookupType', VALUE => "$lookup", OPERATOR => "STARTSWITH" ); } +=head2 LimitToObjectId + +Takes an ObjectId and limits the collection to CFs applied to said object. + +When called multiple times the ObjectId limits are joined with OR. + +=cut + +sub LimitToObjectId { + my $self = shift; + my $id = shift; + $self->Limit( + ALIAS => $self->_OCFAlias, + FIELD => 'ObjectId', + OPERATOR => '=', + VALUE => $id || 0, + ENTRYAGGREGATOR => 'OR' + ); +} =head2 LimitToGlobalOrObjectId @@ -155,19 +170,11 @@ sub LimitToGlobalOrObjectId { foreach my $id (@_) { - $self->Limit( ALIAS => $self->_OCFAlias, - FIELD => 'ObjectId', - OPERATOR => '=', - VALUE => $id || 0, - ENTRYAGGREGATOR => 'OR' ); - $global_only = 0 if $id; + $self->LimitToObjectId($id); + $global_only = 0 if $id; } - $self->Limit( ALIAS => $self->_OCFAlias, - FIELD => 'ObjectId', - OPERATOR => '=', - VALUE => 0, - ENTRYAGGREGATOR => 'OR' ) unless $global_only; + $self->LimitToObjectId(0) unless $global_only; } sub _LimitToOCFs { @@ -360,22 +367,20 @@ sub _OCFAlias { } -=head2 Next +=head2 AddRecord -Returns the next custom field that this user can see. +Overrides the collection to ensure that only custom fields the user can +see are returned; also propagates down the L. =cut -sub Next { +sub AddRecord { my $self = shift; + my ($record) = @_; - my $CF = $self->SUPER::Next(); - return $CF unless $CF; - - $CF->SetContextObject( $self->ContextObject ); - - return $self->Next unless $CF->CurrentUserHasRight('SeeCustomField'); - return $CF; + $record->SetContextObject( $self->ContextObject ); + return unless $record->CurrentUserHasRight('SeeCustomField'); + return $self->SUPER::AddRecord( $record ); } =head2 NewItem