1 package FS::TicketSystem::RT_Internal;
4 use vars qw( @ISA $DEBUG );
6 use FS::CGI qw(popurl);
7 use FS::TicketSystem::RT_Libs;
10 @ISA = qw( FS::TicketSystem::RT_Libs );
14 sub sql_num_customer_tickets {
15 "( select count(*) from tickets
16 join links on ( tickets.id = links.localbase )
17 where ( status = 'new' or status = 'open' or status = 'stalled' )
18 and target = 'freeside://freeside/cust_main/' || custnum
24 if ( $RT::URI::freeside::URL ) {
25 $RT::URI::freeside::URL. '/rt/';
27 'http://you_need_to_set_RT_URI_freeside_URL_in_SiteConfig.pm/';
32 #ShowConfigTab ModifySelf
34 my( $self, $session, $right ) = @_;
36 #return '' unless $conf->config('ticket_system');
37 return '' unless FS::Conf->new->config('ticket_system');
39 $self->_web_external_auth($session)
41 && $session->{'CurrentUser'};
43 $session->{'CurrentUser'}->HasRight( Right => $right,
44 Object => $RT::System );
47 #shameless false laziness w/rt/html/autohandler to get logged into RT from afar
48 sub _web_external_auth {
49 my( $self, $session ) = @_;
51 my $user = $FS::CurrentUser::CurrentUser->username;
53 $session->{'CurrentUser'} = RT::CurrentUser->new();
55 warn "loading RT user for $user\n"
58 $session->{'CurrentUser'}->Load($user);
60 if ( ! $session->{'CurrentUser'}->Id() ) {
62 # Create users on-the-fly
64 warn "can't load RT user for $user; auto-creating\n"
67 my $UserObj = RT::User->new( RT::CurrentUser->new('RT_System') );
69 my ( $val, $msg ) = $UserObj->Create(
70 %{ ref($RT::AutoCreate) ? $RT::AutoCreate : {} },
77 # now get user specific information, to better create our user.
79 = RT::Interface::Web::WebExternalAutoInfo($user);
81 # set the attributes that have been defined.
82 # FIXME: this is a horrible kludge. I'm sure there's something cleaner
83 foreach my $attribute (
85 'Signature', 'EmailAddress',
86 'PagerEmailAddress', 'FreeformContactInfo',
87 'Organization', 'Disabled',
88 'Privileged', 'RealName',
90 'EmailEncoding', 'WebEncoding',
91 'ExternalContactInfoId', 'ContactInfoSystem',
92 'ExternalAuthId', 'Gecos',
93 'HomePhone', 'WorkPhone',
94 'MobilePhone', 'PagerPhone',
95 'Address1', 'Address2',
101 #$m->comp( '/Elements/Callback', %ARGS,
102 # _CallbackName => 'NewUser' );
104 my $method = "Set$attribute";
105 $UserObj->$method( $new_user_info->{$attribute} )
106 if ( defined $new_user_info->{$attribute} );
108 $session->{'CurrentUser'}->Load($user);
112 # we failed to successfully create the user. abort abort abort.
113 delete $session->{'CurrentUser'};
115 die "can't auto-create RT user"; #an error message would be nice :/
116 #$m->abort() unless $RT::WebFallbackToInternalAuth;
117 #$m->comp( '/Elements/Login', %ARGS,
118 # Error => loc( 'Cannot create user: [_1]', $msg ) );
122 unless ( $session->{'CurrentUser'}->Id() ) {
123 delete $session->{'CurrentUser'};
125 die "can't auto-create RT user";
128 #if ($RT::WebExternalOnly) {
129 # $m->comp( '/Elements/Login', %ARGS,
130 # Error => loc('You are not an authorized user') );