X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FTicket_Overlay.pm;h=a294dcafd28fd6b4bc839ba263328d3c37d27963;hp=d04ececd8bde9310438b236e5a868052f4b1976a;hb=9c68254528b6f2c7d8c1921b452fa56064783782;hpb=d4d0590bef31071e8809ec046717444b95b3f30a diff --git a/rt/lib/RT/Ticket_Overlay.pm b/rt/lib/RT/Ticket_Overlay.pm index d04ececd8..a294dcafd 100644 --- a/rt/lib/RT/Ticket_Overlay.pm +++ b/rt/lib/RT/Ticket_Overlay.pm @@ -240,7 +240,7 @@ sub Load { #If it's a local URI, turn it into a ticket id - if ( $id =~ /^$RT::TicketBaseURI(\d+)$/ ) { + if ( $RT::TicketBaseURI && $id =~ /^$RT::TicketBaseURI(\d+)$/ ) { $id = $1; } @@ -440,9 +440,9 @@ sub Create { if ( $args{'Due'} ) { $Due->Set( Format => 'ISO', Value => $args{'Due'} ); } - elsif ( $QueueObj->DefaultDueIn ) { + elsif ( my $due_in = $QueueObj->DefaultDueIn ) { $Due->SetToNow; - $Due->AddDays( $QueueObj->DefaultDueIn ); + $Due->AddDays( $due_in ); } my $Starts = new RT::Date( $self->CurrentUser ); @@ -750,7 +750,7 @@ sub Create { $RT::Handle->Commit(); $ErrStr = $self->loc( "Ticket [_1] created in queue '[_2]'", $self->Id, $QueueObj->Name ); $ErrStr = join( "\n", $ErrStr, @non_fatal_errors ); - return ( $self->Id, $0, $ErrStr ); + return ( $self->Id, 0, $ErrStr ); } } @@ -1315,6 +1315,10 @@ sub AddWatcher { @_ ); + # XXX, FIXME, BUG: if only email is provided then we only check + # for ModifyTicket right, but must try to get PrincipalId and + # check Watch* rights too if user exist + # {{{ Check ACLS #If the watcher we're trying to add is for the current user if ( $self->CurrentUser->PrincipalId eq $args{'PrincipalId'}) { @@ -1979,11 +1983,16 @@ sub SetQueue { ) ) { - $self->Untake(); + my $clone = RT::Ticket->new( $RT::SystemUser ); + $clone->Load( $self->Id ); + unless ( $clone->Id ) { + return ( 0, $self->loc("Couldn't load copy of ticket #[_1].", $self->Id) ); + } + my ($status, $msg) = $clone->SetOwner( $RT::Nobody->Id, 'Force' ); + $RT::Logger->error("Couldn't set owner on queue change: $msg") unless $status; } return ( $self->_Set( Field => 'Queue', Value => $NewQueueObj->Id() ) ); - } # }}} @@ -2501,8 +2510,11 @@ sub DeleteLink { $direction='Base'; } - if ( $val ) { - my $remote_uri = RT::URI->new( $RT::SystemUser ); + if ( $args{'Silent'} ) { + return ( $val, $Msg ); + } + else { + my $remote_uri = RT::URI->new( $self->CurrentUser ); $remote_uri->FromURI( $remote_link ); my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction( @@ -2512,6 +2524,17 @@ sub DeleteLink { TimeTaken => 0 ); + if ( $remote_uri->IsLocal ) { + + my $OtherObj = $remote_uri->Object; + my ( $val, $Msg ) = $OtherObj->_NewTransaction(Type => 'DeleteLink', + Field => $direction eq 'Target' ? $LINKDIRMAP{$args{'Type'}}->{Base} + : $LINKDIRMAP{$args{'Type'}}->{Target}, + OldValue => $self->URI, + ActivateScrips => ! $RT::LinkTransactionsRun1Scrip, + TimeTaken => 0 ); + } + return ( $Trans, $Msg ); } } @@ -2524,52 +2547,6 @@ sub DeleteLink { Takes a paramhash of Type and one of Base or Target. Adds that link to this ticket. -=begin testing - -my $q1 = RT::Queue->new($RT::SystemUser); -my ($id,$msg) = $q1->Create(Name => 'LinkTest1'); -ok ($id,$msg); -my $q2 = RT::Queue->new($RT::SystemUser); -($id,$msg) = $q2->Create(Name => 'LinkTest2'); -ok ($id,$msg); - -my $u1 = RT::User->new($RT::SystemUser); -($id,$msg) =$u1->Create(Name => 'LinkTestUser'); - -ok ($id,$msg); - -($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'CreateTicket'); -ok ($id,$msg); -($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'ModifyTicket'); -ok ($id,$msg); - -my $tid; - -my $creator = RT::CurrentUser->new($u1->id); - -my $ticket = RT::Ticket->new( $creator); -ok($ticket->isa('RT::Ticket')); -($id,$tid, $msg) = $ticket->Create(Subject => 'Link test 1', Queue => $q1->id); -ok ($id,$msg); - - -my $ticket2 = RT::Ticket->new($RT::SystemUser); -($id, $tid, $msg) = $ticket2->Create(Subject => 'Link test 2', Queue => $q2->id); -ok ($id, $msg); - -($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); -ok(!$id,$msg); -($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q2, Right => 'CreateTicket'); -ok ($id,$msg); -($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q2, Right => 'ModifyTicket'); -ok ($id,$msg); -($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); -ok($id,$msg); -($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => -1); -ok(!$id,$msg); - -=end testing - =cut sub AddLink { @@ -2657,7 +2634,7 @@ sub _AddLink { return ( $val, $Msg ); } else { - my $remote_uri = RT::URI->new( $RT::SystemUser ); + my $remote_uri = RT::URI->new( $self->CurrentUser ); $remote_uri->FromURI( $remote_link ); #Write the transaction @@ -2666,6 +2643,17 @@ sub _AddLink { Field => $LINKDIRMAP{$args{'Type'}}->{$direction}, NewValue => $remote_uri->URI || $remote_link, TimeTaken => 0 ); + + if ( $remote_uri->IsLocal ) { + + my $OtherObj = $remote_uri->Object; + my ( $val, $Msg ) = $OtherObj->_NewTransaction(Type => 'AddLink', + Field => $direction eq 'Target' ? $LINKDIRMAP{$args{'Type'}}->{Base} + : $LINKDIRMAP{$args{'Type'}}->{Target}, + NewValue => $self->URI, + ActivateScrips => ! $RT::LinkTransactionsRun1Scrip, + TimeTaken => 0 ); + } return ( $val, $Msg ); } @@ -3039,21 +3027,21 @@ sub SetOwner { $RT::Handle->Commit(); - my ( $trans, $msg, undef ) = $self->_NewTransaction( - Type => $Type, - Field => 'Owner', - NewValue => $NewOwnerObj->Id, - OldValue => $OldOwnerObj->Id, - TimeTaken => 0 ); + ($val, $msg) = $self->_NewTransaction( + Type => $Type, + Field => 'Owner', + NewValue => $NewOwnerObj->Id, + OldValue => $OldOwnerObj->Id, + TimeTaken => 0, + ); - if ($trans) { + if ( $val ) { $msg = $self->loc( "Owner changed from [_1] to [_2]", $OldOwnerObj->Name, $NewOwnerObj->Name ); # TODO: make sure the trans committed properly } - return ( $trans, $msg ); - + return ( $val, $msg ); } # }}} @@ -3239,7 +3227,7 @@ Takes no arguments. Marks this ticket for garbage collection sub Kill { my $self = shift; - $RT::Logger->crit("'Kill' is deprecated. use 'Delete' instead."); + $RT::Logger->crit("'Kill' is deprecated. use 'Delete' instead at (". join(":",caller).")."); return $self->Delete; } @@ -3482,7 +3470,7 @@ sub _Set { #If we can't actually set the field to the value, don't record # a transaction. instead, get out of here. - if ( $ret == 0 ) { return ( 0, $msg ); } + return ( 0, $msg ) unless $ret; } if ( $args{'RecordTransaction'} == 1 ) { @@ -3698,11 +3686,15 @@ See L sub CustomFieldValues { my $self = shift; my $field = shift; - unless ( $field =~ /^\d+$/ ) { + if ( $field and $field !~ /^\d+$/ ) { my $cf = RT::CustomField->new( $self->CurrentUser ); - $cf->LoadByNameAndQueue( Name => $field, Queue => $self->QueueObj->Id ); + $cf->LoadByNameAndQueue( Name => $field, Queue => $self->Queue ); + unless ( $cf->id ) { + $cf->LoadByNameAndQueue( Name => $field, Queue => 0 ); + } unless ( $cf->id ) { - $cf->LoadByNameAndQueue( Name => $field, Queue => '0' ); + # If we didn't find a valid cfid, give up. + return RT::CustomFieldValues->new($self->CurrentUser); } $field = $cf->id; }