[Rt-commit] r5384 - in rt/branches/3.7-EXPERIMENTAL: . bin html/REST/1.0/Forms/ticket lib/t/regression

ruz at bestpractical.com ruz at bestpractical.com
Thu Jun 15 18:04:21 EDT 2006


Author: ruz
Date: Thu Jun 15 18:04:10 2006
New Revision: 5384

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/bin/rt.in
   rt/branches/3.7-EXPERIMENTAL/html/REST/1.0/Forms/ticket/take
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm
   rt/branches/3.7-EXPERIMENTAL/lib/t/regression/26command_line.t

Log:
 r3126 at cubic-pc (orig r5303):  ruz | 2006-05-26 19:15:46 +0400
 * take/steal actions in CLI
 ** pass 'take|steal|untake' as Action argument to REST
 ** don't check rights in REST interface, SetOwner do that for us
 ** return more descriptive message when we try to take ticket from
    other user
 ** all tests pass


Modified: rt/branches/3.7-EXPERIMENTAL/bin/rt.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/bin/rt.in	(original)
+++ rt/branches/3.7-EXPERIMENTAL/bin/rt.in	Thu Jun 15 18:04:10 2006
@@ -757,8 +757,6 @@
     my ($bad, %data) = (0, ());
 
     my $id;
-    my $force = 0;
-    $force = 1 if $cmd eq 'steal';
 
     # get the ticket id
     if (@ARGV == 1) {
@@ -769,10 +767,10 @@
         }
         my $form = [
             "",
-            [ "Ticket", "Force" ],
+            [ "Ticket", "Action" ],
             {
                 Ticket => $id,
-                Force => $force,
+                Action => $cmd,
                 Status => '',
             }
         ];

Modified: rt/branches/3.7-EXPERIMENTAL/html/REST/1.0/Forms/ticket/take
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/REST/1.0/Forms/ticket/take	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/REST/1.0/Forms/ticket/take	Thu Jun 15 18:04:10 2006
@@ -56,8 +56,8 @@
 my ($c, $o, $k, $e) = ("", [], {}, 0);
 
 # http://.../REST/1.0/ticket/1/take
-$ticket->Load($id);
-if (!$ticket->Id) {
+$ticket->Load( $id );
+unless ( $ticket->Id ) {
     $e = 1;
     $c = "# Ticket $id does not exist.";
     goto OUTPUT;
@@ -65,7 +65,6 @@
 
 my $action;
 
-my %data;
 my @comments;
 
 ($action = $changes{Action}) =~ s/^(.)(.*)$/\U$1\L$2\E/;
@@ -75,58 +74,59 @@
     goto OUTPUT;
 }
 
-unless ($ticket->CurrentUserHasRight('ModifyTicket') ||
-        ( ($action eq "Take" || $action eq 'Untake') &&
-         $ticket->CurrentUserHasRight("TakeTicket")) ||
-        ($action eq "Steal" &&
-         $ticket->CurrentUserHasRight("StealTicket")))
-{
-    $e = 1;
-    $c = "# You are not allowed to $action ticket $id.";
-    goto OUTPUT;
-}
-
-if (!keys(%data)) {
-    # assemble a form data structure
-    my @data;
-    push @data, [ Ticket => $ticket->Id ];
-    push @data, [ Force => '0' ];       # 1 => "steal"
-}
-else {
-    # process the form data structure
-    my ($key, $val);
-    
-    foreach $key (keys %data) {
-        $val = $data{$key};
-
-        if ($key =~ /^force$/i) {
-            if ($val !~ /^(?:0|1)$/) {
-                push(@comments, "# invalid value for 'force': $val");
-                goto DONE;
-            }
-            my ($ret_id, $msg);
-
-            ### take
-            if ($val == 0) {
-                ($ret_id, $msg) = $ticket->Take;
-                if (!$ret_id) {
-                    push(@comments, "# Couldn't take ticket $id: $msg");
-                    goto DONE;
-                }
-                push(@comments, "# Ticket $id taken.");
-            }
-            ### steal
-            else {
-                ($ret_id, $msg) = $ticket->Steal;
-                if (!$ret_id) {
-                    push(@comments, "# Couldn't steal ticket $id: $msg");
-                    goto DONE;
-                }
-                push(@comments, "# Ticket $id stolen.");
-            }
-        }
-    }
-}
+my ($status, $msg) = $ticket->$action();
+$c = "# $msg";
+$e = 1  unless $status;
+goto OUTPUT;
+
+#unless ($ticket->CurrentUserHasRight('ModifyTicket') ||
+#        ( ($action eq "Take" || $action eq 'Untake') &&
+#         $ticket->CurrentUserHasRight("TakeTicket")) ||
+#        ($action eq "Steal" &&
+#         $ticket->CurrentUserHasRight("StealTicket")))
+#{
+#    $e = 1;
+#    $c = "# You are not allowed to $action ticket $id.";
+#    goto OUTPUT;
+#}
+
+#if ( keys %changes ) {
+#}
+#else {
+#    # process the form data structure
+#    my ($key, $val);
+#    
+#    foreach $key (keys %data) {
+#        $val = $data{$key};
+#
+#        if ($key =~ /^force$/i) {
+#            if ($val !~ /^(?:0|1)$/) {
+#                push(@comments, "# invalid value for 'force': $val");
+#                goto DONE;
+#            }
+#            my ($ret_id, $msg);
+#
+#            ### take
+#            if ($val == 0) {
+#                ($ret_id, $msg) = $ticket->Take;
+#                if (!$ret_id) {
+#                    push(@comments, "# Couldn't take ticket $id: $msg");
+#                    goto DONE;
+#                }
+#                push(@comments, "# Ticket $id taken.");
+#            }
+#            ### steal
+#            else {
+#                ($ret_id, $msg) = $ticket->Steal;
+#                if (!$ret_id) {
+#                    push(@comments, "# Couldn't steal ticket $id: $msg");
+#                    goto DONE;
+#                }
+#                push(@comments, "# Ticket $id stolen.");
+#            }
+#        }
+#    }
+#}
 
 OUTPUT:
 return [ $c, $o, $k, $e ];

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm	Thu Jun 15 18:04:10 2006
@@ -3016,9 +3016,12 @@
         ( $self->OwnerObj->Id != $RT::Nobody->Id ) and    #and the owner is set
         ( $self->CurrentUser->Id ne $self->OwnerObj->Id() )
       ) {                                                 #and it's not us
-        return ( 0,
-                 $self->loc(
-"You can only reassign tickets that you own or that are unowned" ) );
+        return ( 0, $self->loc("You can only take tickets that are unowned") )
+            if $NewOwnerObj->id == $self->CurrentUser->id;
+        return (
+            0,
+            $self->loc("You can only reassign tickets that you own or that are unowned" )
+        );
     }
 
     #If we've specified a new owner and that user can't modify the ticket

