[Rt-commit] r5098 - in rt/branches/3.7-EXPERIMENTAL: .
ruz at bestpractical.com
ruz at bestpractical.com
Tue Apr 25 09:24:52 EDT 2006
Author: ruz
Date: Tue Apr 25 09:24:51 2006
New Revision: 5098
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/html/autohandler
Log:
r2322 at cubic-pc (orig r4922): jesse | 2006-03-31 05:41:00 +0400
r10630 at hualien: jesse | 2006-03-31 10:40:29 +0900
* perltidied the autohandler per Jim Meyer.
Modified: rt/branches/3.7-EXPERIMENTAL/html/autohandler
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/autohandler (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/autohandler Tue Apr 25 09:24:51 2006
@@ -53,7 +53,8 @@
$RT::Handle->LogSQLStatements(1);
}
-local *session unless $m->is_subrequest; # avoid reentrancy, as suggested by masonbook
+# avoid reentrancy, as suggested by masonbook
+local *session unless $m->is_subrequest;
# Disable AutoFlush using an attribute
if ( $m->request_comp->attr_exists('AutoFlush') ) {
@@ -61,16 +62,32 @@
}
%ARGS = map {
- # if they've passed multiple values, they'll be an array. if they've
+
+ # if they've passed multiple values, they'll be an array. if they've
# passed just one, a scalar whatever they are, mark them as utf8
my $type = ref($_);
- (!$type)
- ? Encode::is_utf8($_) ? $_ : Encode::decode(utf8 => $_, Encode::FB_PERLQQ) :
- ($type eq 'ARRAY')
- ? [ map { (ref($_) or Encode::is_utf8($_)) ? $_ : Encode::decode(utf8 => $_, Encode::FB_PERLQQ) } @$_ ] :
- ($type eq 'HASH')
- ? { map { (ref($_) or Encode::is_utf8($_)) ? $_ : Encode::decode(utf8 => $_, Encode::FB_PERLQQ) } %$_ } : $_
- } %ARGS;
+ ( !$type )
+ ? Encode::is_utf8($_)
+ ? $_
+ : Encode::decode( utf8 => $_, Encode::FB_PERLQQ )
+ : ( $type eq 'ARRAY' )
+ ? [
+ map {
+ ( ref($_) or Encode::is_utf8($_) )
+ ? $_
+ : Encode::decode( utf8 => $_, Encode::FB_PERLQQ )
+ } @$_
+ ]
+ : ( $type eq 'HASH' )
+ ? {
+ map {
+ ( ref($_) or Encode::is_utf8($_) )
+ ? $_
+ : Encode::decode( utf8 => $_, Encode::FB_PERLQQ )
+ } %$_
+ }
+ : $_
+} %ARGS;
# This code canonicalizes time inputs in hours into minutes
foreach my $field ( keys %ARGS ) {
@@ -79,7 +96,7 @@
$ARGS{$local} =~ s|\b (?: (\d+) \s+ )? (\d+)/(\d+) \b
|$1 + $3 ? $2 / $3 : 0
|xe;
- if ($ARGS{$field} && $ARGS{$field} =~ /hours/i) {
+ if ( $ARGS{$field} && $ARGS{$field} =~ /hours/i ) {
$ARGS{$local} *= 60;
}
delete $ARGS{$field};
@@ -87,9 +104,9 @@
$m->{'rt_base_time'} = [ Time::HiRes::gettimeofday() ];
-$m->comp('/Elements/SetupSessionCookie', %ARGS);
+$m->comp( '/Elements/SetupSessionCookie', %ARGS );
-unless ($session{'CurrentUser'} && $session{'CurrentUser'}->Id) {
+unless ( $session{'CurrentUser'} && $session{'CurrentUser'}->Id ) {
$session{'CurrentUser'} = RT::CurrentUser->new;
}
@@ -110,77 +127,92 @@
my $orig_user = $user;
$user = RT::Interface::Web::WebCanonicalizeInfo();
+ $session{'CurrentUser'} = RT::CurrentUser->new();
my $load_method = RT->Config->Get('WebExternalGecos') ? 'LoadByGecos' : 'Load';
- if ($^O eq 'MSWin32' and RT->Config->Get('WebExternalGecos')) {
+ if ( $^O eq 'MSWin32' and RT->Config->Get('WebExternalGecos') ) {
my $NodeName = Win32::NodeName();
$user =~ s/^\Q$NodeName\E\\//i;
}
$session{'CurrentUser'} = RT::CurrentUser->new();
$session{'CurrentUser'}->$load_method($user);
-
+
if ( RT->Config->Get('WebExternalAuto') && !$session{'CurrentUser'}->Id ) {
+
# Create users on-the-fly
my $UserObj = RT::User->new( $RT::SystemUser );
my ($val, $msg) = $UserObj->Create(
- %{ref(RT->Config->Get('AutoCreate')) ? RT->Config->Get('AutoCreate') : {}},
- Name => $user,
- Gecos => $user,
- );
+ %{ ref RT->Config->Get('AutoCreate') ? RT->Config->Get('AutoCreate') : {} },
+ Name => $user,
+ Gecos => $user,
+ );
- if ($val) {
+ if ( $val ) {
# now get user specific information, to better create our user.
- my $new_user_info = RT::Interface::Web::WebExternalAutoInfo($user);
+ my $new_user_info
+ = RT::Interface::Web::WebExternalAutoInfo($user);
# set the attributes that have been defined.
# FIXME: this is a horrible kludge. I'm sure there's something cleaner
- foreach my $attribute ('Name', 'Comments', 'Signature', 'EmailAddress',
- 'PagerEmailAddress', 'FreeformContactInfo',
- 'Organization', 'Disabled', 'Privileged',
- 'RealName', 'NickName', 'Lang', 'EmailEncoding',
- 'WebEncoding', 'ExternalContactInfoId',
- 'ContactInfoSystem', 'ExternalAuthId', 'Gecos',
- 'HomePhone', 'WorkPhone', 'MobilePhone',
- 'PagerPhone', 'Address1', 'Address2', 'City',
- 'State', 'Zip', 'Country') {
- # XXX: should it be here? May be we need to move it out of the block?
- $m->comp('/Elements/Callback', %ARGS, _CallbackName => 'NewUser');
+ foreach my $attribute (
+ 'Name', 'Comments',
+ 'Signature', 'EmailAddress',
+ 'PagerEmailAddress', 'FreeformContactInfo',
+ 'Organization', 'Disabled',
+ 'Privileged', 'RealName',
+ 'NickName', 'Lang',
+ 'EmailEncoding', 'WebEncoding',
+ 'ExternalContactInfoId', 'ContactInfoSystem',
+ 'ExternalAuthId', 'Gecos',
+ 'HomePhone', 'WorkPhone',
+ 'MobilePhone', 'PagerPhone',
+ 'Address1', 'Address2',
+ 'City', 'State',
+ 'Zip', 'Country'
+ )
+ {
+ $m->comp( '/Elements/Callback', %ARGS,
+ _CallbackName => 'NewUser' );
my $method = "Set$attribute";
- $UserObj->$method($new_user_info->{$attribute})
- if( defined $new_user_info->{$attribute} );
- }
+ $UserObj->$method( $new_user_info->{$attribute} )
+ if defined $new_user_info->{$attribute};
+ }
$session{'CurrentUser'}->Load($user);
}
else {
+
# we failed to successfully create the user. abort abort abort.
delete $session{'CurrentUser'};
$m->abort unless RT->Config->Get('WebFallbackToInternalAuth');
- $m->comp('/Elements/Login', %ARGS,
- Error=> loc('Cannot create user: [_1]', $msg));
+ $m->comp( '/Elements/Login', %ARGS,
+ Error => loc( 'Cannot create user: [_1]', $msg ) );
}
}
-
+
unless ( $session{'CurrentUser'}->Id ) {
delete $session{'CurrentUser'};
$user = $orig_user;
- unless ( RT->Config->Get('WebFallbackToInternalAuth') ) {
- $m->comp('/Elements/Login', %ARGS,
- Error=> loc('You are not an authorized user'));
+
+ if ( RT->Config->Get('WebExternalOnly') ) {
+ $m->comp( '/Elements/Login', %ARGS,
+ Error => loc('You are not an authorized user') );
$m->abort();
}
}
}
elsif (RT->Config->Get('WebFallbackToInternalAuth')) {
- unless (defined($session{'CurrentUser'})) {
- $m->comp('/Elements/Login', %ARGS,
- Error=> loc('You are not an authorized user'));
- $m->abort();
+ unless ( defined $session{'CurrentUser'} ) {
+ $m->comp( '/Elements/Login', %ARGS,
+ Error => loc('You are not an authorized user') );
+ $m->abort();
}
- } else {
+ }
+ else {
+
# WebExternalAuth is set, but we don't have a REMOTE_USER. abort
# XXX: we must return AUTH_REQUIRED status or we fallback to
# internal auth here too.
@@ -192,7 +224,7 @@
unless $session{'CurrentUser'} && $session{'CurrentUser'}->Id;
# Process per-page authentication callbacks
-$m->comp('/Elements/Callback', %ARGS, _CallbackName => 'Auth');
+$m->comp( '/Elements/Callback', %ARGS, _CallbackName => 'Auth' );
delete $session{'CurrentUser'}
unless $session{'CurrentUser'} && $session{'CurrentUser'}->Id;
@@ -211,7 +243,8 @@
$m->abort;
}
$session{'CurrentUser'} = $user_obj;
- $RT::Logger->info("Successful login for $user from $ENV{'REMOTE_ADDR'}");
+ $RT::Logger->info(
+ "Successful login for $user from $ENV{'REMOTE_ADDR'}");
}
# if no credentials then show him login page
else {
@@ -228,9 +261,12 @@
unless ( $session{'CurrentUser'}->Privileged ) {
# if the user is trying to access a ticket, redirect them
- if ( $m->request_comp->path =~ '^(/+)Ticket/Display.html' && $ARGS{'id'} ) {
+ if ( $m->request_comp->path =~ '^(/+)Ticket/Display.html'
+ && $ARGS{'id'} )
+ {
$m->comp("/SelfService/Display.html", %ARGS);
}
+
# otherwise, drop the user at the SelfService default page
elsif ( $m->base_comp->path !~ '^(/+)SelfService/' ) {
$m->comp('/SelfService/index.html');
@@ -250,17 +286,21 @@
my @log = $RT::Handle->SQLStatementLog;
$RT::Handle->ClearSQLStatementLog;
for my $stmt (@log) {
- my ($time, $sql, $bind, $duration) = @{$stmt};
+ my ( $time, $sql, $bind, $duration ) = @{$stmt};
my @bind;
- if (ref $bind) {
+ if ( ref $bind ) {
@bind = @{$bind};
- } else {
+ }
+ else {
+
# Older DBIx-SB
$duration = $bind;
}
- $RT::Logger->log( level => RT->Config->Get('StatementLog'),
- message => "SQL(".sprintf("%.2f",$duration)."s): $sql;" . (@bind ? " [ bound values: @{[map{qq|'$_'|} @bind]} ]" : "")
- );
+ $RT::Logger->log(
+ level => RT->Config->Get('StatementLog'),
+ message => "SQL(" . sprintf( "%.2f", $duration ) . "s): $sql;"
+ . ( @bind ? " [ bound values: @{[map{qq|'$_'|} @bind]} ]" : "" )
+ );
}
}
More information about the Rt-commit
mailing list