import rt 3.8.8
[freeside.git] / rt / lib / RT / Queue_Overlay.pm
index a839679..98bdec5 100644 (file)
@@ -636,6 +636,7 @@ sub TicketCustomFields {
         $cfs->SetContextObject( $self );
        $cfs->LimitToGlobalOrObjectId( $self->Id );
        $cfs->LimitToLookupType( 'RT::Queue-RT::Ticket' );
+        $cfs->ApplySortOrder;
     }
     return ($cfs);
 }
@@ -658,6 +659,7 @@ sub TicketTransactionCustomFields {
     if ( $self->CurrentUserHasRight('SeeQueue') ) {
        $cfs->LimitToGlobalOrObjectId( $self->Id );
        $cfs->LimitToLookupType( 'RT::Queue-RT::Ticket-RT::Transaction' );
+        $cfs->ApplySortOrder;
     }
     return ($cfs);
 }
@@ -787,8 +789,15 @@ sub _AddWatcher {
     my $principal = RT::Principal->new( $self->CurrentUser );
     if ( $args{'PrincipalId'} ) {
         $principal->Load( $args{'PrincipalId'} );
+        if ( $principal->id and $principal->IsUser and my $email = $principal->Object->EmailAddress ) {
+            return (0, $self->loc("[_1] is an address RT receives mail at. Adding it as a '[_2]' would create a mail loop", $email, $self->loc($args{'Type'})))
+                if RT::EmailParser->IsRTAddress( $email );
+        }
     }
     elsif ( $args{'Email'} ) {
+        if ( RT::EmailParser->IsRTAddress( $args{'Email'} ) ) {
+            return (0, $self->loc("[_1] is an address RT receives mail at. Adding it as a '[_2]' would create a mail loop", $args{'Email'}, $self->loc($args{'Type'})));
+        }
         my $user = RT::User->new($self->CurrentUser);
         $user->LoadByEmail( $args{'Email'} );
         $user->Load( $args{'Email'} )