[Rt-commit] r7500 - in rtir/branches/2.3-EXPERIMENTAL: . html/RTIR html/RTIR/Elements lib/RT/IR

jesse at bestpractical.com jesse at bestpractical.com
Thu Apr 12 22:00:05 EDT 2007


Author: jesse
Date: Thu Apr 12 22:00:05 2007
New Revision: 7500

Added:
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Elements/ShowLock
Modified:
   rtir/branches/2.3-EXPERIMENTAL/   (props changed)
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Display.html
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Edit.html
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Elements/QueueTabs
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/NoAuth/webrtir.css
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Update.html
   rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Ticket.pm

Log:
 r54810 at pinglin:  jesse | 2007-04-12 21:59:49 -0400
 * First pass at locking


Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Display.html
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Display.html	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Display.html	Thu Apr 12 22:00:05 2007
@@ -30,8 +30,8 @@
     current_subtab => 'RTIR/Display.html?id='.$Ticket->id,
     Title => $Title &>
 
+<& /RTIR/Elements/ShowLock, Ticket => $Ticket &>
 <& /Elements/ListActions, actions => \@results &>
-
 <table border="0" cellpadding="0" cellspacing="2" width="100%">
 <tr>
 <td valign="top" width="50%">
@@ -247,15 +247,51 @@
 
     if ( $ARGS{'Action'} && $ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/ ) {
         my $action = $1;
-        my (undef, $msg) = $Ticket->$action();
+        my ($status, $msg) = $Ticket->$action();
         push @results, $msg;
+        # If they succeeded in taking the ticket, they should also get a lock
+        if ($status && $action =~  /^(?:Take|Steal)$/) { $ARGS{'Lock'} = 'add'; }
     }
 
+
     if ( $ARGS{'TakeOrStealFirst'} and $Ticket->Owner != $Ticket->CurrentUser->Id) {
         my ($status, $msg) = $Ticket->SetOwner($Ticket->CurrentUser->Id, 'Force');
         push @results, $msg if $msg;
+
+        # If they succeeded in taking the ticket, they should also get a lock
+        if ($status) { $ARGS{'Lock'} = 'add'; }
     }
 
+    if ( $ARGS{'Lock'} ) {
+
+        if ( $ARGS{'Lock'} eq 'add' ) {
+            if ( $Ticket->RT::IR::Ticket::Lock() ) {
+                push @results, loc('You now have a lock on this ticket');
+            } else {
+                push @results, loc('Your attempt to lock this ticket failed');
+
+            }
+        } elsif ( $ARGS{'Lock'} eq 'remove' ) {
+            my $lock = $Ticket->RT::IR::Ticket::Locked();
+            if ( !$lock ) {
+                push @results, loc('This ticket was not locked');
+
+                } elsif ( $lock->Content->{'User'} == $session{'CurrentUser'}->id ) {
+                $Ticket->RT::IR::Ticket::Unlock();
+                push @results, loc('You have unlocked this ticket');
+            } else {
+                push @results,
+                    loc("You can't unlock tickets that you did not lock");
+
+            }
+
+        } elsif ( $ARGS{'Lock'} eq 'break' ) {
+            $Ticket->RT::IR::Ticket::BreakLock();
+            push @results, loc('You have broken the lock on this ticket');
+        }
+    }
+
+
     $ARGS{UpdateAttachments} = delete $session{'Attachments'};
     push @results, ProcessUpdateMessage( TicketObj => $Ticket, ARGSRef => \%ARGS );
     push @results, ProcessTicketBasics(  TicketObj => $Ticket, ARGSRef => \%ARGS );

Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Edit.html
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Edit.html	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Edit.html	Thu Apr 12 22:00:05 2007
@@ -29,6 +29,7 @@
     current_subtab => "RTIR/Edit.html?id=".$Ticket->Id, 
     Title => $Title &>
 
+<& /RTIR/Elements/ShowLock, Ticket => $Ticket &>
 <& /Elements/ListActions, actions => \@results &>
 
 % if (!$Ticket->CurrentUserHasRight('ModifyTicket')) {

Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Elements/QueueTabs
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Elements/QueueTabs	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Elements/QueueTabs	Thu Apr 12 22:00:05 2007
@@ -99,6 +99,9 @@
     my %can = map { $_, $Ticket->CurrentUserHasRight($_) }
         qw(ModifyTicket ReplyToTicket OwnTicket CommentOnTicket);
 
+
+    
+
     my $ticket_page_tabs = {
         _A => {
             title => loc('Display'),
@@ -274,6 +277,10 @@
             path  => "RTIR/Update.html?Action=Comment&id=$id"
         };
     }
+
+
+
+
 } else {
     $mytab = $current_tab;
 }
