[Rt-commit] r4478 - in rtir/branches/1.9-EXPERIMENTAL: html/RTIR/Incident

ruz at bestpractical.com ruz at bestpractical.com
Fri Feb 3 18:40:13 EST 2006


Author: ruz
Date: Fri Feb  3 18:40:04 2006
New Revision: 4478

Modified:
   rtir/branches/1.9-EXPERIMENTAL/   (props changed)
   rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Incident/Display.html

Log:
 r616 at cubic-pc:  cubic | 2006-01-27 17:37:29 +0300
 * jump generic Display.html if it's not incident
 * do update ticket even if we have no rights to see results
 * changes in checkbox handling broke linking, fix it
 * allow linking IRs to mutiple incidents


Modified: rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Incident/Display.html
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Incident/Display.html	(original)
+++ rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Incident/Display.html	Fri Feb  3 18:40:04 2006
@@ -22,30 +22,25 @@
 %# 
 %# 
 %# END LICENSE BLOCK
-<& /RTIR/Elements/Header, Title => loc("Incident #[_1]: [_2]", $Ticket->Id, $Ticket->Subject) &>
+<& /RTIR/Elements/Header, Title => loc("Incident #[_1]: [_2]", $id, $TicketObj->Subject) &>
 <& /RTIR/Incident/Elements/Tabs, 
-    Ticket => $Ticket, 
-    current_tab => 'RTIR/Display.html?id='.$Ticket->id,
-    current_subtab => 'RTIR/Display.html?id='.$Ticket->id,
-    Title => loc("Incident #[_1]: [_2]", $Ticket->Id, $Ticket->Subject) &>
+    Ticket => $TicketObj, 
+    current_tab => 'RTIR/Display.html?id='.$id,
+    current_subtab => 'RTIR/Display.html?id='.$id,
+    Title => loc("Incident #[_1]: [_2]", $id, $TicketObj->Subject) &>
 
 <& /Elements/ListActions, actions => \@results &>
 
-% if ($id != 'new' && $Ticket->QueueObj->Name ne "Incidents") {
-<&|/l&>This ticket isn't an Incident.</&>
-%  $m->abort();
-%}
-
 <table border="0" cellpadding="0" cellspacing="2" width="100%"><tr><td valign="top" width="50%">
 
-<& /Widgets/TitleBoxStart, title => loc('Incident #[_1]', $Ticket->Id), 
-        title_href => RT->Config->Get('WebPath') ."/RTIR/Edit.html?id=".$Ticket->Id, 
+<& /Widgets/TitleBoxStart, title => loc('Incident #[_1]', $id), 
+        title_href => RT->Config->Get('WebPath') ."/RTIR/Edit.html?id=".$id, 
         title_class=> 'inverse' &>
 
 <table>
   <tr>
     <td class="label"><&|/l&>Owner</&>:</td>
-    <td class="value"><%$Ticket->OwnerObj->Name%></td>
+    <td class="value"><%$TicketObj->OwnerObj->Name%></td>
   </tr>
   <tr>
     <td class="label">
@@ -54,25 +49,25 @@
     <td class="value">
       <& /RTIR/Elements/ShowRTIRField, 
         Name => 'State', 
-        Ticket => $Ticket &>
+        Ticket => $TicketObj &>
     </td>
   </tr>
   <tr>
     <td class="label"><&|/l&>Subject</&>:</td>
-    <td class="value"><%$Ticket->Subject %></td>
+    <td class="value"><%$TicketObj->Subject %></td>
   </tr>
   <tr>
     <td class="label"><&|/l&>Description</&>:</td>
     <td class="value">
       <& /RTIR/Elements/ShowRTIRField, 
-         Ticket => $Ticket, 
+         Ticket => $TicketObj, 
          Name => 'Description',
          Cols => 60 &>
     </td>
   </tr>
   <tr>
     <td class="label"><&|/l&>Priority</&>:</td>
-    <td class="value"><%$Ticket->Priority %></td>
+    <td class="value"><%$TicketObj->Priority %></td>
   </tr>
   <tr>
     <td class="label"><&|/l&>Time Worked</&>:</td>
@@ -82,7 +77,7 @@
     <td class="label"><&|/l&>Constituency</&>:</td>
     <td class="value">
       <& /RTIR/Elements/ShowRTIRField, 
-         Ticket => $Ticket, 
+         Ticket => $TicketObj, 
          Name => 'Constituency' &>
     </td>
   </tr>
