[Rt-commit] rt branch, setowner-refactor, updated. rt-3.9.4-468-g3dcca45
? sunnavy
sunnavy at bestpractical.com
Tue Nov 16 00:09:01 EST 2010
The branch, setowner-refactor has been updated
via 3dcca451f932849cbffebcd71f34ddbe54dd9890 (commit)
from 96b9a419f51a2fb913b5e012323658d3cb13dfe7 (commit)
Summary of changes:
lib/RT/Interface/Web.pm | 11 +--------
lib/RT/Ticket_Overlay.pm | 8 +++---
lib/RT/Transaction_Overlay.pm | 33 ++++++++++++++++++++++++++++
t/web/ticket_owner.t | 47 +++++++++++++++++++++++-----------------
4 files changed, 65 insertions(+), 34 deletions(-)
- Log -----------------------------------------------------------------
commit 3dcca451f932849cbffebcd71f34ddbe54dd9890
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Nov 16 13:03:24 2010 +0800
for SetOwner: txn type is always Set, but we also want the customized description, which can be accomplished by checking the old/new values
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 13d40dd..d6b2767 100755
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1704,17 +1704,8 @@ sub ProcessTicketBasics {
if ( $ARGSRef->{'ForceOwnerChange'} ) {
$ChownType = "Force";
}
- elsif ( $session{CurrentUser}->id == $ARGSRef->{'Owner'} )
- {
- if ( $OrigOwner == RT->Nobody->id ) {
- $ChownType = "Take";
- }
- else {
- $ChownType = "Steal";
- }
- }
else {
- $ChownType = "Give";
+ $ChownType = "Set";
}
my ( $val, $msg ) = $TicketObj->SetOwner( $ARGSRef->{'Owner'}, $ChownType );
diff --git a/lib/RT/Ticket_Overlay.pm b/lib/RT/Ticket_Overlay.pm
index 6573513..e5c553d 100755
--- a/lib/RT/Ticket_Overlay.pm
+++ b/lib/RT/Ticket_Overlay.pm
@@ -2845,7 +2845,7 @@ sub OwnerAsString {
Takes two arguments:
the Id or Name of the owner
and (optionally) the type of the SetOwner Transaction. It defaults
-to 'Give'. 'Steal' is also a valid option.
+to 'Set'. 'Steal' is also a valid option.
=cut
@@ -2853,7 +2853,7 @@ to 'Give'. 'Steal' is also a valid option.
sub SetOwner {
my $self = shift;
my $NewOwner = shift;
- my $Type = shift || "Give";
+ my $Type = shift || "Set";
$RT::Handle->BeginTransaction();
@@ -2956,7 +2956,7 @@ sub SetOwner {
RecordTransaction => 0,
Value => $NewOwnerObj->Id,
TimeTaken => 0,
- TransactionType => $Type,
+ TransactionType => 'Set',
CheckACL => 0, # don't check acl
);
@@ -2966,7 +2966,7 @@ sub SetOwner {
}
($val, $msg) = $self->_NewTransaction(
- Type => $Type,
+ Type => 'Set',
Field => 'Owner',
NewValue => $NewOwnerObj->Id,
OldValue => $OldOwnerObj->Id,
diff --git a/lib/RT/Transaction_Overlay.pm b/lib/RT/Transaction_Overlay.pm
index e03f133..18e41e1 100755
--- a/lib/RT/Transaction_Overlay.pm
+++ b/lib/RT/Transaction_Overlay.pm
@@ -892,6 +892,39 @@ sub BriefDescription {
$t2->Set(Format => 'ISO', Value => $self->OldValue);
return $self->loc( "[_1] changed from [_2] to [_3]", $self->loc($self->Field), $t2->AsString, $t1->AsString );
}
+ elsif ( $self->Field eq 'Owner' ) {
+ my $Old = RT::User->new( $self->CurrentUser );
+ $Old->Load( $self->OldValue );
+ my $New = RT::User->new( $self->CurrentUser );
+ $New->Load( $self->NewValue );
+
+ if ( $Old->id == RT->Nobody->id ) {
+ if ( $New->id == $self->CurrentUser->id ) {
+ return $self->loc("Taken");
+ }
+ else {
+ return $self->loc( "Given to [_1]", $New->Name );
+ }
+ }
+ else {
+ if ( $New->id == $self->CurrentUser->id ) {
+ return $self->loc("Stolen from [_1]", $Old->Name);
+ }
+ elsif ( $Old->id == $self->CurrentUser->id ) {
+ if ( $New->id == RT->Nobody->id ) {
+ return $self->loc("Untaken");
+ }
+ else {
+ return $self->loc( "Given to [_1]", $New->Name );
+ }
+ }
+ else {
+ return $self->loc(
+ "Owner forcibly changed from [_1] to [_2]",
+ $Old->Name, $New->Name );
+ }
+ }
+ }
else {
return $self->loc( "[_1] changed from [_2] to [_3]",
$self->loc($self->Field),
diff --git a/t/web/ticket_owner.t b/t/web/ticket_owner.t
index bcac397..864817e 100644
--- a/t/web/ticket_owner.t
+++ b/t/web/ticket_owner.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Test nodata => 1, tests => 100;
+use RT::Test nodata => 1, tests => 101;
my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
ok $queue && $queue->id, 'loaded or created queue';
@@ -365,7 +365,8 @@ ok(
'set rights'
);
-diag "action is Take when old owner is nobody and new owner is current user";
+diag
+"action is Take if old owner is nobody and new owner is current user in update page";
{
my $ticket = RT::Ticket->new( $user_a );
my ( $id, $txn, $msg ) = $ticket->Create(
@@ -376,31 +377,37 @@ diag "action is Take when old owner is nobody and new owner is current user";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_a->goto_ticket( $id );
- $agent_a->content_lacks('Taken', 'No Taken in display page');
+ $agent_a->content_lacks('Taken', 'no Taken');
$agent_a->follow_link_ok({text => 'Reply'}, 'Ticket -> Reply');
- $agent_a->form_name('TicketUpdate');
- $agent_a->select( Owner => $user_a->id );
- $agent_a->click('SubmitTicket');
- $agent_a->content_contains('Taken', 'action is Take');
+ $agent_a->submit_form(
+ form_name => 'TicketUpdate',
+ fields => { Owner => $user_a->id },
+ button => 'SubmitTicket',
+ );
+ $agent_a->content_contains('Taken', 'got Taken msg');
}
-diag "action is Steal when old owner isn't nobody and new owner is current user";
-{
- my $ticket = RT::Ticket->new( $user_a );
+diag
+"action is Take if old owner is nobody and new owner is current user in basics page";
+{
+ my $ticket = RT::Ticket->new($user_a);
my ( $id, $txn, $msg ) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
- Owner => $user_b->id,
);
- ok $id, 'created a ticket #'. $id or diag "error: $msg";
- is $ticket->Owner, $user_b->id, 'correct owner';
+ ok $id, 'created a ticket #' . $id or diag "error: $msg";
+ is $ticket->Owner, RT->Nobody->id, 'correct owner';
- $agent_a->goto_ticket( $id );
- $agent_a->content_lacks('Stolen', 'No Stolen in display page');
- $agent_a->follow_link_ok({text => 'Reply'}, 'Ticket -> Reply');
- $agent_a->form_name('TicketUpdate');
- $agent_a->select( Owner => $user_a->id );
- $agent_a->click('SubmitTicket');
- $agent_a->content_contains('Stolen from user_b', 'action is Steal');
+ $agent_a->goto_ticket($id);
+ $agent_a->content_lacks('Taken', 'no Taken');
+ $agent_a->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
+ $agent_a->submit_form(
+ form_name => 'TicketModify',
+ fields => { Owner => $user_a->id },
+ );
+ $agent_a->content_contains( 'Owner changed from Nobody to user_a',
+ 'got set message in Basics' );
+ $agent_a->goto_ticket($id);
+ $agent_a->content_contains( 'Taken', 'got Taken message' );
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list