[Rt-commit] r4099 - in rt/branches/3.7-EXPERIMENTAL: . html/Search html/SelfService html/Ticket lib/RT/Interface

ruz at bestpractical.com ruz at bestpractical.com
Tue Nov 15 22:52:08 EST 2005


Author: ruz
Date: Tue Nov 15 22:52:07 2005
New Revision: 4099

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/html/Search/Bulk.html
   rt/branches/3.7-EXPERIMENTAL/html/SelfService/Display.html
   rt/branches/3.7-EXPERIMENTAL/html/Ticket/Display.html
   rt/branches/3.7-EXPERIMENTAL/html/Ticket/ModifyAll.html
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web.pm
Log:
 r1291 at cubic-pc:  cubic | 2005-11-16 06:55:12 +0300
  r1290 at cubic-pc:  cubic | 2005-11-15 04:40:50 +0300
  * SkipSignatureOnly argument in RT::Interface::Web::ProcessUpdateMessage
  * update code to use it everywhere
 


Modified: rt/branches/3.7-EXPERIMENTAL/html/Search/Bulk.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Search/Bulk.html	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Search/Bulk.html	Tue Nov 15 22:52:07 2005
@@ -233,20 +233,6 @@
     }
 }
 
-my $do_comment_reply = 0;
-
-# Prepare for ticket updates
-$ARGS{'UpdateContent'} =~ s/\r\n/\n/g;
-chomp( $ARGS{'UpdateContent'} );
-
-if (   $ARGS{'UpdateContent'}
-    && $ARGS{'UpdateContent'} ne ''
-    && $ARGS{'UpdateContent'} ne "-- \n"
-    . $session{'CurrentUser'}->UserObj->Signature )
-{
-    $do_comment_reply = 1;
-}
-
 #Iterate through each ticket we've been handed
 my @linkresults;
 my %queues;
@@ -268,13 +254,10 @@
     $ARGS{'id'} = $Ticket->id;
     $queues{ $Ticket->QueueObj->Id }++;
 