@@ -90,7 +85,7 @@
     <td class="label"><&|/l&>Function</&>:</td>
     <td class="value">
       <& /RTIR/Elements/ShowRTIRField, 
-         Ticket => $Ticket, 
+         Ticket => $TicketObj, 
          Name => 'Function' &>
     </td>
   </tr>
@@ -98,7 +93,7 @@
     <td class="label"><&|/l&>Classification</&>:</td>
     <td class="value">
       <& /RTIR/Elements/ShowRTIRField, 
-         Ticket => $Ticket, 
+         Ticket => $TicketObj, 
          Name => 'Classification' &>
     </td>
   </tr>
@@ -110,66 +105,66 @@
 
 <& /Widgets/TitleBoxStart,
     title => loc('Incident Reports'),
-    title_href => RT->Config->Get('WebPath') ."/RTIR/Incident/ShowChildren.html?Queue=Incident%20Reports&id=".$Ticket->Id,
+    title_href => RT->Config->Get('WebPath') ."/RTIR/Incident/ShowChildren.html?Queue=Incident%20Reports&id=".$id,
     titleright => '',
     title_class=> 'inverse', color=> "#336633",
 &>
 
-% if ($Ticket->CurrentUserHasRight('ModifyTicket')) {
+% if ($TicketObj->CurrentUserHasRight('ModifyTicket')) {
     <table width="100%"><tr><td align="right"><font size="-1">
-        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Create.html?Incident=<%$Ticket->Id%>&Queue=Incident%20Reports"><%loc('New')%></a>
-        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Incident/LinkChildren.html?id=<%$Ticket->Id%>&Queue=Incident%20Reports"><%loc("Link")%></a> |
+        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Create.html?Incident=<%$id%>&Queue=Incident%20Reports"><%loc('New')%></a>
+        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Incident/LinkChildren.html?id=<%$id%>&Queue=Incident%20Reports"><%loc("Link")%></a> |
     </font></td></tr></table>
 % }
 
     <& /RTIR/Elements/ShowChildren, 
-            Ticket    => $Ticket, 
+            Ticket    => $TicketObj, 
             Queue     => 'Incident Reports',
             Rows      => 8,
-            FullList  => RT->Config->Get('WebPath')."/RTIR/Incident/ShowChildren.html?Queue=Incident%20Reports&id=".$Ticket->id,
+            FullList  => RT->Config->Get('WebPath')."/RTIR/Incident/ShowChildren.html?Queue=Incident%20Reports&id=".$id,
     &>
 <& /Widgets/TitleBoxEnd &>
 
 </td></tr><tr><td valign="top" width="50%">
 
 <& /Widgets/TitleBoxStart, title => loc('Investigations'), 
-    title_href => RT->Config->Get('WebPath') ."/RTIR/Incident/ShowChildren.html?Queue=Investigations&id=".$Ticket->Id, 
+    title_href => RT->Config->Get('WebPath') ."/RTIR/Incident/ShowChildren.html?Queue=Investigations&id=".$id, 
     title_class=> 'inverse',  
     titleright => '', color=> "#336633" &>
 
-% if ($Ticket->CurrentUserHasRight('ModifyTicket')) {
+% if ($TicketObj->CurrentUserHasRight('ModifyTicket')) {
     <table width="100%"><tr><td align="right"><font size="-1">
-        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Create.html?Incident=<%$Ticket->Id%>&Queue=Investigations"><%loc('Launch')%></a> 
-        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Incident/LinkChildren.html?id=<%$Ticket->Id%>&Queue=Investigations"><%loc("Link")%></a> |
+        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Create.html?Incident=<%$id%>&Queue=Investigations"><%loc('Launch')%></a> 
+        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Incident/LinkChildren.html?id=<%$id%>&Queue=Investigations"><%loc("Link")%></a> |
     </font></td></tr></table>
 % }
 
 <& /RTIR/Elements/ShowChildren,
-    Ticket => $Ticket, 
+    Ticket => $TicketObj, 
     Queue => 'Investigations',
     Rows => 8,
-    FullList => RT->Config->Get('WebPath')."/RTIR/Incident/ShowChildren.html?Queue=Investigations&id=".$Ticket->id,
+    FullList => RT->Config->Get('WebPath')."/RTIR/Incident/ShowChildren.html?Queue=Investigations&id=".$id,
 &>
 
 </td><td valign="top" width="50%">
 
 <& /Widgets/TitleBoxStart, title => loc('Blocks'), 
-    title_href => RT->Config->Get('WebPath') ."/RTIR/Incident/ShowChildren.html?Queue=Blocks&id=".$Ticket->Id, 
+    title_href => RT->Config->Get('WebPath') ."/RTIR/Incident/ShowChildren.html?Queue=Blocks&id=".$id, 
     title_class=> 'inverse',  
     titleright => '', color=> "#336633" &>
 
-% if ($Ticket->CurrentUserHasRight('ModifyTicket')) {
+% if ($TicketObj->CurrentUserHasRight('ModifyTicket')) {
     <table width="100%"><tr><td align="right"><font size="-1">
-        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Create.html?Incident=<%$Ticket->Id%>&Queue=Blocks"><%loc('New')%></a> 
-        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Incident/LinkChildren.html?id=<%$Ticket->Id%>&Queue=Blocks>"><%loc("Link")%></a> |
+        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Create.html?Incident=<%$id%>&Queue=Blocks"><%loc('New')%></a> 
+        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Incident/LinkChildren.html?id=<%$id%>&Queue=Blocks>"><%loc("Link")%></a> |
     </font></td></tr></table>
 % }
 
 <& /RTIR/Elements/ShowChildren, 
-    Ticket   => $Ticket, 
+    Ticket   => $TicketObj, 
     Queue    => 'Blocks',
     Rows     => 8,
-    FullList => RT->Config->Get('WebPath')."/RTIR/Incident/ShowChildren.html?Queue=Blocks&id=".$Ticket->id,
+    FullList => RT->Config->Get('WebPath')."/RTIR/Incident/ShowChildren.html?Queue=Blocks&id=".$id,
 &>
 
 <& /Widgets/TitleBoxEnd &>
@@ -177,21 +172,21 @@
 </td></tr><tr><td colspan="2">
 
 <& /Widgets/TitleBoxStart, title => loc("Dates"),
-    title_href => RT->Config->Get('WebPath') ."/RTIR/Edit.html?id=".$Ticket->Id, 
+    title_href => RT->Config->Get('WebPath') ."/RTIR/Edit.html?id=".$id, 
     title_class=> 'inverse',  
     color => "#663366" &>
-<& /RTIR/Elements/ShowDates, Ticket => $Ticket &>
+<& /RTIR/Elements/ShowDates, Ticket => $TicketObj &>
 <& /Widgets/TitleBoxEnd &>
 
 <br />
 
-<& /Ticket/Elements/ShowAttachments, Ticket => $Ticket, Attachments => $attachments &>
-<& /Ticket/Elements/ShowRequestor, Ticket => $Ticket, DisplayPath => "/RTIR/Display.html" &>
+<& /Ticket/Elements/ShowAttachments, Ticket => $TicketObj, Attachments => $attachments &>
+<& /Ticket/Elements/ShowRequestor, Ticket => $TicketObj, DisplayPath => "/RTIR/Display.html" &>
 
 </td></tr></table>
 
 <& /Ticket/Elements/ShowHistory , 
-    Ticket => $Ticket, 
+    Ticket => $TicketObj, 
     Collapsed => $ARGS{'Collapsed'}, 
     ShowHeaders => $ARGS{'ShowHeaders'},
     UpdatePath => RT->Config->Get('WebPath') ."RTIR/Update.html",
@@ -199,134 +194,144 @@
 
   
 <%INIT>
-my ($Ticket, $ChildObj);
-$Ticket = new RT::Ticket( $session{'CurrentUser'} );
-$ChildObj = LoadTicket( $Child ) if $Child;
-
-
 if ($SelectedTicket) {
     $id = $SelectedTicket;
     $ARGS{'Status'} = "open";
 }
 Abort('No incident specified') unless $id;
 
+my $deleted_links = 0;
 my $DoLinks = sub {
-    my $Ticket = shift;
+    my $TicketObj = shift;
     my $Target = shift;
 
-    my @results;
-    my ($Type) = $m->comp( "/RTIR/Elements/Type", TicketObj => $Ticket );
-    $ARGS{ $Ticket->Id .'-MemberOf' } = $Target->Id;
+    my %args = ();
 
-    # Blocks can have multiple incidents
-    my $unlinked;
-    if ( $Type ne 'Block' ) {
-        my $query = "Queue = 'Incidents' AND HasMember = " . $Ticket->Id;
+    # Blocks or Incedent Reports can have multiple incidents
+    my ($Type) = $m->comp( "/RTIR/Elements/Type", TicketObj => $TicketObj );
+    unless( $Type eq 'Block' || $Type eq 'Report' ) {
+        my $query = "Queue = 'Incidents' AND HasMember = ". $TicketObj->Id ." AND id != ". $Target->id;
         my $incidents = new RT::Tickets( $session{'CurrentUser'} );
         $incidents->FromSQL( $query );
-        while ( my $member = $incidents->Next ) {
-            $RT::Logger->debug ("Deleting: ".$member->Id."\n");
-            # XXX: this code looks wrong absolutly.
-            $ARGS{'DeleteLink--MemberOf-'. $member->Id} = '';
-            $unlinked->{ $member->Id } = $member;
+        while ( my $incident = $incidents->Next ) {
+            $deleted_links = 1;
+            $args{'DeleteLink-'. $TicketObj->id .'-MemberOf-'. $incident->id } = '';
         }
     }
 
-    # If we don't own the thing we're linking to, change the owner
-    if ( $Ticket->Owner != $session{'CurrentUser'}->id ) {
+    my @results;
+    # If we own one end than take or steal other end of the link
+    if ( $TicketObj->Owner != $Target->Owner && (
+         $TicketObj->Owner == $session{'CurrentUser'}->id ||
+         $Target->Owner == $session{'CurrentUser'}->id ) )
+    {
+        my $obj;
+        $obj = $TicketObj unless $TicketObj->Owner == $session{'CurrentUser'}->id;
+        $obj = $TargetObj unless $TargetObj->Owner == $session{'CurrentUser'}->id;
         my $action = 'Steal';
-        if ( $Ticket->Owner == $RT::Nobody->id ) {
-            $action = 'Take';
-        }
-        my ($res, $msg) = $Ticket->$action();
+        $action = 'Take' if $obj->Owner == $RT::Nobody->id;
+        my ($res, $msg) = $obj->$action();
         push @results, $msg;
     }
 
-    push @results, ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
+    $args{ $TicketObj->Id .'-MemberOf' } = $Target->Id;
+    push @results, ProcessTicketLinks( TicketObj => $TicketObj, ARGSRef => \%args );
 
-    return map { loc("Ticket [_1]: [_2]", $Ticket->Id, $_) } @results;
+    return map { loc("Ticket [_1]: [_2]", $TicketObj->Id, $_) } @results;
 };
 
+my $TicketObj;
+my $new_ticket = 0;
 if ( $id eq 'new' ) {
-    my $Queue = new RT::Queue($session{'CurrentUser'});
-    $Queue->Load( $ARGS{'Queue'} ) || Abort(loc("Queue could not be loaded."));
-
-    unless ( $Queue->CurrentUserHasRight('CreateTicket') ) {
-        Abort('You have no permission to create tickets in that queue.');
-    }
-    ($Ticket, @results) =
-        CreateTicket( Attachments => $session{'Attachments'}, %ARGS );
-    delete $session{'Attachments'};
-
-    unless ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
-        Abort("No permission to view newly created ticket #".$Ticket->id.".");
+    my $QueueObj = RT::Queue->new( $session{'CurrentUser'} );
+    $QueueObj->Load( $Queue ) || Abort(loc("Couldn't load queue."));
+    unless( $QueueObj->Name eq 'Incidents' ) {
+        $m->comp('/RTIR/Display.html', %ARGS );
+        return;
     }
 
-    $ARGS{'id'} = $id = $Ticket->Id;
-
-    push @results, $DoLinks->( $ChildObj, $Ticket ) if $ChildObj;
-} else { 
-    $Ticket = LoadTicket( $id );
-    $ARGS{'id'} = $id = $Ticket->Id;
+    ($TicketObj, @results) = CreateTicket( %ARGS, Attachments => delete $session{'Attachments'} );
+    my $new_ticket = 1;
+} else {
+    $TicketObj = LoadTicket( $id );
+}
 
-    my $oldstate = $Ticket->FirstCustomFieldValue('_RTIR_State');
+unless( $TicketObj->QueueObj->Name eq 'Incidents' ) {
+    $m->comp('/RTIR/Display.html', %ARGS );
+    return;
+}
+$ARGS{'id'} = $id = $TicketObj->Id;
 
-    push @results, $DoLinks->( $ChildObj, $Ticket ) if $ChildObj;
+if( 1 ) {
+    my $oldstate = $TicketObj->FirstCustomFieldValue('_RTIR_State');
 
-    if ( $ARGS{'Action'} && $ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/ ) {
-        my $action = $1;
-        my ($res, $msg) = $Ticket->$action();
+    if ( $ARGS{'Action'} && $ARGS{'Action'} =~ /^(?:Steal|Kill|Take|SetTold)$/ )
+    {
+        my ($res, $msg) = $TicketObj->$1();
         push @results, $msg;
     }
 
-    # XXX: check usage of this option
-    if ( $ARGS{'BulkLink'} ) {
-        #Iterate through each ticket we've been handed
-        while ( my $t = $session{'tickets'}->Next ) {
-            next unless $ARGS{ "UpdateTicket". $t->Id };
-            push @results, $DoLinks->( $t, $Ticket );
+    unless( $new_ticket ) {
+        push @results, ProcessTicketBasics( ARGSRef => \%ARGS, TicketObj=>$TicketObj );
+    }
+
+    if ( $ARGS{'BulkLink'} || $Child ) {
+        my @link;
+        push @link, @SelectedTickets if $ARGS{'BulkLink'};
+        push @link, $Child if $Child;
+        foreach my $id ( grep $_, @link ) {
+            my $child = RT::Ticket->new( $session{'CurrentUser'} );
+            $child->Load($id);
+            unless( $child->id ) {
+                push @results, loc("Couldn't load ticket #[_1] for linking.", $id);
+                next;
+            }
+            push @results, $DoLinks->( $child, $TicketObj );
         }
     }
 
-    $ARGS{UpdateAttachments} = delete $session{'Attachments'};
-    push @results, ProcessUpdateMessage( ARGSRef => \%ARGS, TicketObj => $Ticket );
-    push @results, ProcessTicketBasics( ARGSRef => \%ARGS, TicketObj=>$Ticket );
+    unless( $new_ticket ) {
+        $ARGS{UpdateAttachments} = delete $session{'Attachments'};
+        push @results, ProcessUpdateMessage( ARGSRef => \%ARGS, TicketObj => $TicketObj );
+    }
 
-    my $newstate = $Ticket->FirstCustomFieldValue('_RTIR_State');
+    my $newstate = $TicketObj->FirstCustomFieldValue('_RTIR_State');
     if ($newstate ne $oldstate) {
-        push @results, loc("State changed from [_1] to [_2]", $oldstate, $newstate);
+        push @results, loc("State changed from [_1] to [_2]", $oldstate, $newstate );
     }
+}
 
-    # XXX: need the way to show @results when aborting
-    unless ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
-        Abort("No permission to view ticket");
-    }
+# XXX: need the way to show @results when aborting
+unless ( $TicketObj->CurrentUserHasRight('ShowTicket') ) {
+    Abort("No permission to view ticket #$id.");
 }
 
-my $TimeWorked = $Ticket->TimeWorked;
-if ( $Ticket->TimeLeft > 0 ) {
-    $TimeWorked .= '/'. $Ticket->TimeLeft;
+my $TimeWorked = $TicketObj->TimeWorked;
+if ( $TicketObj->TimeLeft > 0 ) {
+    $TimeWorked .= '/'. $TicketObj->TimeLeft;
 }
 
 # If we deleted any links, check if what we deleted from still has children
-if ( grep $_ =~ /^DeleteLink-.*-MemberOf-.*$/, keys %ARGS ) {
+if ( $deleted_links ) {
     my $children = new RT::Tickets( $session{'CurrentUser'} );
     $children->LimitQueue( VALUE => 'Incident Reports' );
     $children->LimitQueue( VALUE => 'Investigations' );
     $children->LimitQueue( VALUE => 'Blocks' );
     $children->LimitMemberOf( $id );
-    if ($children->Count == 0) {
+    unless ( $children->Count ) {
         push @results, loc("WARNING: Incident [_1] has no children.", $id);
     }
 }
 
-my $attachments = $m->comp('/Ticket/Elements/FindAttachments', Ticket => $Ticket);
+my $attachments = $m->comp('/Ticket/Elements/FindAttachments', Ticket => $TicketObj);
 
 </%INIT>
 
 <%ARGS>
+ at results => ()
 $id => undef
-$SelectedTicket => undef
+$Queue => 'Incidents'
 $Child => undef
- at results => ()
+$SelectedTicket => undef
+ at SelectedTickets => ()
 </%ARGS>


More information about the Rt-commit mailing list