Modified: rt/branches/3.7-EXPERIMENTAL/lib/t/regression/26command_line.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/t/regression/26command_line.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/t/regression/26command_line.t	Thu Jun 15 18:04:10 2006
@@ -3,7 +3,7 @@
 use strict;
 use Test::Expect;
 #use Test::More qw/no_plan/;
-use Test::More tests => 137;
+use Test::More tests => 138;
 
 use RT;
 RT::LoadConfig();
@@ -282,8 +282,8 @@
 # }}}
 
 # {{{ test taking/stealing tickets
-TODO: {
-    local $TODO = "Taking/stealing haven't been implemented yet.";
+{
+#    local $TODO = "Taking/stealing haven't been implemented yet.";
 
     # create a user; give them privileges to take and steal
     ### TODO: implement 'grant' in the CLI tool; use that here instead.
@@ -297,10 +297,11 @@
     ok($steal_user_id, "Created the user? $msg");
     my $steal_queue = RT::Queue->new($RT::SystemUser);
     my $steal_queue_id;
-    ($steal_queue_id, $msg) = $steal_queue->Load( Name => "Steal$$" );
+    ($steal_queue_id, $msg) = $steal_queue->Create( Name => "Steal$$" );
     ok($steal_queue_id, "Got the queue? $msg");
+    ok($steal_queue->id, "queue obj has id");
     my $status;
-    ($status, $msg) = $steal_user->PrincipalObj->GrantRight( Right => 'SeeTicket', Object => $steal_queue );
+    ($status, $msg) = $steal_user->PrincipalObj->GrantRight( Right => 'ShowTicket', Object => $steal_queue );
     ok($status, "Gave 'SeeTicket' to our user? $msg");
     ($status, $msg) = $steal_user->PrincipalObj->GrantRight( Right => 'OwnTicket', Object => $steal_queue );
     ok($status, "Gave 'OwnTicket' to our user? $msg");
@@ -310,7 +311,7 @@
     ok($status, "Gave 'TakeTicket' to our user? $msg");
 
     # create a ticket to take/steal
-    expect_send("create -t ticket set subject='CLIStealTest-$$'", 'Creating ticket to steal...');
+    expect_send("create -t ticket set queue=$steal_queue_id subject='CLIStealTest-$$'", 'Creating ticket to steal...');
     expect_like(qr/Ticket \d+ created/, 'Created ticket');
     expect_handle->before() =~ /Ticket (\d+) created/;
     my $steal_ticket_id = $1;
@@ -318,7 +319,8 @@
 
     # root takes the ticket
     expect_send("take $steal_ticket_id", 'root takes the ticket...');
-    expect_like(qr/Took ticket $steal_ticket_id/, 'root took the ticket');
+    expect_like(qr/Owner changed from Nobody to root/, 'root took the ticket');
+#    expect_like(qr/Took ticket $steal_ticket_id/, 'root took the ticket');
 
     # log in as the non-root user
     #expect_quit();      # this is apparently unnecessary, but I'll leave it in
@@ -333,16 +335,16 @@
     # 'steal' it back from them.  'steal' can automatically 'take' a ticket,
     # though.
     expect_send("take $steal_ticket_id", 'user tries to take the ticket...');
-    expect_like(qr/Ticket $steal_ticket_id already owned by user root/, '...and fails.');
+    expect_like(qr/You can only take tickets that are unowned/, '...and fails.');
     expect_send("show ticket/$steal_ticket_id -f owner", 'Double-checking...');
     expect_like(qr/Owner: root/, '...no change.');
 
     # user steals the ticket
     expect_send("steal $steal_ticket_id", 'user tries to *steal* the ticket...');
-    expect_like(qr/Stole ticket $steal_ticket_id/, '...and succeeds!');
+    expect_like(qr/Owner changed from root to fooser$$/, '...and succeeds!');
     expect_send("show ticket/$steal_ticket_id -f owner", 'Double-checking...');
     expect_like(qr/Owner: fooser$$/, '...yup, it worked.');
-    
+
     # log back in as root
     #expect_quit();     # ditto
     $ENV{'RTUSER'} = 'root';
@@ -351,7 +353,7 @@
 
     # root steals the ticket back
     expect_send("steal $steal_ticket_id", 'root steals the ticket back...');
-    expect_like(qr/Stole ticket $steal_ticket_id/, '...and succeeds.');
+    expect_like(qr/Owner changed from fooser$$ to root/, '...and succeeds.');
 }
 # }}}
 


More information about the Rt-commit mailing list