[Rt-commit] rt branch, 4.2/merge-jsgantt, created. rt-4.0.0rc4-72-gb8b8a88
? sunnavy
sunnavy at bestpractical.com
Wed Feb 2 00:51:06 EST 2011
The branch, 4.2/merge-jsgantt has been created
at b8b8a8813b86673501bd1b2c18b10b181f09f35c (commit)
- Log -----------------------------------------------------------------
commit 43231878e48848ef7487fe7413a4ade9df42b4bf
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri Jan 28 14:48:27 2011 -0500
Refactor RT::Ticket->SetOwner to be a bit easier to override
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index b6f3639..d5999da 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -2866,61 +2866,15 @@ sub SetOwner {
return ( 0, $self->loc("That user does not exist") );
}
-
- # must have ModifyTicket rights
- # or TakeTicket/StealTicket and $NewOwner is self
- # see if it's a take
- if ( $OldOwnerObj->Id == RT->Nobody->Id ) {
- unless ( $self->CurrentUserHasRight('ModifyTicket')
- || $self->CurrentUserHasRight('TakeTicket') ) {
- $RT::Handle->Rollback();
- return ( 0, $self->loc("Permission Denied") );
- }
- }
-
- # see if it's a steal
- elsif ( $OldOwnerObj->Id != RT->Nobody->Id
- && $OldOwnerObj->Id != $self->CurrentUser->id ) {
-
- unless ( $self->CurrentUserHasRight('ModifyTicket')
- || $self->CurrentUserHasRight('StealTicket') ) {
- $RT::Handle->Rollback();
- return ( 0, $self->loc("Permission Denied") );
- }
- }
- else {
- unless ( $self->CurrentUserHasRight('ModifyTicket') ) {
- $RT::Handle->Rollback();
- return ( 0, $self->loc("Permission Denied") );
- }
- }
-
- # If we're not stealing and the ticket has an owner and it's not
- # the current user
- if ( $Type ne 'Steal' and $Type ne 'Force'
- and $OldOwnerObj->Id != RT->Nobody->Id
- and $OldOwnerObj->Id != $self->CurrentUser->Id )
- {
+ if ( !$self->_CurrentUserHasRightToSetOwner ) {
$RT::Handle->Rollback();
- 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
- elsif ( !$NewOwnerObj->HasRight( Right => 'OwnTicket', Object => $self ) ) {
- $RT::Handle->Rollback();
- return ( 0, $self->loc("That user may not own tickets in that queue") );
+ return ( 0, $self->loc("Permission Denied") );
}
- # If the ticket has an owner and it's the new owner, we don't need
- # To do anything
- elsif ( $NewOwnerObj->Id == $OldOwnerObj->Id ) {
+ my ( $val, $msg ) = $self->_IsProposedOwnerChangeValid( $NewOwnerObj, $Type );
+ if ( !$val ) {
$RT::Handle->Rollback();
- return ( 0, $self->loc("That user already owns that ticket") );
+ return ( $val, $msg );
}
# Delete the owner in the owner group, then add a new one
@@ -2984,7 +2938,69 @@ sub SetOwner {
return ( $val, $msg );
}
+sub _CurrentUserHasRightToSetOwner {
+ my $self = shift;
+ # must have ModifyTicket rights
+ # or TakeTicket/StealTicket and $NewOwner is self
+ # see if it's a take
+ my $OldOwnerObj = $self->OwnerObj;
+ if ( $OldOwnerObj->Id == RT->Nobody->Id ) {
+ unless ( $self->CurrentUserHasRight('ModifyTicket')
+ || $self->CurrentUserHasRight('TakeTicket') ) {
+ return 0;
+ }
+ }
+
+ # see if it's a steal
+ elsif ( $OldOwnerObj->Id != RT->Nobody->Id
+ && $OldOwnerObj->Id != $self->CurrentUser->id ) {
+
+ unless ( $self->CurrentUserHasRight('ModifyTicket')
+ || $self->CurrentUserHasRight('StealTicket') ) {
+ return 0;
+ }
+ }
+ else {
+ unless ( $self->CurrentUserHasRight('ModifyTicket') ) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+sub _IsProposedOwnerChangeValid {
+ my $self = shift;
+ my $NewOwnerObj = shift;
+ my $Type = shift;
+
+ my $OldOwnerObj = $self->OwnerObj;
+
+ # If we're not stealing and the ticket has an owner and it's not
+ # the current user
+ if ( $Type ne 'Steal' and $Type ne 'Force'
+ and $OldOwnerObj->Id != RT->Nobody->Id
+ and $OldOwnerObj->Id != $self->CurrentUser->Id ) {
+ if ( $NewOwnerObj->id == $self->CurrentUser->id) {
+ return ( 0, $self->loc("You can only take tickets that are unowned") )
+ }
+ else {
+ 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
+ elsif ( !$NewOwnerObj->HasRight( Right => 'OwnTicket', Object => $self ) )
+ {
+ return ( 0, $self->loc("That user may not own tickets in that queue") );
+ }
+
+ # If the ticket has an owner and it's the new owner, we don't need
+ # To do anything
+ elsif ( $NewOwnerObj->Id == $OldOwnerObj->Id ) {
+ return ( 0, $self->loc("That user already owns that ticket") );
+ }
+ return (1, undef);
+}
=head2 Take
commit 6e6c583550228e1b03c9f01341a8a4fb6ab6aa77
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Sat Jan 29 14:05:57 2011 -0500
Remove an extraneous "my" that caused warnings.
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index d5999da..b3e4495 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -2902,7 +2902,7 @@ sub SetOwner {
# We call set twice with slightly different arguments, so
# as to not have an SQL transaction span two RT transactions
- my ( $val, $msg ) = $self->_Set(
+ ( $val, $msg ) = $self->_Set(
Field => 'Owner',
RecordTransaction => 0,
Value => $NewOwnerObj->Id,
commit caebe1dade3e92bb161a4acabeeaaf79ba768167
Merge: d0ff1a5 8b4fe7c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Jan 31 12:52:07 2011 -0500
Merge branch '4.0-trunk'
commit b8b8a8813b86673501bd1b2c18b10b181f09f35c
Merge: caebe1d 6e6c583
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Jan 31 13:37:07 2011 -0500
Merge branch '4.2/split-up-setowner-a-bit'
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list