[Rt-commit] r18588 - in rt/3.999/trunk: lib/RT
clkao at bestpractical.com
clkao at bestpractical.com
Wed Feb 25 11:48:18 EST 2009
Author: clkao
Date: Wed Feb 25 11:48:18 2009
New Revision: 18588
Modified:
rt/3.999/trunk/lib/RT/CurrentUser.pm
rt/3.999/trunk/lib/RT/Record.pm
rt/3.999/trunk/t/ticket/deferred_owner.t
Log:
allow current user coercion when calling model->new with
user object.
Modified: rt/3.999/trunk/lib/RT/CurrentUser.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/CurrentUser.pm (original)
+++ rt/3.999/trunk/lib/RT/CurrentUser.pm Wed Feb 25 11:48:18 2009
@@ -102,6 +102,25 @@
=cut
+sub new {
+ my $class = shift;
+ if ($#_ == 0 && ref $_[0] && ref $_[0] eq 'RT::Model::User') {
+ unshift @_, 'user_object';
+ }
+ $class->SUPER::new(@_);
+}
+
+sub _init {
+ my $self = shift;
+ my %args = @_;
+ if ($args{user_object}) {
+ $self->user_object($args{user_object});
+ return 1;
+ }
+
+ return $self->SUPER::_init(@_);
+}
+
sub create {
my $self = shift;
Jifty->log->error('RT::CurrentUser is read-only, RT::Model::User for manipulation');
Modified: rt/3.999/trunk/lib/RT/Record.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Record.pm (original)
+++ rt/3.999/trunk/lib/RT/Record.pm Wed Feb 25 11:48:18 2009
@@ -1629,4 +1629,23 @@
return RT->config->get('WebPath') . "/index.html?q=";
}
+=head2 _get_current_user
+
+This overridden version of C<_get_current_user> allows user object to
+be coerced into CurrentUser object during C<Model->new( current_user => $u)>.
+
+=cut
+
+sub _get_current_user {
+ my ($self, %args) = @_;
+ return if ( ref($self) && $self->current_user );
+
+ if ( my $cu = $args{'current_user'}) {
+ $args{'current_user'} = RT::CurrentUser->new(user_object => $cu)
+ if $cu->isa('RT::Model::User');
+ }
+
+ return $self->SUPER::_get_current_user(%args);
+}
+
1;
Modified: rt/3.999/trunk/t/ticket/deferred_owner.t
==============================================================================
--- rt/3.999/trunk/t/ticket/deferred_owner.t (original)
+++ rt/3.999/trunk/t/ticket/deferred_owner.t Wed Feb 25 11:48:18 2009
@@ -1,4 +1,4 @@
-use Test::More tests => 18;
+use Test::More tests => 19;
use strict;
use warnings;
@@ -57,6 +57,7 @@
},
);
my $ticket = RT::Model::Ticket->new(current_user => $tester );
+ isa_ok($ticket->current_user, 'RT::CurrentUser');
# tester is owner, owner has right to modify owned tickets,
# this right is required to set somebody as Admincc
my ( $tid, $txn_id, $msg ) = $ticket->create(
More information about the Rt-commit
mailing list