X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FTicket_Overlay.pm;h=dad94375fcfb5458e2adbe59f91108708e823a88;hb=200171841941972b3305cf8be8ef367a1a363e93;hp=5960f0b63fbde98930261cad2d5c860d309b6365;hpb=9509e5bfb7f9331303153cac24d7bfecbe2ea9f1;p=freeside.git diff --git a/rt/lib/RT/Ticket_Overlay.pm b/rt/lib/RT/Ticket_Overlay.pm index 5960f0b63..dad94375f 100644 --- a/rt/lib/RT/Ticket_Overlay.pm +++ b/rt/lib/RT/Ticket_Overlay.pm @@ -716,6 +716,68 @@ sub Create { # }}} + # {{{ Deal with auto-customer association + + #unless we already have (a) customer(s)... + unless ( $self->Customers->Count ) { + + #first find any requestors with emails but *without* customer targets + my @NoCust_Requestors = + grep { $_->EmailAddress && ! $_->Customers->Count } + @{ $self->_Requestors->UserMembersObj->ItemsArrayRef }; + + for my $Requestor (@NoCust_Requestors) { + + #perhaps the stuff in here should be in a User method?? + my @Customers = + &RT::URI::freeside::email_search( email=>$Requestor->EmailAddress ); + + foreach my $custnum ( map $_->{'custnum'}, @Customers ) { + + ## false laziness w/RT/Interface/Web_Vendor.pm + my @link = ( 'Type' => 'MemberOf', + 'Target' => "freeside://freeside/cust_main/$custnum", + ); + + my( $val, $msg ) = $Requestor->_AddLink(@link); + #XXX should do something with $msg# push @non_fatal_errors, $msg; + + } + + } + + #find any requestors with customer targets + + my %cust_target = (); + + my @Requestors = + grep { $_->Customers->Count } + @{ $self->_Requestors->UserMembersObj->ItemsArrayRef }; + + foreach my $Requestor ( @Requestors ) { + foreach my $cust_link ( @{ $Requestor->Customers->ItemsArrayRef } ) { + $cust_target{ $cust_link->Target } = 1; + } + } + + #and then auto-associate this ticket with those customers + + foreach my $cust_target ( keys %cust_target ) { + + my @link = ( 'Type' => 'MemberOf', + #'Target' => "freeside://freeside/cust_main/$custnum", + 'Target' => $cust_target, + ); + + my( $val, $msg ) = $self->_AddLink(@link); + push @non_fatal_errors, $msg; + + } + + } + + # }}} + # {{{ Add all the custom fields foreach my $arg ( keys %args ) { @@ -1349,7 +1411,7 @@ sub AddWatcher { #If the watcher we're trying to add is for the current user if ( $self->CurrentUser->PrincipalId == ($args{'PrincipalId'} || 0) or lc( $self->CurrentUser->UserObj->EmailAddress ) - eq lc( RT::User::CanonicalizeEmailAddress(undef, $args{'Email'}) || '' ) ) + eq lc( RT::User->CanonicalizeEmailAddress( $args{'Email'} ) || '' ) ) { # If it's an AdminCc and they don't have # 'WatchAsAdminCc' or 'ModifyTicket', bail @@ -1749,6 +1811,25 @@ sub Requestors { # }}} +# {{{ sub _Requestors + +=head2 _Requestors + +Private non-ACLed variant of Reqeustors so that we can look them up for the +purposes of customer auto-association during create. + +=cut + +sub _Requestors { + my $self = shift; + + my $group = RT::Group->new($RT::SystemUser); + $group->LoadTicketRoleGroup(Type => 'Requestor', Ticket => $self->Id); + return ($group); +} + +# }}} + # {{{ sub Cc =head2 Cc @@ -2410,15 +2491,16 @@ sub _RecordNote { # The "NotifyOtherRecipients" scripAction will look for RT-Send-Cc: and RT-Send-Bcc: # headers - $args{'MIMEObj'}->head->add( 'RT-Send-Cc', RT::User::CanonicalizeEmailAddress( - undef, $args{'CcMessageTo'} - ) ) - if defined $args{'CcMessageTo'}; - $args{'MIMEObj'}->head->add( 'RT-Send-Bcc', - RT::User::CanonicalizeEmailAddress( - undef, $args{'BccMessageTo'} - ) ) - if defined $args{'BccMessageTo'}; + + foreach my $type (qw/Cc Bcc/) { + if ( defined $args{ $type . 'MessageTo' } ) { + + my $addresses = join ', ', ( + map { RT::User->CanonicalizeEmailAddress( $_->address ) } + Mail::Address->parse( $args{ $type . 'MessageTo' } ) ); + $args{'MIMEObj'}->head->add( 'RT-Send-' . $type, $addresses ); + } + } # If this is from an external source, we need to come up with its # internal Message-ID now, so all emails sent because of this @@ -2472,7 +2554,13 @@ sub _Links { unless ( $self->{"$field$type"} ) { $self->{"$field$type"} = new RT::Links( $self->CurrentUser ); - if ( $self->CurrentUserHasRight('ShowTicket') ) { + + #not sure what this ACL was supposed to do... but returning the + # bare (unlimited) RT::Links certainly seems wrong, it causes the + # $Ticket->Customers method during creation to return results for every + # ticket... + #if ( $self->CurrentUserHasRight('ShowTicket') ) { + # Maybe this ticket is a merged ticket my $Tickets = new RT::Tickets( $self->CurrentUser ); # at least to myself @@ -2489,7 +2577,7 @@ sub _Links { $self->{"$field$type"}->Limit( FIELD => 'Type', VALUE => $type ) if ($type); - } + #} } return ( $self->{"$field$type"} ); }