X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTicketSystem%2FRT_Internal.pm;h=6ae8881a4a6f2d034899488aac6a818ce20f4443;hb=b5c4237a34aef94976bc343c8d9e138664fc3984;hp=d6b9c5298202b80ac0d1141f56cce827a3f94cb7;hpb=e19cf74e68ef0ebad22df8a4165a93b897d863b9;p=freeside.git diff --git a/FS/FS/TicketSystem/RT_Internal.pm b/FS/FS/TicketSystem/RT_Internal.pm index d6b9c5298..6ae8881a4 100644 --- a/FS/FS/TicketSystem/RT_Internal.pm +++ b/FS/FS/TicketSystem/RT_Internal.pm @@ -7,7 +7,6 @@ use MIME::Entity; use FS::UID qw(dbh); use FS::CGI qw(popurl); use FS::TicketSystem::RT_Libs; -use RT::CurrentUser; @ISA = qw( FS::TicketSystem::RT_Libs ); @@ -15,10 +14,10 @@ $DEBUG = 0; $me = '[FS::TicketSystem::RT_Internal]'; sub sql_num_customer_tickets { - "( select count(*) from tickets - join links on ( tickets.id = links.localbase ) - where ( status = 'new' or status = 'open' or status = 'stalled' ) - and target = 'freeside://freeside/cust_main/' || custnum + "( select count(*) from Tickets + join Links on ( Tickets.id = Links.LocalBase ) + where ( Status = 'new' or Status = 'open' or Status = 'stalled' ) + and Target = 'freeside://freeside/cust_main/' || custnum )"; } @@ -138,6 +137,11 @@ Cc: email address or arrayref of addresses Ticket message +=item mime_type + +MIME type to use for message. Defaults to text/plain. Specifying text/html +can be useful to use HTML markup in message. + =item custnum Customer number (see L) to associate with ticket. @@ -169,7 +173,7 @@ sub create_ticket { my $mimeobj = MIME::Entity->build( 'Data' => $param{'message'}, - 'Type' => 'text/plain', + 'Type' => ( $param{'mime_type'} || 'text/plain' ), ); my %ticket = ( @@ -211,6 +215,121 @@ sub create_ticket { $Ticket; } +=item get_ticket SESSION_HASHREF, OPTION => VALUE ... + +Class method. Retrieves a ticket. If there is an error, returns the scalar +error. Otherwise, currently returns a slightly tricky data structure containing +a list of the linked customers and each transaction's content, description, and +create time. + +Accepts the following options: + +=over 4 + +=item ticket_id + +The ticket id + +=back + +=cut + +sub get_ticket { + my($self, $session, %param) = @_; + + $session = $self->session($session); + + my $Ticket = RT::Ticket->new($session->{'CurrentUser'}); + my $ticketid = $Ticket->Load( $param{'ticket_id'} ); + return 'Could not load ticket' unless $ticketid; + + my @custs = (); + foreach my $link ( @{ $Ticket->Customers->ItemsArrayRef } ) { + my $cust = $link->Target; + push @custs, $1 if $cust =~ /\/(\d+)$/; + } + + my @txns = (); + my $transactions = $Ticket->Transactions; + while ( my $transaction = $transactions->Next ) { + my $t = { created => $transaction->Created, + content => $transaction->Content, + description => $transaction->Description, + type => $transaction->Type, + }; + push @txns, $t; + } + + { txns => [ @txns ], + custs => [ @custs ], + }; +} + + +=item correspond_ticket SESSION_HASHREF, OPTION => VALUE ... + +Class method. Correspond on a ticket. If there is an error, returns the scalar +error. Otherwise, returns the transaction id, error message, and +RT::Transaction object. + +Accepts the following options: + +=over 4 + +=item ticket_id + +The ticket id + +=item content + +Correspondence content + +=back + +=cut + +sub correspond_ticket { + my($self, $session, %param) = @_; + + $session = $self->session($session); + + my $Ticket = RT::Ticket->new($session->{'CurrentUser'}); + my $ticketid = $Ticket->Load( $param{'ticket_id'} ); + return 'Could not load ticket' unless $ticketid; + return 'No content' unless $param{'content'}; + + $Ticket->Correspond( Content => $param{'content'} ); +} + +=item queues SESSION_HASHREF [, ACL ] + +Retrieve a list of queues. Pass the name of an RT access control right, +such as 'CreateTicket', to return only queues on which the current user +has that right. Otherwise this will return all queues with the 'SeeQueue' +right. + +=cut + +sub queues { + my( $self, $session, $acl ) = @_; + $session = $self->session($session); + + my $showall = $acl ? 0 : 1; + my @result = (); + my $q = new RT::Queues($session->{'CurrentUser'}); + $q->UnLimit; + while (my $queue = $q->Next) { + if ($showall || $queue->CurrentUserHasRight($acl)) { + push @result, { + Id => $queue->Id, + Name => $queue->Name, + Description => $queue->Description, + }; + } + } + return map { $_->{Id} => $_->{Name} } @result; +} + #shameless false laziness w/RT::Interface::Web::AttemptExternalAuth # to get logged into RT from afar sub _web_external_auth { @@ -218,6 +337,9 @@ sub _web_external_auth { my $user = $FS::CurrentUser::CurrentUser->username; + eval 'use RT::CurrentUser;'; + die $@ if $@; + $session ||= {}; $session->{'CurrentUser'} = RT::CurrentUser->new();