[rt-users] Everybody group added as requestor

Terence Monteiro terence at deeproot.co.in
Fri May 30 23:58:20 EDT 2008


Jesse Vincent wrote:
>
> On May 30, 2008, at 2:07 AM, Terence Monteiro wrote:
>
>> Hello,
>>
>> I've been writing a Perl Catalyst application that uses the RT 
>> library to
>> create, work on and resolve RT tickets. I'm making a call to
>> RT::Ticket->create
>> to create a ticket, passing the Queue, Subject, Requestors, 
>> Attachments in a
>> hash.
>>
>> Yesterday, when the form was submitted with a user's email address as 
>> the
>> requestor, the Everybody group got added as the requestor for the ticket
>> that got created. I checked the transactions and found that no 
>> AddRequestor
>> transaction happened on the ticket, from which I deduce that the 
>> Everybody
>> group got added as requestor during ticket creation.
>>
>> Anyone has any idea how this could have happened?
>>
>
> It'd probably help if you posted your code...
>
I'm calling the send action of the create controller,

package tirt::Controller::Create;
use base 'Catalyst::Controller';

sub send : Local {
    # reads parameters and passes them to rthelper create
    my ( $self, $c ) = @_;

    my ( $Cc, $Subject, $Requestor, $Queue, $Priority, $ContentType, 
$Content ) =
    map { $c->req->params->{$_} }
        qw/cc subject   requestor   queue   priority   content_type  
content/;

    my ($id, $tid, $msg) = $c->forward('/rthelper/create_ticket', [
        Requestor => $Requestor,
        Cc => $Cc,
        Subject => $Subject,
        ContentType => $ContentType || 'text/html',
        Content => $Content,
        Queue => $Queue,
        Priority => $Priority,
        Attachments => $c->req->uploads ]); # calling RTHelper to create 
ticket
...
}

# other actions
...
1;

package tirt::Controller::RTHelper;
use base 'Catalyst::Controller';

sub create_ticket : Local {
    my $self = shift;
    my $c = shift;

    my %tkt_fields = ( @_ ); # the hash for arguments to RT::Ticket->create

    my $starts = RT::Date->new($c->session->{CurrentUser});
    $starts->SetToNow();
    $tkt_fields{Starts} = $starts;

    my $html = $tkt_fields{Content};
    delete $tkt_fields{Content};

    my $attachments = $tkt_fields{Attachments};
    delete $tkt_fields{Attachments};

    my $ctype = $tkt_fields{ContentType};
    delete $tkt_fields{ContentType};

    my $ent = $c->forward( '__make_mimeobj', [ $ctype,
        $html, $attachments ] );
   
    $tkt_fields{MIMEObj} = $ent;

    my $ticket = RT::Ticket->new($c->session->{CurrentUser});
    return $ticket->Create(%tkt_fields);
}

sub __make_mimeobj : Private {
    my ( $self, $c, $ctype, $content, $attachments ) = @_;

    my $msg;
    if ( $ctype =~ 'text/plain' ) {
        $msg = MIME::Entity->build(
            Type => 'text/plain',
            Data => $content);
    } else {
        my $text = HTML::FormatText->new()->format(
            HTML::TreeBuilder->new_from_content($content));
        $msg = MIME::Entity->build(Type => "multipart/alternative");
        $msg->attach(Type => 'text/plain', Data => $text);
        $msg->attach(Type => 'text/html', Data => $content);
    }

    $c->log->debug("\$attachments = $attachments, values " .
        join (", ", values(%$attachments)));
    unless ($attachments and values(%$attachments)) {
        return $msg;
    }

    my $ent;
    if ($msg->mime_type =~ m/^multipart/) {
        $ent = MIME::Entity->build(Type => "multipart/mixed");
        $ent->add_part($msg);
    } else {
        $ent = $msg;
    }

    foreach my $attach (values(%$attachments)) {
        $ent->attach(
            Type => $attach->type,
            Data => $attach->slurp,
            Filename => $attach->basename,
            Disposition => 'attachment'
        );
    }

    return $ent;
}

# other actions ...
1;




More information about the rt-users mailing list