
sartak at bestpractical
Nov 4, 2009, 1:38 PM
Post #1 of 1
(64 views)
Permalink
|
|
rt branch, create-action, updated. 48636fcad4d2973d3a5615147952cb1ed259b6e4
|
|
The branch, create-action has been updated via 48636fcad4d2973d3a5615147952cb1ed259b6e4 (commit) from 30e3416b7fd3530f2b3e85809b6f01a3d5de210e (commit) Summary of changes: lib/RT/Interface/Web.pm | 185 ----------------------------------------------- 1 files changed, 0 insertions(+), 185 deletions(-) - Log ----------------------------------------------------------------- commit 48636fcad4d2973d3a5615147952cb1ed259b6e4 Author: Shawn M Moore <sartak[at]bestpractical.com> Date: Wed Nov 4 16:38:44 2009 -0500 Kill create_ticket. Use the action! diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm index c948e83..517a629 100755 --- a/lib/RT/Interface/Web.pm +++ b/lib/RT/Interface/Web.pm @@ -326,191 +326,6 @@ sub abort { } } - - -=head2 create_ticket ARGS - -Create a new ticket, using Mason's %ARGS. returns @results. - -=cut - -sub create_ticket { - my %ARGS = (@_); - - my (@Actions); - - my $Ticket = RT::Model::Ticket->new( current_user => Jifty->web->current_user ); - - my $Queue = RT::Model::Queue->new( current_user => Jifty->web->current_user ); - unless ( $Queue->load( $ARGS{'queue'} ) ) { - abort('Queue not found'); - } - - unless ( $Queue->current_user_has_right('CreateTicket') ) { - abort('You have no permission to create tickets in that queue.'); - } - - my $due; - if ( defined $ARGS{'Due'} and $ARGS{'Due'} =~ /\S/ ) { - $due = RT::DateTime->new_from_string($ARGS{'Due'}); - } - my $starts; - if ( defined $ARGS{'Starts'} and $ARGS{'Starts'} =~ /\S/ ) { - $starts = RT::DateTime->new_from_string($ARGS{'Starts'}); - } - - my $sigless = RT::Interface::Web::strip_content( - content => $ARGS{content}, - content_type => $ARGS{content_type}, - strip_signature => 1, - current_user => Jifty->web->current_user, - ); - - my $mime_obj = make_mime_entity( - subject => $ARGS{'subject'}, - from => $ARGS{'from'}, - cc => $ARGS{'cc'}, - body => $sigless, - type => $ARGS{'content_type'}, - ); - - if ( $ARGS{'Attachments'} ) { - my $rv = $mime_obj->make_multipart; - Jifty->log->error("Couldn't make multipart message") - if !$rv || $rv !~ /^(?:DONE|ALREADY)$/; - - foreach ( values %{ $ARGS{'Attachments'} } ) { - unless ($_) { - Jifty->log->error("Couldn't add empty attachemnt"); - next; - } - $mime_obj->add_part($_); - } - } - - foreach my $argument (qw(encrypt sign)) { - $mime_obj->head->add( "X-RT-$argument" => $ARGS{$argument} ) - if defined $ARGS{$argument}; - } - - my %create_args = ( - type => $ARGS{'type'} || 'ticket', - queue => $ARGS{'queue'}, - owner => $ARGS{'owner'}, - - # note: name change - requestor => $ARGS{'requestors'}, - cc => $ARGS{'cc'}, - admin_cc => $ARGS{'admin_cc'}, - initial_priority => $ARGS{'initial_priority'}, - final_priority => $ARGS{'final_priority'}, - time_left => $ARGS{'time_left'}, - time_estimated => $ARGS{'time_estimated'}, - time_worked => $ARGS{'time_worked'}, - subject => $ARGS{'subject'}, - status => $ARGS{'status'}, - due => $due ? $due->iso : undef, - starts => $starts ? $starts->iso : undef, - mime_obj => $mime_obj - ); - - my @temp_squelch; - foreach my $type (qw(requestor cc admin_cc)) { - push @temp_squelch, map $_->address, Email::Address->parse( $create_args{$type} ) - if grep $_ eq $type || $_ eq ( $type . 's' ), - @{ $ARGS{'SkipNotification'} || [] }; - - } - - if (@temp_squelch) { - require RT::ScripAction::SendEmail; - RT::ScripAction::SendEmail->squelch_mail_to( RT::ScripAction::SendEmail->squelch_mail_to, @temp_squelch ); - } - - if ( $ARGS{'attach_tickets'} ) { - require RT::ScripAction::SendEmail; - RT::ScripAction::SendEmail->attach_tickets( - RT::ScripAction::SendEmail->attach_tickets, ref $ARGS{'AttachTickets'} - ? @{ $ARGS{'attach_tickets'} } - : ( $ARGS{'attach_tickets'} ) - ); - } - - foreach my $arg ( keys %ARGS ) { - next if $arg =~ /-(?:magic)$/; - - if ( $arg =~ /^object-RT::Model::Transaction--CustomField-/ ) { - $create_args{$arg} = $ARGS{$arg}; - } - - # object-RT::Model::Ticket--CustomField-3-values - elsif ( $arg =~ /^object-RT::Model::Ticket--CustomField-(\d+)/ ) { - my $cfid = $1; - - my $cf = RT::Model::CustomField->new( current_user => Jifty->web->current_user ); - $cf->load($cfid); - unless ( $cf->id ) { - Jifty->log->error( "Couldn't load custom field #" . $cfid ); - next; - } - - if ( $arg =~ /-Upload$/ ) { - $create_args{"custom_field-$cfid"} = _uploaded_file($arg); - next; - } - - my $type = $cf->type; - - my @values = (); - if ( ref $ARGS{$arg} eq 'ARRAY' ) { - @values = @{ $ARGS{$arg} }; - } elsif ( $type =~ /text/i ) { - @values = ( $ARGS{$arg} ); - } else { - @values = split /\r*\n/, $ARGS{$arg} || ''; - } - @values = grep length, map { - s/\r+\n/\n/g; - s/^\s+//; - s/\s+$//; - $_; - } - grep defined, @values; - - $create_args{"custom_field-$cfid"} = \@values; - } - } - - # turn new link lists into arrays, and pass in the proper arguments - my %map = ( - 'new-DependsOn' => 'DependsOn', - 'DependsOn-new' => 'DependedOnBy', - 'new-MemberOf' => 'Parents', - 'MemberOf-new' => 'Children', - 'new-RefersTo' => 'RefersTo', - 'RefersTo-new' => 'ReferredToBy', - ); - foreach my $key ( keys %map ) { - next unless $ARGS{$key}; - $create_args{ $map{$key} } = [ grep $_, split ' ', $ARGS{$key} ]; - - } - - my ( $id, $Trans, $ErrMsg ) = $Ticket->create(%create_args); - unless ($id) { - abort($ErrMsg); - } - - push( @Actions, split( "\n", $ErrMsg ) ); - unless ( $Ticket->current_user_has_right('ShowTicket') ) { - abort( "No permission to view newly Created ticket #" . $Ticket->id . "." ); - } - return ( $Ticket, @Actions ); - -} - - - =head2 load_ticket id Takes a ticket id as its only variable. if it's handed an array, it takes ----------------------------------------------------------------------- _______________________________________________ Rt-commit mailing list Rt-commit[at]lists.bestpractical.com http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit
|