[rt-users] Create a new Ticket via RT Web Interface - behavior ofspecifying Cc's

Pei Ku pku at autotradecenter.com
Thu Jan 13 22:33:14 EST 2005


I hacked Ticket_Overlay.pm to do the following and it seems to work:

Before the loop in which LoadOrCreateByEmail() is called, I added
a loop that calls LoadByEmail to check each Cc and AdminCc values; if
the value is not an existing email address in the Users table, I set
the value in @{$args{$type}} to '' so that when it gets to the LoadOrCreateEmail()
loop, those blanked out email addresses won't get created as RT users
and won't get added to the Watcher lists for the ticket.

If anyone sees something wrong with my hack pls let me know.

thanks!

Pei
 

 diff -C 10 Ticket_Overlay.pm ../../../lib/RT/Ticket_Overlay.pm
*** Ticket_Overlay.pm   Thu Jan 13 18:42:20 2005
--- ../../../lib/RT/Ticket_Overlay.pm   Thu Sep 23 22:21:43 2004
***************
*** 525,582 ****
      }
  
      #If we haven't been handed a valid owner, make it nobody.
      unless ( defined($Owner) && $Owner->Id ) {
          $Owner = new RT::User( $self->CurrentUser );
          $Owner->Load( $RT::Nobody->Id );
      }
  
      # }}}
  
- 
- # {{{
- # hack 
- #
- # Eliminate CCs and AdminCCs that are not existing
- # users in RT.
- #
-      foreach my $type ( "Cc", "AdminCc" ) {
-  
-        next unless ( defined $args{$type}  );
-  
-        # It appears CC and AdminCC are always a ref (
-        # even if it's empty or contains only one element).
-        # So bail out if the data structure is not a ref
-        # (lazy coding ;-)
-        #
-        next unless ( ref( $args{$type} ) ) ;
-  
-        for (my $i = 0; $i < scalar( @{$args{$type}} ) ; $i++) {
-            my $user = RT::User->new($RT::SystemUser);
-  
-            $user->LoadByEmail( ${$args{$type}}[$i] ) ;
-  
-          if ( ! $user->Id ) { 
-  
-              push( @non_fatal_errors,
-                  $self->loc("Not adding " . ${$args{$type}}[$i] 
-                     . " to Cc watcher list because it is not an existing RT user." ) ); 
-  
-            ${$args{$type}}[$i] = '' ; 
-  
-            }
-        } 
-      }
- # end of hack 
- # }}}
- 
- 
  # We attempt to load or create each of the people who might have a role for this ticket
  # _outside_ the transaction, so we don't get into ticket creation races
      foreach my $type ( "Cc", "AdminCc", "Requestor" ) {
          next unless ( defined $args{$type} );
          foreach my $watcher (
              ref( $args{$type} ) ? @{ $args{$type} } : ( $args{$type} ) )
          {
              my $user = RT::User->new($RT::SystemUser);
              $user->LoadOrCreateByEmail($watcher)
                if ( $watcher && $watcher !~ /^\d+$/ );
--- 525,544 ----



> -----Original Message-----
> From: rt-users-bounces at lists.bestpractical.com
> [mailto:rt-users-bounces at lists.bestpractical.com]On Behalf Of Pei Ku
> Sent: Thursday, January 13, 2005 1:49 PM
> To: Andy Harrison
> Cc: rt-users at lists.bestpractical.com
> Subject: RE: [rt-users] Create a new Ticket via RT Web Interface -
> behavior ofspecifying Cc's
> 
> 
> Hi Andy,
> 
> Thanks for the pointer.  I think you pointed me in the right 
> direction; however, I was not clear on one thing: when 
> someone who is not an existing user in RT, I still want RT to 
> create an account for that person (assuming I've granted the 
> proper proper privilege to the appropriate role; e.g., 
> CreateTicket priv to Everyone role).   In other words, I 
> still want RT to create a new RT user for the Requestor if 
> the requestor is not a RT user yet; when a RT user specified 
> CC's and AdminCC's, I don't want RT to automatically create 
> accounts for those email addresses that are in the CC/AdminCC 
> lists but are not existing RT users.
> 
> Anyway, based on the inspiration you provided, I think I've 
> found the right place to hack RT: lib/RT/Ticket_Overlay.pm:
> 
> # We attempt to load or create each of the people who might 
> have a role for this ticket
> # _outside_ the transaction, so we don't get into ticket 
> creation races
>     foreach my $type ( "Cc", "AdminCc", "Requestor" ) {
>         next unless ( defined $args{$type} );
>         foreach my $watcher (
>             ref( $args{$type} ) ? @{ $args{$type} } : ( 
> $args{$type} ) )
>         {
>             my $user = RT::User->new($RT::SystemUser);
>             $user->LoadOrCreateByEmail($watcher)
>               if ( $watcher && $watcher !~ /^\d+$/ );
>         }
>     }
> 
> 
> I think I just need to take out "Cc" and "AdminCC" from 
> outer-most "foreach" statement.  Sounds about right?  
> 
> thanks again.
> 
> Pei
> 
> 
> 
> > -----Original Message-----
> > From: Andy Harrison [mailto:aharrison at gmail.com]
> > Sent: Thursday, January 13, 2005 12:21 PM
> > To: Pei Ku
> > Cc: rt-users at lists.bestpractical.com
> > Subject: Re: [rt-users] Create a new Ticket via RT Web Interface -
> > behavior of specifying Cc's
> > 
> > 
> > > I want to change the behavior such that RT won't 
> > automatically create RT's accounts for Cc's that are not 
> > existing RT accounts.  How do I do that?
> > 
> > That takes place in the LoadOrCreateByEmail sub in 
> > rt3/lib/RT/User_Overlay.pm.
> > 
> > There's probably a better way, but you could probably replace the
> > whole unless ($self->Id) routine with something like:
> > 
> >          unless ($self->Id) {
> >              $RT::Logger->info("User creation ignored for 
> ".$email .":
> > " .$message);
> >          }
> > 
> > 
> > -- 
> > Andy Harrison
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
> 
> Be sure to check out the RT wiki at http://wiki.bestpractical.com
> 



More information about the rt-users mailing list