# BEGIN BPS TAGGED BLOCK {{{ # # COPYRIGHT: # # This software is Copyright (c) 1996-2006 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) # # # LICENSE: # # This work is made available to you under the terms of Version 2 of # the GNU General Public License. A copy of that license should have # been provided with this software, but in any event can be snarfed # from www.gnu.org. # # This work is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # # CONTRIBUTION SUBMISSION POLICY: # # (The following paragraph is not intended to limit the rights granted # to you to modify and distribute this software under the terms of # the GNU General Public License and is only of importance to you if # you choose to contribute your changes and enhancements to the # community by submitting them to Best Practical Solutions, LLC.) # # By intentionally submitting any modifications, corrections or # derivatives to this work, or any other work intended for use with # Request Tracker, to Best Practical Solutions, LLC, you confirm that # you are the copyright holder for those contributions and you grant # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, # royalty-free, perpetual, license to use, copy, create derivative # works based on those contributions, and sublicense and distribute # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} package RT::Ticket; use strict; no warnings qw(redefine); # {{{ sub Import =head2 Import PARAMHASH Import a ticket. Doesn\'t create a transaction. Doesn\'t supply queue defaults, etc. Returns: TICKETID =cut sub Import { my $self = shift; my ( $ErrStr, $QueueObj, $Owner ); my %args = ( id => undef, EffectiveId => undef, Queue => undef, Requestor => undef, Type => 'ticket', Owner => $RT::Nobody->Id, Subject => '[no subject]', InitialPriority => undef, FinalPriority => undef, Status => 'new', TimeWorked => "0", Due => undef, Created => undef, Updated => undef, Resolved => undef, Told => undef, @_ ); if ( ( defined( $args{'Queue'} ) ) && ( !ref( $args{'Queue'} ) ) ) { $QueueObj = RT::Queue->new($RT::SystemUser); $QueueObj->Load( $args{'Queue'} ); #TODO error check this and return 0 if it\'s not loading properly +++ } elsif ( ref( $args{'Queue'} ) eq 'RT::Queue' ) { $QueueObj = RT::Queue->new($RT::SystemUser); $QueueObj->Load( $args{'Queue'}->Id ); } else { $RT::Logger->debug( "$self " . $args{'Queue'} . " not a recognised queue object." ); } #Can't create a ticket without a queue. unless ( defined($QueueObj) and $QueueObj->Id ) { $RT::Logger->debug("$self No queue given for ticket creation."); return ( 0, $self->loc('Could not create ticket. Queue not set') ); } #Now that we have a queue, Check the ACLS unless ( $self->CurrentUser->HasRight( Right => 'CreateTicket', Object => $QueueObj ) ) { return ( 0, $self->loc("No permission to create tickets in the queue '[_1]'" , $QueueObj->Name)); } # {{{ Deal with setting the owner # Attempt to take user object, user name or user id. # Assign to nobody if lookup fails. if ( defined( $args{'Owner'} ) ) { if ( ref( $args{'Owner'} ) ) { $Owner = $args{'Owner'}; } else { $Owner = new RT::User( $self->CurrentUser ); $Owner->Load( $args{'Owner'} ); if ( !defined( $Owner->id ) ) { $Owner->Load( $RT::Nobody->id ); } } } #If we have a proposed owner and they don't have the right #to own a ticket, scream about it and make them not the owner if ( ( defined($Owner) ) and ( $Owner->Id != $RT::Nobody->Id ) and ( !$Owner->HasRight( Object => $QueueObj, Right => 'OwnTicket' ) ) ) { $RT::Logger->warning( "$self user " . $Owner->Name . "(" . $Owner->id . ") was proposed " . "as a ticket owner but has no rights to own " . "tickets in '" . $QueueObj->Name . "'\n" ); $Owner = undef; } #If we haven't been handed a valid owner, make it nobody. unless ( defined($Owner) ) { $Owner = new RT::User( $self->CurrentUser ); $Owner->Load( $RT::Nobody->UserObj->Id ); } # }}} unless ( $self->ValidateStatus( $args{'Status'} ) ) { return ( 0, $self->loc("'[_1]' is an invalid value for status", $args{'Status'}) ); } $self->{'_AccessibleCache'}{Created} = { 'read' => 1, 'write' => 1 }; $self->{'_AccessibleCache'}{Creator} = { 'read' => 1, 'auto' => 1 }; $self->{'_AccessibleCache'}{LastUpdated} = { 'read' => 1, 'write' => 1 }; $self->{'_AccessibleCache'}{LastUpdatedBy} = { 'read' => 1, 'auto' => 1 }; # This doesn't work... It's actually a bug somewhere in the superclass # Which means that it still thinks that an Id and EffId have been passed # in. # # This is therefore a horrible nasty hack and needs fixing in (probably) # DBIx::SearchBuilder # # If we're coming in with an id, set that now. # my $EffectiveId = undef; # if ( $args{'id'} ) { # $EffectiveId = $args{'id'}; # } my $id = $self->SUPER::Create( # id => $args{'id'}, # EffectiveId => $EffectiveId, EffectiveId => '0', Queue => $QueueObj->Id, Owner => $Owner->Id, Subject => $args{'Subject'}, # loc InitialPriority => $args{'InitialPriority'}, # loc FinalPriority => $args{'FinalPriority'}, # loc Priority => $args{'InitialPriority'}, # loc Status => $args{'Status'}, # loc TimeWorked => $args{'TimeWorked'}, # loc Type => $args{'Type'}, # loc Created => $args{'Created'}, # loc Told => $args{'Told'}, # loc LastUpdated => $args{'Updated'}, # loc Resolved => $args{'Resolved'}, # loc Due => $args{'Due'}, # loc ); # If the ticket didn't have an id # Set the ticket's effective ID now that we've created it. if ( $args{'id'} ) { $self->Load( $args{'id'} ); } else { my ( $val, $msg ) = $self->__Set( Field => 'EffectiveId', Value => $id ); unless ($val) { $RT::Logger->err( $self . "->Import couldn't set EffectiveId: $msg\n" ); } } my $create_groups_ret = $self->_CreateTicketGroups(); unless ($create_groups_ret) { $RT::Logger->crit( "Couldn't create ticket groups for ticket " . $self->Id ); } $self->OwnerGroup->_AddMember( PrincipalId => $Owner->PrincipalId ); my $watcher; foreach $watcher ( @{ $args{'Cc'} } ) { $self->_AddWatcher( Type => 'Cc', Email => $watcher, Silent => 1 ); } foreach $watcher ( @{ $args{'AdminCc'} } ) { $self->_AddWatcher( Type => 'AdminCc', Email => $watcher, Silent => 1 ); } foreach $watcher ( @{ $args{'Requestor'} } ) { $self->_AddWatcher( Type => 'Requestor', Email => $watcher, Silent => 1 ); } return ( $self->Id, $ErrStr ); } return 1;