-    my @updateresults;
-    if ($do_comment_reply) {
-        push @updateresults, ProcessUpdateMessage(
+    my @updateresults, ProcessUpdateMessage(
             TicketObj => $Ticket,
             ARGSRef   => \%ARGS,
         );
-    }
 
     #Update the basics.
     my @basicresults =

Modified: rt/branches/3.7-EXPERIMENTAL/html/SelfService/Display.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/SelfService/Display.html	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/SelfService/Display.html	Tue Nov 15 22:52:07 2005
@@ -181,17 +181,10 @@
 
     # }}}
 
-    if (
-        $session{'Attachments'}
-        || (   $ARGS{'UpdateContent'} ne ''
-            && $ARGS{'UpdateContent'} ne "-- \n"
-            . $session{'CurrentUser'}->UserObj->Signature )
-      )
-    {
-        $ARGS{UpdateAttachments} = $session{'Attachments'};
-    }
+    # XXX: review attachment processing because all this had done in the different ways
+    # in the different places.
     push @results, ProcessUpdateMessage(
-        ARGSRef   => \%ARGS,
+        ARGSRef   => { %ARGS, UpdateAttachments => $session{'Attachments'} },
         TicketObj => $Ticket,
     );
 

Modified: rt/branches/3.7-EXPERIMENTAL/html/Ticket/Display.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Ticket/Display.html	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Ticket/Display.html	Tue Nov 15 22:52:07 2005
@@ -67,23 +67,21 @@
       ShowHeaders => $ARGS{'ShowHeaders'},
       Attachments => $attachments,
       AttachmentContent => $attachment_content
-      
-      &> 
+&> 
 
 
 <%ARGS>
 $id => undef
-$Create => undef
+$TicketObj => undef
 $ShowHeaders => 0
 $Collapsed => undef
-$TicketObj => undef
 </%ARGS>
 
 <%INIT>
 
 $m->comp('/Elements/Callback', _CallbackName => 'Initial', TicketObj => $TicketObj, ARGSRef => \%ARGS);
 
-my ($linkid, $message, $tid, @Actions, $Tickets);  
+my (@Actions, $Tickets);  
 
 unless ($id || $TicketObj) {
     Abort('No ticket specified');
@@ -91,57 +89,45 @@
 
 if ($ARGS{'id'} eq 'new') {
     # {{{ Create a new ticket
-    
-    my $Queue = new RT::Queue($session{'CurrentUser'});	
-    unless ($Queue->Load($ARGS{'Queue'})) {
-	Abort('Queue not found');
+
+    my $Queue = new RT::Queue( $session{'CurrentUser'} );
+    $Queue->Load($ARGS{'Queue'});
+    unless ( $Queue->id ) {
+        Abort('Queue not found');
     }
-    
-    unless ($Queue->CurrentUserHasRight('CreateTicket')) {
-	Abort('You have no permission to create tickets in that queue.');
+
+    unless ( $Queue->CurrentUserHasRight('CreateTicket') ) {
+        Abort('You have no permission to create tickets in that queue.');
+    }
+
+    ($TicketObj, @Actions) = CreateTicket(
+        Attachments => delete $session{'Attachments'},
+        %ARGS,
+    );
+    unless ( $TicketObj->CurrentUserHasRight('ShowTicket') ) {
+        Abort("No permission to view newly created ticket #".$TicketObj->id.".");
     }
-    ($TicketObj, @Actions) =
-	CreateTicket(Attachments => $session{'Attachments'}, %ARGS);
-    delete $session{'Attachments'};
-    unless ($TicketObj->CurrentUserHasRight('ShowTicket')) {
-	Abort("No permission to view newly created ticket #".$TicketObj->id.".");
-	}
     # }}}
 } else { 
-    if (!$TicketObj) {
-
-	$TicketObj = RT::Ticket->new($session{'CurrentUser'});
-
-	$TicketObj = LoadTicket($ARGS{'id'});
-	unless ($TicketObj->CurrentUserHasRight('ShowTicket')) {
-	    Abort("No permission to view ticket");
-	}
+    $TicketObj ||= LoadTicket($ARGS{'id'});
+    if ( defined $ARGS{'Action'} ) {
+        if ($ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/) {
+            my $action = $1;
+            my ($res, $msg) = $TicketObj->$action();
+            push(@Actions, $msg);
+        }
     }
 
-    if (defined $ARGS{'Action'}) {
-	if ($ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/) {
-	    my $action = $1;
-	    my ($res, $msg)=$TicketObj->$action();
-	    push(@Actions, $msg);
-	}
-    }
+    $ARGS{UpdateAttachments} = delete $session{'Attachments'};
+    push @Actions, ProcessUpdateMessage( ARGSRef => \%ARGS, TicketObj => $TicketObj );
+    push @Actions, ProcessTicketBasics(  ARGSRef => \%ARGS, TicketObj => $TicketObj );
+    push @Actions, ProcessTicketLinks(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
 
-    $ARGS{'UpdateContent'} =~ s/\r\n/\n/g if defined $ARGS{'UpdateContent'};
-    if ( $ARGS{'UpdateTimeWorked'} ||
-	 $session{'Attachments'} || 
-	 (   defined $ARGS{'UpdateContent'}
-             && $ARGS{'UpdateContent'} ne ''
-	     && $ARGS{'UpdateContent'} ne "-- \n"
-	     . $session{'CurrentUser'}->UserObj->Signature )) {
-	$ARGS{UpdateAttachments} = $session{'Attachments'};
-	push @Actions, ProcessUpdateMessage( ARGSRef   => \%ARGS, TicketObj => $TicketObj );
-	delete $session{'Attachments'};
+    # XXX: we shouldn't block actions here if user has no right to see the ticket,
+    # but we should allow him to see actions he has done
+    unless ($TicketObj->CurrentUserHasRight('ShowTicket')) {
+        Abort("No permission to view ticket");
     }
-    #Process status updates
-    my @BasicActions = ProcessTicketBasics(ARGSRef => \%ARGS, TicketObj=>$TicketObj);
-    my @results = ProcessTicketLinks( TicketObj => $TicketObj, ARGSRef => \%ARGS);
-
-    push (@Actions, @BasicActions, @results);
 }
 
 # This code does automatic redirection if any updates happen. 
@@ -161,7 +147,7 @@
 }
 
 $m->comp('/Elements/Callback', _CallbackName => 'BeforeDisplay',
-	 TicketObj => \$TicketObj, Tickets => \$Tickets, ARGSRef => \%ARGS);
+         TicketObj => \$TicketObj, Tickets => \$Tickets, ARGSRef => \%ARGS);
 
 
 my $attachments = $m->comp('Elements/FindAttachments', Ticket => $TicketObj, Tickets => $Tickets);

Modified: rt/branches/3.7-EXPERIMENTAL/html/Ticket/ModifyAll.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Ticket/ModifyAll.html	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Ticket/ModifyAll.html	Tue Nov 15 22:52:07 2005
@@ -165,17 +165,12 @@
            Body                => "",
            AttachmentFieldName => 'UpdateAttachment'
         );
-	delete $ARGS{'UpdateAttachment'};
-	$ARGS{'UpdateAttachments'}->{ $subject } = $attachment;
+        delete $ARGS{'UpdateAttachment'};
+        $ARGS{'UpdateAttachments'}->{ $subject } = $attachment;
     }
 
-    $ARGS{'UpdateContent'} =~ s/\r+\n/\n/g;
-
-    if ($ARGS{'UpdateAttachments'} || ( $ARGS{'UpdateContent'} && $ARGS{'UpdateContent'} ne  "-- \n" .
-				$session{'CurrentUser'}->UserObj->Signature)) {
-   	    push @results, ProcessUpdateMessage( TicketObj => $Ticket, ARGSRef=>\%ARGS );
-	}
-    @results = ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
+    push @results, ProcessUpdateMessage( TicketObj => $Ticket, ARGSRef=>\%ARGS );
+    push @results, ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
 }
 push @results, @wresults;
 push @results, @dresults;

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web.pm	Tue Nov 15 22:52:07 2005
@@ -433,20 +433,50 @@
 
 # {{{ sub ProcessUpdateMessage
 
+=head2 ProcessUpdateMessage
+
+Takes paramhash with fields ARGSRef, TicketObj and SkipSignatureOnly.
+
+Don't write message if it only contains current user's signature and
+SkipSignatureOnly argument is true. Function anyway adds attachments
+and updates time worked field even if skips message. The default value
+is true.
+
+=cut
+
 sub ProcessUpdateMessage {
 
     #TODO document what else this takes.
     my %args = (
         ARGSRef   => undef,
         TicketObj => undef,
+        SkipSignatureOnly => 1,
         @_
     );
+
     my @results;
 
     #Make the update content have no 'weird' newlines in it
     return () unless    $args{ARGSRef}->{'UpdateTimeWorked'}
-                     || $args{ARGSRef}->{'UpdateContent'}
-                     || $args{ARGSRef}->{'UpdateAttachments'};
+                     || $args{ARGSRef}->{'UpdateAttachments'}
+                     || $args{ARGSRef}->{'UpdateContent'};
+
+    $args{ARGSRef}->{'UpdateContent'} =~ s/\r+\n/\n/g if $args{ARGSRef}->{'UpdateContent'};
+
+    # skip updates if the content contains only user's signature
+    # and we don't update other fields
+    if( $args{'SkipSignatureOnly'} ) {
+        my $sig = $args{'TicketObj'}->CurrentUser->UserObj->Signature || '';
+        $sig =~ s/^\s*|\s*$//g;
+        if( $args{ARGSRef}->{'UpdateContent'} =~ /^\s*(--)?\s*\Q$sig\E\s*$/ ) {
+            return () unless $args{ARGSRef}->{'UpdateTimeWorked'} ||
+                             $args{ARGSRef}->{'UpdateAttachments'};
+
+            # we have to create transaction, but we don't create attachment
+            # XXX: this couldn't work as expected
+            $args{ARGSRef}->{'UpdateContent'} = '';
+        }
+    }
 
     if ( $args{ARGSRef}->{'UpdateSubject'} eq $args{'TicketObj'}->Subject ) {
         $args{ARGSRef}->{'UpdateSubject'} = undef;
@@ -476,11 +506,12 @@
         $old_txn = $args{TicketObj}->Transactions->First();
     }
 
-    if ( $old_txn->Message && $old_txn->Message->First ) {
-        my @in_reply_to = split(/\s+/m, $old_txn->Message->First->GetHeader('In-Reply-To') || '');  
-        my @references = split(/\s+/m, $old_txn->Message->First->GetHeader('References') || '' );  
-        my @msgid = split(/\s+/m,$old_txn->Message->First->GetHeader('Message-ID') || ''); 
-        my @rtmsgid = split(/\s+/m,$old_txn->Message->First->GetHeader('RT-Message-ID') || ''); 
+    if ( $old_txn->Message and my $msg = $old_txn->Message->First ) {
+        my @in_reply_to = split(/\s+/m, $msg->GetHeader('In-Reply-To') || '');  
+        my @references = split(/\s+/m, $msg->GetHeader('References') || '' );  
+        my @msgid = split(/\s+/m, $msg->GetHeader('Message-ID') || '');
+        #XXX: custom header should begin with X- otherwise is violation of the standard
+        my @rtmsgid = split(/\s+/m, $msg->GetHeader('RT-Message-ID') || ''); 
 
         $Message->head->replace( 'In-Reply-To', join(' ', @rtmsgid ? @rtmsgid : @msgid));
         $Message->head->replace( 'References', join(' ', @references, @msgid, @rtmsgid));


More information about the Rt-commit mailing list