@@ -335,6 +342,30 @@
     }
 }
 
+if ($Ticket) {
+if (my $Lock = $Ticket->RT::IR::Ticket::Locked()) {
+    if ($Lock->Content->{'User'} == $session{'CurrentUser'}->id) {
+    $actions->{'Lock'} = { 
+                    path  => "Ticket/Display.html?Lock=remove&id=$id",
+                    title => loc('Unlock') 
+                    };
+    } else {
+    $actions->{'Lock'} = { 
+                    path  => "Ticket/Display.html?Lock=break&id=$id",
+                    title => loc('Break lock') 
+                    };
+
+    }
+} else {
+    $actions->{'Lock'} = { 
+                    path  => "Ticket/Display.html?Lock=add&id=$id",
+                    title => loc('Lock') 
+                    };
+
+
+}
+}
+
 </%INIT>
 <%ARGS>
 $Title          => ''

Added: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Elements/ShowLock
==============================================================================
--- (empty file)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Elements/ShowLock	Thu Apr 12 22:00:05 2007
@@ -0,0 +1,23 @@
+% if ($u->id == $session{'CurrentUser'}->id) {
+<div class="locked-by-you">
+<&|/l, $ago &>You have had this ticket locked for [_1]</&>.
+
+[<a href="<%$RT::WebPath%>/Ticket/Display.html?id=<%$Ticket->id%>&Lock=remove"><&|/l&>Unlock</&></a>]
+
+</div>
+% } else {
+<div class="locked">
+<&|/l, $u->Name, $ago &>This ticket has been locked by [_1] for [_2]</&>.
+</div>
+%}
+<%init>
+return unless (my $Lock = $Ticket->RT::IR::Ticket::Locked());
+my $u = RT::User->new($session{'CurrentUser'});
+$u->Load($Lock->Content->{'User'});
+
+my $date = RT::Date->new($session{'CurrentUser'});
+my $ago = $date->DurationAsString(time() - $Lock->Content->{'Timestamp'});
+</%init>
+<%args>
+$Ticket
+</%args>

Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/NoAuth/webrtir.css
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/NoAuth/webrtir.css	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/NoAuth/webrtir.css	Thu Apr 12 22:00:05 2007
@@ -22,6 +22,26 @@
   content:"";
  }
 
+
+div.locked-by-you {
+    
+    width: 80%;
+    align: center;
+    border: 2px solid green;
+    padding: 1em;
+    margin: 1em;
+}    
+
+div.lock {
+    
+    width: 80%;
+    align: center;
+    border: 2px solid red;
+    padding: 1em;
+    margin: 1em;
+    
+}
+
 % $m->abort;
 <%INIT>
 $r->content_type('text/css');

Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Update.html
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Update.html	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Update.html	Thu Apr 12 22:00:05 2007
@@ -28,6 +28,7 @@
     current_subtab => "RTIR/Edit.html?id=$id",
     Title => $title &>
 
+<& /RTIR/Elements/ShowLock, Ticket => $Ticket &>
 <form action="Update.html" name="TicketUpdate" 
 	method="post" enctype="multipart/form-data">
 <input type="hidden" name="QuoteTransaction" value="<% $ARGS{'QuoteTransaction'} || '' %>" />

Modified: rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Ticket.pm
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Ticket.pm	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/lib/RT/IR/Ticket.pm	Thu Apr 12 22:00:05 2007
@@ -75,7 +75,18 @@
 
 sub Unlock {
     my $ticket = shift;
+
+    my $lock = $ticket->RT::IR::Ticket::Locked();
+     return undef unless $lock;
+     return undef unless $lock->Content->{User} ==  $ticket->CurrentUser->id;
     $ticket->DeleteAttribute('RTIR_Lock');
 }
 
+
+sub BreakLock {
+    my $ticket = shift;
+    my $lock = $ticket->RT::IR::Ticket::Locked();
+     return undef unless $lock;
+    $ticket->DeleteAttribute('RTIR_Lock');
+}
 1;


More information about the Rt-commit mailing list