limit ticket creation queue dropdowns based on ACL, RT#7778
[freeside.git] / rt / lib / RT / Queue_Overlay.pm
index a839679..dcca84e 100644 (file)
@@ -381,6 +381,8 @@ sub Create {
             unless $status;
     }
 
+    RT->System->QueueCacheNeedsUpdate(1);
+
     return ( $id, $self->loc("Queue created") );
 }
 
@@ -421,6 +423,8 @@ sub SetDisabled {
 
     $RT::Handle->Commit();
 
+    RT->System->QueueCacheNeedsUpdate(1);
+
     if ( $val == 1 ) {
         return (1, $self->loc("Queue disabled"));
     } else {
@@ -636,6 +640,7 @@ sub TicketCustomFields {
         $cfs->SetContextObject( $self );
        $cfs->LimitToGlobalOrObjectId( $self->Id );
        $cfs->LimitToLookupType( 'RT::Queue-RT::Ticket' );
+        $cfs->ApplySortOrder;
     }
     return ($cfs);
 }
@@ -658,6 +663,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 +793,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'} )