[Rt-commit] r8182 - rt/branches/3.6-RELEASE/lib/RT
ruz at bestpractical.com
ruz at bestpractical.com
Tue Jul 17 07:11:13 EDT 2007
Author: ruz
Date: Tue Jul 17 07:11:12 2007
New Revision: 8182
Modified:
rt/branches/3.6-RELEASE/lib/RT/Base.pm
Log:
::Base::CurrentUser
* allow passing RT::User as argument
* check that the object is really RT::CurrentUser
or its sub-class
* verbose error message
* on error return undef instead of 0(zero)
Modified: rt/branches/3.6-RELEASE/lib/RT/Base.pm
==============================================================================
--- rt/branches/3.6-RELEASE/lib/RT/Base.pm (original)
+++ rt/branches/3.6-RELEASE/lib/RT/Base.pm Tue Jul 17 07:11:12 2007
@@ -72,8 +72,10 @@
=head2 CurrentUser
If called with an argument, sets the current user to that user object.
-This will affect ACL decisions, etc.
-Returns the current user
+This will affect ACL decisions, etc. The argument can be either
+L<RT::CurrentUser> or L<RT::User> object.
+
+Returns the current user object of L<RT::CurrentUser> class.
=cut
@@ -82,18 +84,30 @@
if (@_) {
$self->{'original_user'} = $self->{'user'};
- $self->{'user'} = shift;
+ my $current_user = $_[0];
+ if ( ref $current_user eq 'RT::User' ) {
+ $self->{'user'} = new RT::CurrentUser;
+ $self->{'user'}->Load( $current_user->id );
+ } else {
+ $self->{'user'} = $current_user;
+ }
# We need to weaken the CurrentUser ($self->{'user'}) reference
# if the object in question is the currentuser object.
# This avoids memory leaks.
- Scalar::Util::weaken($self->{'user'}) if (ref($self->{'user'}) &&
- $self->{'user'} == $self );
+ Scalar::Util::weaken($self->{'user'})
+ if ref $self->{'user'} && $self->{'user'} == $self;
}
- unless ( ref( $self->{'user'}) ) {
- $RT::Logger->err( "$self was created without a CurrentUser\n" . Carp::cluck() );
- return (0);
+ unless ( ref $self->{'user'} && $self->{'user'}->isa('RT::CurrentUser') ) {
+ my $msg = "$self was created without a CurrentUser."
+ ." Any RT object which is subclass of RT::Base must be created"
+ ." with a RT::CurrentUser or a RT::User obejct as the first argument.";
+ $msg .= "\n". Carp::cluck() if @_;
+
+ $RT::Logger->err( $msg );
+ return $self->{'user'} = undef;
}
+
return ( $self->{'user'} );
}
More information about the Rt-commit
mailing list