1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
51 RT::CurrentUser - an RT object representing the current user
58 my $current_user = RT::CurrentUser->new;
59 $current_user->Load(...);
61 my $current_user = RT::CurrentUser->new( $user_obj );
63 my $current_user = RT::CurrentUser->new( $address || $name || $id );
66 $current_user->UserObj->SetName('new_name');
71 B<Read-only> subclass of L<RT::User> class. Used to define the current
72 user. You should pass an instance of this class to constructors of
73 many RT classes, then the instance used to check ACLs and localize
78 See also L<RT::User> for a list of methods this class has.
82 Returns new CurrentUser object. Unlike all other classes of RT it takes
83 either subclass of C<RT::User> class object or scalar value that is
84 passed to Load method.
89 package RT::CurrentUser;
94 use base qw/RT::User/;
98 #The basic idea here is that $self->CurrentUser is always supposed
99 # to be a CurrentUser object. but that's hard to do when we're trying to load
100 # the CurrentUser object
106 $self->{'table'} = "Users";
108 if ( defined $User ) {
110 if ( UNIVERSAL::isa( $User, 'RT::User' ) ) {
111 $self->LoadById( $User->id );
113 elsif ( ref $User ) {
115 "RT::CurrentUser->new() called with a bogus argument: $User");
118 $self->Load( $User );
122 $self->_BuildTableAttributes;
126 =head2 Create, Delete and Set*
128 As stated above it's a subclass of L<RT::User>, but this class is read-only
129 and calls to these methods are illegal. Return 'permission denied' message
136 $RT::Logger->error('RT::CurrentUser is read-only, RT::User for manipulation');
137 return (0, $self->loc('Permission Denied'));
142 $RT::Logger->error('RT::CurrentUser is read-only, RT::User for manipulation');
143 return (0, $self->loc('Permission Denied'));
148 $RT::Logger->error('RT::CurrentUser is read-only, RT::User for manipulation');
149 return (0, $self->loc('Permission Denied'));
154 Returns the L<RT::User> object associated with this CurrentUser object.
161 my $user = RT::User->new( $self );
162 unless ( $user->LoadById( $self->Id ) ) {
163 $RT::Logger->error("Couldn't load " . $self->Id . " from the users database.");
168 sub _CoreAccessible {
170 Name => { 'read' => 1 },
171 Gecos => { 'read' => 1 },
172 RealName => { 'read' => 1 },
173 Lang => { 'read' => 1 },
174 Password => { 'read' => 0, 'write' => 0 },
175 EmailAddress => { 'read' => 1, 'write' => 0 }
182 Loads a User into this CurrentUser object.
183 Takes a unix username as its only argument.
189 return $self->LoadByCol( "Gecos", shift );
194 Loads a User into this CurrentUser object.
201 return $self->LoadByCol( "Name", shift );
204 =head2 LanguageHandle
206 Returns this current user's langauge handle. Should take a language
207 specification. but currently doesn't
213 if ( !defined $self->{'LangHandle'}
214 || !UNIVERSAL::can( $self->{'LangHandle'}, 'maketext' )
217 if ( my $lang = $self->Lang ) {
220 elsif ( $self->id && ($self->id == (RT->SystemUser->id||0) || $self->id == (RT->Nobody->id||0)) ) {
221 # don't use ENV magic for system users
225 $self->{'LangHandle'} = RT::I18N->get_handle(@_);
228 # Fall back to english.
229 unless ( $self->{'LangHandle'} ) {
230 die "We couldn't get a dictionary. Ne mogu naidti slovar. No puedo encontrar dictionario.";
232 return $self->{'LangHandle'};
237 return '' if !defined $_[0] || $_[0] eq '';
239 my $handle = $self->LanguageHandle;
242 # If we have no [_1] replacements, and the key does not appear
243 # in the lexicon, unescape (using ~) and return it verbatim, as
245 my $unescaped = $_[0];
246 $unescaped =~ s!~(.)!$1!g;
247 return $unescaped unless grep exists $_->{$_[0]}, @{ $handle->_lex_refs };
250 return $handle->maketext(@_);
255 return '' if !defined $_[0] || $_[0] eq '';
257 return $self->LanguageHandle->maketext_fuzzy( @_ );
262 Return the current currentuser object
270 sub CustomFieldLookupType {
274 RT::Base->_ImportOverlays();