Skip to content

Commit

Permalink
(empty commit message)
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.bestpractical.com/svn/jifty.org/jifty/trunk@6620 e84bef0a-9b06-0410-84ba-c4c9edb13aeb
  • Loading branch information
sartak committed Mar 17, 2009
1 parent 29d5a73 commit 88fa024
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 160 deletions.
19 changes: 10 additions & 9 deletions lib/Jifty/CurrentUser.pm
Expand Up @@ -77,9 +77,8 @@ sub _init {
my %args = (@_);

# Duck-typing to check to for a user class
my $user_class = Jifty->app_class({require => 0}, 'Model', 'User');
if (keys %args and UNIVERSAL::can($user_class, 'new') ) {
$self->user_object($user_class->new(current_user => $self));
if (keys %args and UNIVERSAL::can(Jifty->app_class('Model', 'User'), 'new') ) {
$self->user_object(Jifty->app_class('Model', 'User')->new(current_user => $self));
$self->user_object->load_by_cols(%args);
}

Expand Down Expand Up @@ -138,14 +137,16 @@ user_object, return that user's id.
sub id {
my $self = shift;

# This can be a hotspot, so we don't use method calls, instead
# directly accessing the value.

# Make sure we have a user object before trying to ID it
return $self->{user_object}->id if $self->{user_object};

if ($self->user_object) {
return ($self->user_object->id());
}

# No user object, return a null ID
return 0;
else {
return '0';
}

}

=head2 current_user
Expand Down
28 changes: 14 additions & 14 deletions lib/Jifty/Dispatcher.pm
Expand Up @@ -286,9 +286,8 @@ our @EXPORT = qw<
>;

our $Dispatcher;
our $Request;

sub request { $Request }
sub request { Jifty->web->request }
sub _ret (@);
sub under ($$@) { _ret @_ } # partial match at beginning of path component
sub before ($$@) { _ret @_ } # exact match on the path component
Expand All @@ -305,9 +304,9 @@ sub default ($$@) { _ret @_ } # set parameter if it's not yet set
sub set ($$@) { _ret @_ } # set parameter
sub del ($@) { _ret @_ } # remove parameter
sub get ($) {
my $val = $Request->template_argument( $_[0] );
my $val = request->template_argument( $_[0] );
return $val if defined $val;
return $Request->argument( $_[0] );
return request->argument( $_[0] );
}

sub _qualify ($@);
Expand Down Expand Up @@ -484,10 +483,9 @@ sub handle_request {
# do it once per request. But it's really, really painful when you
# do it often, as is the case with fragments
local $SIG{__DIE__} = 'DEFAULT';
local $Request = Jifty->web->request;

eval {
my $path = $Request->path;
my $path = Jifty->web->request->path;
utf8::downgrade($path); # Mason handle non utf8 path.
$Dispatcher->_do_dispatch( $path );
};
Expand Down Expand Up @@ -810,21 +808,21 @@ sub _do_set {
my ( $self, $key, $value ) = @_;
no warnings 'uninitialized';
$self->log->debug("Setting argument $key to $value");
$Request->template_argument($key, $value);
request->template_argument($key, $value);
}

sub _do_del {
my ( $self, $key ) = @_;
$self->log->debug("Deleting argument $key");
$Request->delete($key);
request->delete($key);
}

sub _do_default {
my ( $self, $key, $value ) = @_;
no warnings 'uninitialized';
$self->log->debug("Setting argument default $key to $value");
$Request->template_argument($key, $value)
unless defined $Request->argument($key) or defined $Request->template_argument($key);
request->template_argument($key, $value)
unless defined request->argument($key) or defined request->template_argument($key);
}

=head2 _do_dispatch [PATH]
Expand Down Expand Up @@ -921,8 +919,9 @@ sub _match {
elsif ( ref($cond) eq 'HASH' ) {
local $@;
my $rv = eval {
for my $key ( sort grep {length} keys %$cond )
for my $key ( sort keys %$cond )
{
next if $key eq '';
my $meth = "_match_$key";
$self->$meth( $cond->{$key} ) or return;
}
Expand Down Expand Up @@ -958,7 +957,7 @@ came in with that method.
sub _match_method {
my ( $self, $method ) = @_;
#$self->log->debug("Matching method ".request->request_method." against ".$method);
$Request->request_method eq uc($method);
lc( request->request_method ) eq lc($method);
}

=head2 _match_https
Expand Down Expand Up @@ -1256,8 +1255,8 @@ sub render_template {

# Handle parse errors
my $err = $@;
$self->log->fatal("View error: $err") if $err;
if ( $err and not eval { $err->isa('HTML::Mason::Exception::Abort') } ) {
$self->log->fatal("View error: $err") if $err;
if ($template eq '/errors/500') {
$self->log->warn("Can't render internal_error: $err");
# XXX Built-in static "oh noes" page?
Expand All @@ -1280,8 +1279,9 @@ sub render_template {
Jifty->web->_redirect( "/errors/500?J:C=" . $c->id );
} elsif ($err) {
Jifty->handler->buffer->pop while Jifty->handler->buffer->depth > $start_depth;
$self->_abort;
die $err;
}

}


Expand Down
2 changes: 0 additions & 2 deletions lib/Jifty/Everything.pm
Expand Up @@ -40,8 +40,6 @@ use Jifty::DateTime ();
use Jifty::Record ();
use Jifty::Collection ();
use Jifty::Action ();
use Jifty::Action::Autocomplete ();
use Jifty::Action::Redirect ();
use Jifty::Action::Record ();
use Jifty::Action::Record::Create ();
use Jifty::Action::Record::Update ();
Expand Down
5 changes: 0 additions & 5 deletions lib/Jifty/Handler.pm
Expand Up @@ -85,11 +85,6 @@ sub new {

$self->buffer(String::BufferStack->new( out_method => \&Jifty::View::out_method ));
$self->setup_view_handlers();
{
my $buffer = $self->buffer;
no warnings 'redefine';
*Jifty::Web::out = sub {shift;unshift @_,$buffer;goto \&String::BufferStack::append};
}
return $self;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/Jifty/Model/Session.pm
Expand Up @@ -58,9 +58,7 @@ are...
=cut

my $SUPERUSER;
sub current_user { return $SUPERUSER ||= Jifty->app_class('CurrentUser')->superuser }
sub current_user_can {return 1;}
sub current_user { return Jifty->app_class('CurrentUser')->superuser }

=head2 new_session_id
Expand Down
5 changes: 3 additions & 2 deletions lib/Jifty/Object.pm
Expand Up @@ -79,8 +79,9 @@ sub _get_current_user {
my $x = (CORE::caller( $depth++ ))[0];
my $caller_self = $DB::args[0];
next unless ref($caller_self); #skip class methods;
next unless my $s = $caller_self->can('current_user');
next unless my $t = $s->($caller_self);
next if $caller_self->isa('Jifty::Date');
next unless $caller_self->can('current_user');
next unless my $t = $caller_self->current_user;
next unless defined $t->id;
$cu = $t;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Jifty/Record.pm
Expand Up @@ -250,7 +250,7 @@ sub _guess_table_name {

# Add plugin table prefix if a plugin model
my $class = ref($self) ? ref($self) : $self;
my $app_plugin_root = Jifty->app_class({require => 0}, 'Plugin');
my $app_plugin_root = Jifty->app_class('Plugin');
if ( $class =~ /^(?:Jifty::Plugin::|$app_plugin_root)/ ) {

# Guess the plugin class name
Expand Down
2 changes: 1 addition & 1 deletion lib/Jifty/Request.pm
Expand Up @@ -118,7 +118,7 @@ sub fill {
my ($cgi) = @_;

# Store away request method
$self->request_method( uc $cgi->request_method );
$self->request_method( $cgi->request_method );

# Grab content type and posted data, if any
my $ct = $ENV{"CONTENT_TYPE"};
Expand Down
38 changes: 20 additions & 18 deletions lib/Jifty/Web.pm
Expand Up @@ -20,7 +20,7 @@ use base qw/Class::Accessor::Fast Class::Data::Inheritable Jifty::Object/;
use vars qw/$SERIAL @JS_INCLUDES/;

__PACKAGE__->mk_accessors(
qw(next_page force_redirect request response session temporary_current_user)
qw(next_page force_redirect request response session temporary_current_user _current_user _state_variables)
);

__PACKAGE__->mk_classdata($_)
Expand Down Expand Up @@ -241,24 +241,24 @@ sub current_user {
my $currentuser_obj = shift;
$self->session->set(
'user_id' => $currentuser_obj ? $currentuser_obj->id : undef );
$self->{current_user} = ( $currentuser_obj || undef );
$self->_current_user( $currentuser_obj || undef );
}

my $object;

if ( defined $self->temporary_current_user ) {
return $self->temporary_current_user;
} elsif ( defined $self->{current_user} ) {
return $self->{current_user};
} elsif ( defined $self->_current_user ) {
return $self->_current_user;
} elsif ( my $id = $self->session->get('user_id') ) {
$object = Jifty->app_class({require => 0}, "CurrentUser")->new( id => $id );
$object = Jifty->app_class("CurrentUser")->new( id => $id );
} elsif ( Jifty->config->framework('AdminMode')) {
$object = Jifty->app_class({require => 0}, "CurrentUser")->superuser;
$object = Jifty->app_class("CurrentUser")->superuser;
} else {
$object = Jifty->app_class({require => 0}, "CurrentUser")->new;
$object = Jifty->app_class("CurrentUser")->new;
}

$self->{current_user} = $object;
$self->_current_user($object);
return $object;
}

Expand Down Expand Up @@ -354,10 +354,11 @@ sub _validate_request_actions {
next if $request_action->has_run;
unless ( $self->request->just_validating ) {
unless ( Jifty->api->is_allowed( $request_action->class ) ) {
$self->log->warn( Carp::longmess("Attempt to call denied action '"
$self->log->warn( "Attempt to call denied action '"
. $request_action->class
. "'" ));
$self->log->error("NOTICE! A cross-site scripting security fix has been installed so that actions are now by default DENIED during GET requests. You must specifically whitelist safe actions using this in your dispatcher: before '*' => run { Jifty->api->allow('SafeAction') }; - We apologize for the inconvenience.") if $self->request->request_method eq "GET";
. "'" );
Carp::cluck;
$self->log->error("NOTICE! A cross-site scripting security fix has been installed so that actions are now by default DENIED during GET requests. You must specifically whitelist safe actions using this in your dispatcher: before '*' => run { Jifty->api->allow('SafeAction') }; - We apologize for the inconvenience.");
push @denied_actions, $request_action;
next;
}
Expand Down Expand Up @@ -529,9 +530,10 @@ sub new_action {
# Prepend the base path (probably "App::Action") unless it's there already
$class = Jifty->api->qualify($class);

my $loaded = Jifty::Util->require( $class );
# The implementation class is provided by the client, so this
# isn't a "shouldn't happen"
return unless Jifty::Util->require( $class );
return unless $loaded;

my $action;
# XXX TODO bullet proof
Expand Down Expand Up @@ -715,8 +717,8 @@ sub redirect {
my $request = Jifty::Request->new();
$request->add_state_variable( key => $_->key, value => $_->value )
for $self->request->state_variables;
$request->add_state_variable( key => $_, value => $self->{state_variables}->{$_} )
for keys %{ $self->{state_variables} };
$request->add_state_variable( key => $_, value => $self->_state_variables->{$_} )
for keys %{ $self->_state_variables };
for (@actions) {
my $new_action = $request->add_action(
moniker => $_->moniker,
Expand Down Expand Up @@ -1246,9 +1248,9 @@ sub set_variable {
my $value = shift;

if (!defined($value)) {
delete $self->{state_variables}{$name};
delete $self->_state_variables->{$name};
} else {
$self->{state_variables}{$name} = $value;
$self->_state_variables->{$name} = $value;
}

}
Expand All @@ -1265,7 +1267,7 @@ versions of Jifty

sub state_variables {
my $self = shift;
return %{ $self->{state_variables} };
return %{ $self->_state_variables };
}

=head3 clear_state_variables
Expand All @@ -1277,7 +1279,7 @@ Remove all the state variables to be serialized for the next request.
sub clear_state_variables {
my $self = shift;

$self->{state_variables} = {};
$self->_state_variables({});
}

=head2 REGIONS
Expand Down

0 comments on commit 88fa024

Please sign in to comment.