[Rt-commit] r8281 - in rt/branches/3.7-EXPERIMENTAL-TUNIS: . html/Ticket lib/RT

thayes at bestpractical.com thayes at bestpractical.com
Wed Jul 25 12:23:42 EDT 2007


Author: thayes
Date: Wed Jul 25 12:23:41 2007
New Revision: 8281

Added:
   rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Elements/ShowLock   (contents, props changed)
Modified:
   rt/branches/3.7-EXPERIMENTAL-TUNIS/   (props changed)
   rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Ticket/Display.html
   rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Ticket/Update.html
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm

Log:
 r8404 at toth:  toth | 2007-07-25 12:22:45 -0400
 * Added locking to RT
 


Added: rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Elements/ShowLock
==============================================================================
--- (empty file)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Elements/ShowLock	Wed Jul 25 12:23:41 2007
@@ -0,0 +1,34 @@
+% if ($u->id == $session{'CurrentUser'}->id) {
+<div class="locked-by-you">
+% if(defined $duration) {
+	<&|/l, $ago &>You had this ticket locked for [_1]. It is now unlocked.</&>.
+% } else {
+	<&|/l, $ago &>You have had this ticket locked for [_1]</&>.
+% 		unless($ARGS{'noUnlock'}) {
+			[<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::Ticket::Locked());
+my $u = RT::User->new($session{'CurrentUser'});
+$u->Load($Lock->Content->{'User'});
+
+my $date = RT::Date->new($session{'CurrentUser'});
+my $ago;
+if(defined $duration) {
+	$ago = $date->DurationAsString($duration);
+} else {
+	$ago = $date->DurationAsString(time() - $Lock->Content->{'Timestamp'});
+}
+</%init>
+<%args>
+$Ticket
+$duration => undef
+</%args>

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Ticket/Display.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Ticket/Display.html	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Ticket/Display.html	Wed Jul 25 12:23:41 2007
@@ -52,6 +52,9 @@
     current_tab => 'Ticket/Display.html?id='.$TicketObj->id,
     Title => loc("#[_1]: [_2]", $TicketObj->Id, $TicketObj->Subject) &>
 
+% $duration ||= $ARGS{'duration'};
+<& /Elements/ShowLock, Ticket => $TicketObj, duration => $duration &>
+
 <& /Elements/ListActions, actions => \@Actions &>
 <& Elements/ShowUpdateStatus, Ticket => $TicketObj &>
 
@@ -88,6 +91,7 @@
 $m->callback( TicketObj => $TicketObj, ARGSRef => \%ARGS, CallbackName => 'Initial' );
 
 my (@Actions, $Tickets);  
+my $duration;
 
 unless ($id || $TicketObj) {
     Abort('No ticket specified');
@@ -123,10 +127,51 @@
     if ( defined $ARGS{'Action'} ) {
         if ($ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/) {
             my $action = $1;
-            my ($res, $msg) = $TicketObj->$action();
-            push(@Actions, $msg);
+            my $lock = $TicketObj->RT::Ticket::Locked();
+            if($lock && $lock->Content->{'User'} != $session{'CurrentUser'}->id)
+            {
+            	my $u = RT::User->new($session{'CurrentUser'});
+				$u->Load($lock->Content->{'User'});
+            	push @Actions, "Cannot $action: Ticket locked by " . $u->Name . ' and cannot be modified';
+            }
+            elsif(!$lock)
+            {
+            	$TicketObj->RT::Ticket::Lock();
+				my ($res, $msg) = $TicketObj->$action();
+				push(@Actions, $msg);
+			}
         }
     }
+    
+    if ( defined $ARGS{'Lock'} ) {
+        if ( $ARGS{'Lock'} eq 'add' ) {
+            if ( $TicketObj->RT::Ticket::Lock() ) {
+                push @Actions, loc('You now have a lock on this ticket');
+            } else {
+                push @Actions, loc('Your attempt to lock this ticket failed');
+
+            }
+        } elsif ( $ARGS{'Lock'} eq 'remove' ) {
+            my $lock = $TicketObj->RT::Ticket::Locked();
+            if ( !$lock ) {
+                push @Actions, loc('This ticket was not locked');
+
+			} elsif ( $lock->Content->{'User'} == $session{'CurrentUser'}->id ) {
+				$duration = time() - $lock->Content->{'Timestamp'};
+				my $date = RT::Date->new($session{'CurrentUser'});
+				$duration = $date->DurationAsString($duration);
+				$TicketObj->RT::Ticket::Unlock();
+				push @Actions, loc('You have unlocked this ticket (locked for ' . $duration . ')');
+			} else {
+				push @Actions,
+					loc("You can't unlock tickets that you did not lock");
+			}
+
+		} elsif ( $ARGS{'Lock'} eq 'break' ) {
+			$TicketObj->RT::IR::Ticket::BreakLock();
+			push @Actions, loc('You have broken the lock on this ticket');
+		}
+    }
 
     $ARGS{'UpdateContent'} =~ s/\r\n/\n/g if defined $ARGS{'UpdateContent'};
     if ( $ARGS{'UpdateTimeWorked'} || (

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Ticket/Update.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Ticket/Update.html	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Ticket/Update.html	Wed Jul 25 12:23:41 2007
@@ -49,6 +49,8 @@
 <& /Ticket/Elements/Tabs, 
     Ticket => $TicketObj, 
     Title=> $title &>
+    
+<& /Elements/ShowLock, Ticket => $TicketObj, noUnlock => 1 &>
 
 <form action="Update.html" name="TicketUpdate"
     method="post" enctype="multipart/form-data">
@@ -148,6 +150,8 @@
 
 my $TicketObj = LoadTicket($id);
 
+$TicketObj->RT::Ticket::Lock() unless $TicketObj->RT::Ticket::Locked();
+
 unless($DefaultStatus){
     $DefaultStatus=($ARGS{'Status'} ||$TicketObj->Status());
 }
@@ -230,6 +234,7 @@
 # }}}
 
 if ( exists $ARGS{SubmitTicket} ) {
+	$ARGS{'Lock'} = 'remove';
     $m->comp('Display.html', TicketObj => $TicketObj, %ARGS);
     return;
 }

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm	Wed Jul 25 12:23:41 2007
@@ -227,6 +227,48 @@
 	return($Queue);
 }
 
+
+
+sub Locked {
+    my $ticket =shift;
+    return $ticket->FirstAttribute('RT_Lock');
+}
+
+sub Lock {
+    my $ticket = shift;
+
+    if ( $ticket->RT::Ticket::Locked ) {
+        return undef;
+    } else {
+        $ticket->SetAttribute(
+            Name    => 'RT_Lock',
+            Content => {
+                User      => $ticket->CurrentUser->id,
+                Timestamp => time()
+
+            }
+        );
+    }
+}
+
+
+sub Unlock {
+    my $ticket = shift;
+
+    my $lock = $ticket->RT::Ticket::Locked();
+     return undef unless $lock;
+     return undef unless $lock->Content->{User} ==  $ticket->CurrentUser->id;
+    $ticket->DeleteAttribute('RT_Lock');
+}
+
+
+sub BreakLock {
+    my $ticket = shift;
+    my $lock = $ticket->RT::Ticket::Locked();
+     return undef unless $lock;
+    $ticket->DeleteAttribute('RT_Lock');
+}
+
 =head2 Type
 
 Returns the current value of Type. 


More information about the Rt-commit mailing list