-# $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/CurrentUser.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
-# (c) 1996-1999 Jesse Vincent <jesse@fsck.com>
-# This software is redistributable under the terms of the GNU GPL
-
+# BEGIN LICENSE BLOCK
+#
+# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
+#
+# (Except where explictly superceded by other copyright notices)
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# Unless otherwise specified, all modifications, corrections or
+# extensions to this work which alter its source code become the
+# property of Best Practical Solutions, LLC when submitted for
+# inclusion in the work.
+#
+#
+# END LICENSE BLOCK
=head1 NAME
RT::CurrentUser - an RT object representing the current user
=begin testing
-ok (require RT::TestHarness);
ok (require RT::CurrentUser);
=end testing
package RT::CurrentUser;
+
use RT::Record;
-@ISA= qw(RT::Record);
+use RT::I18N;
+use strict;
+use vars qw/@ISA/;
+@ISA= qw(RT::Record);
# {{{ sub _Init
$self->Load($Name);
}
- $self->_MyCurrentUser($self);
+ # $self->CurrentUser($self);
}
# }}}
# {{{ sub Create
sub Create {
- return (0, 'Permission Denied');
+ my $self = shift;
+ return (0, $self->loc('Permission Denied'));
}
# }}}
# {{{ sub Delete
sub Delete {
- return (0, 'Permission Denied');
+ my $self = shift;
+ return (0, $self->loc('Permission Denied'));
}
# }}}
sub UserObj {
my $self = shift;
- unless ($self->{'UserObj'}) {
use RT::User;
- $self->{'UserObj'} = RT::User->new($self);
- unless ($self->{'UserObj'}->Load($self->Id)) {
- $RT::Logger->err("Couldn't load ".$self->Id. "from the users database.\n");
+ my $user = RT::User->new($self);
+
+ unless ($user->Load($self->Id)) {
+ $RT::Logger->err($self->loc("Couldn't load [_1] from the users database.\n", $self->Id));
}
-
- }
- return ($self->{'UserObj'});
+ return ($user);
+}
+# }}}
+
+# {{{ sub PrincipalObj
+
+=head2 PrincipalObj
+
+ Returns this user's principal object. this is just a helper routine for
+ $self->UserObj->PrincipalObj
+
+=cut
+
+sub PrincipalObj {
+ my $self = shift;
+ return($self->UserObj->PrincipalObj);
+}
+
+
+# }}}
+
+
+# {{{ sub PrincipalId
+
+=head2 PrincipalId
+
+ Returns this user's principal Id. this is just a helper routine for
+ $self->UserObj->PrincipalId
+
+=cut
+
+sub PrincipalId {
+ my $self = shift;
+ return($self->UserObj->PrincipalId);
}
+
+
# }}}
+
# {{{ sub _Accessible
sub _Accessible {
my $self = shift;
Gecos => 'read',
RealName => 'read',
Password => 'neither',
+ Lang => 'read',
EmailAddress => 'read',
Privileged => 'read',
IsAdministrator => 'read'
sub LoadByEmail {
my $self = shift;
my $identifier = shift;
+
+ $identifier = RT::User::CanonicalizeEmailAddress(undef, $identifier);
$self->LoadByCol("EmailAddress",$identifier);
if ($identifier !~ /\D/) {
$self->SUPER::LoadById($identifier);
}
+
+ elsif (UNIVERSAL::isa($identifier,"RT::User")) {
+ # DWIM if they pass a user in
+ $self->SUPER::LoadById($identifier->Id);
+ }
else {
# This is a bit dangerous, we might get false authen if somebody
# uses ambigous userids or real names:
# }}}
-# {{{ Convenient ACL methods
-=head2 HasQueueRight
+# {{{ sub HasRight
+
+=head2 HasRight
-calls $self->UserObj->HasQueueRight with the arguments passed in
+calls $self->UserObj->HasRight with the arguments passed in
=cut
-sub HasQueueRight {
- my $self = shift;
- return ($self->UserObj->HasQueueRight(@_));
+sub HasRight {
+ my $self = shift;
+ return ($self->UserObj->HasRight(@_));
}
-=head2 HasSystemRight
+# }}}
-calls $self->UserObj->HasSystemRight with the arguments passed in
+# {{{ Localization
-=cut
+=head2 LanguageHandle
+
+Returns this current user's langauge handle. Should take a language
+specification. but currently doesn't
+
+=begin testing
+
+ok (my $cu = RT::CurrentUser->new('root'));
+ok (my $lh = $cu->LanguageHandle);
+ok ($lh != undef);
+ok ($lh->isa('Locale::Maketext'));
+ok ($cu->loc('TEST_STRING') eq "Concrete Mixer", "Localized TEST_STRING into English");
+ok ($lh = $cu->LanguageHandle('fr'));
+ok ($cu->loc('Before') eq "Avant", "Localized TEST_STRING into Frenc");
+
+=end testing
+
+=cut
+
+sub LanguageHandle {
+ my $self = shift;
+ if ( ( !defined $self->{'LangHandle'} )
+ || ( !UNIVERSAL::can( $self->{'LangHandle'}, 'maketext' ) )
+ || (@_) ) {
+ if ( (!$RT::SystemUser || $self->id == $RT::SystemUser->id() )) {
+ @_ = qw(en-US);
+ }
+
+ elsif ( $self->Lang ) {
+ push @_, $self->Lang;
+ }
+ $self->{'LangHandle'} = RT::I18N->get_handle(@_);
+ }
+
+ # Fall back to english.
+ unless ( $self->{'LangHandle'} ) {
+ die "We couldn't get a dictionary. Nye mogu naidti slovar. No puedo encontrar dictionario.";
+ }
+ return ( $self->{'LangHandle'} );
+}
+
+sub loc {
+ my $self = shift;
+ return '' if $_[0] eq '';
+
+ my $handle = $self->LanguageHandle;
+
+ if (@_ == 1) {
+ # pre-scan the lexicon hashes to return _AUTO keys verbatim,
+ # to keep locstrings containing '[' and '~' from tripping over Maketext
+ return $_[0] unless grep { exists $_->{$_[0]} } @{ $handle->_lex_refs };
+ }
+
+ return $handle->maketext(@_);
+}
+
+sub loc_fuzzy {
+ my $self = shift;
+ return '' if $_[0] eq '';
+ # XXX: work around perl's deficiency when matching utf8 data
+ return $_[0] if Encode::is_utf8($_[0]);
+ my $result = $self->LanguageHandle->maketext_fuzzy(@_);
-sub HasSystemRight {
- my $self = shift;
- return ($self->UserObj->HasSystemRight(@_));
+ return($result);
}
# }}}
-# {{{ sub HasRight
-=head2 HasSystemRight
+=head2 CurrentUser
-calls $self->UserObj->HasRight with the arguments passed in
+Return the current currentuser object
=cut
-sub HasRight {
- my $self = shift;
- return ($self->UserObj->HasRight(@_));
+sub CurrentUser {
+ my $self = shift;
+ return($self);
+
}
-# }}}
+eval "require RT::CurrentUser_Vendor";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/CurrentUser_Vendor.pm});
+eval "require RT::CurrentUser_Local";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/CurrentUser_Local.pm});
1;