3 =head1 NAME $RCSfile: Admin.pm,v $
5 Clearquest Admin - Provide access Clearquest AdminSession objects
13 Andrew DeFaria <Andrew@ClearSCM.com>
21 Wed Apr 18 09:59:47 PDT 2012
25 $Date: 2012/11/09 06:53:11 $
31 Provides an interface to the Clearquest AdminSession objects. These are for
32 dealing with objects in the schema, not the user database.
36 The Admin object allows you to create a session object associated with a schema
37 repository. This allows you to retrieve and modify information in a schema
38 repository. You must log into the Admin object as an admin user.
40 Functions are available to deal with users, groups, databases and schemas.
42 Note: Admin object needs to be filled out with more functions over time...
46 The following methods are available:
50 package Clearquest::Admin;
65 # Seed options from config file
66 my $config = $ENV{CQD_CONF} || dirname (__FILE__) . '/../../etc/cqdservice.conf';
68 croak "Unable to find config file $config" unless -r $config;
70 our %OPTS = GetConfig $config;
72 our $VERSION = '$Revision: 1.3 $';
73 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
75 # Override options if in the environment
76 $OPTS{CQD_HOST} = $ENV{CQD_HOST}
78 $OPTS{CQD_PORT} = $ENV{CQD_PORT}
80 $OPTS{CQD_MULTITHREADED} = $ENV{CQD_MULTITHREADED}
81 if defined $ENV{CQD_MULTITHREADED};
82 $OPTS{CQD_DATABASE} = $ENV{CQD_DATABASE}
83 if $ENV{CQD_DATABASE};
84 $OPTS{CQD_USERNAME} = $ENV{CQD_USERNAME}
85 if $ENV{CQD_USERNAME};
86 $OPTS{CQD_PASSWORD} = $ENV{CQD_PASSWORD}
87 if $ENV{CQD_PASSWORD};
88 $OPTS{CQD_DBSET} = $ENV{CQD_DBSET}
92 my ($self, $loginname) = @_;
98 Returns a user object for the specified user or undef.
102 =for html <blockquote>
108 The $loginname to retrieve the user object for
112 =for html </blockquote>
116 =for html <blockquote>
126 =for html </blockquote>
130 return $self->{session}->GetUser ($loginname);
134 my ($self, $loginname) = @_;
138 =head2 userActive ($)
140 Returns a true if user is active
144 =for html <blockquote>
150 The $loginname to see if active
154 =for html </blockquote>
158 =for html <blockquote>
162 =item 1 if true, 0 if false
166 =for html </blockquote>
170 my $user = $self->getUser ($loginname);
173 return $user->GetActive;
179 sub userActivate ($) {
180 my ($self, $loginname) = @_;
184 =head2 userActivate ($)
186 Activates a user if they were inactive
190 =for html <blockquote>
196 The $loginname to activate
200 =for html </blockquote>
204 =for html <blockquote>
212 =for html </blockquote>
216 unless ($self->activeUser ($logname)) {
217 my $user = $self->getUser ($loginname);
225 sub userActivate ($) {
226 my ($self, $loginname) = @_;
230 =head2 userInactivate ($)
232 Inactivates a user if they were active
236 =for html <blockquote>
242 The $loginname to inactivate
246 =for html </blockquote>
250 =for html <blockquote>
258 =for html </blockquote>
262 if ($self->activeUser ($logname)) {
263 my $user = $self->getUser ($loginname);
272 my ($class, $username, $password, $dbset) = @_;
274 my $self = bless {}, $class;
276 if (ref $username eq 'HASH') {
277 my %parms = %$username;
279 $self->{username} = $parms{username};
280 $self->{password} = $parms{password};
281 $self->{dbset} = $parms{dbset};
283 $self->{username} = $username;
284 $self->{password} = $password;
285 $self->{dbset} = $dbset;
295 =head2 connect (;$$$)
297 Connect to the Clearquest schema database. You can supply parameters such as
298 username, password, etc and they will override any passed to
299 Clearquest::Admin::new (or those coming from ../etc/cq.conf)
303 =for html <blockquote>
309 Username to use to connect to the schema database
313 Password to use to connect to the schema database
317 Database set to connect to (Default: Connect to the default dbset)
321 =for html </blockquote>
325 =for html <blockquote>
333 =for html </blockquote>
337 my ($self, $username, $password, $dbset) = @_;
339 $self->{username} = $username if $username;
340 $self->{password} = $password if $password;
341 $self->{database} = $database if $database;
342 $self->{dbset} = $dbset if $dbset;
344 $self->{session} = CQAdminSession::Build;
346 # TODO: Should handle failures better
347 $self->{session}->($self->{username},
350 $self->{loggedin} = 1;
352 return $self->{loggedin};
362 Returns 1 if we are currently connected to a Clearquest Admin Schema Database
366 =for html <blockquote>
374 =for html </blockquote>
378 =for html <blockquote>
382 =item 1 if logged in - 0 if not
386 =for html </blockquote>
390 return $self->{loggedin};
400 Disconnect from Clearquest Admin Schema Database
404 =for html <blockquote>
412 =for html </blockquote>
416 =for html <blockquote>
424 =for html </blockquote>
428 CQAdminSession::Unbuild ($self->{session});
430 undef $self->{session};
432 $self->{loggedin} = 0;
443 =head1 CONFIGURATION AND ENVIRONMENT
445 DEBUG: If set then $debug is set to this level.
447 VERBOSE: If set then $verbose is set to this level.
449 TRACE: If set then $trace is set to this level.
457 L<File::Basename|File::Basename>
461 L<IO::Socket|IO::Socket>
463 L<Net::hostent|Net::hostent>
467 =head2 ClearSCM Perl Modules
480 <a href="http://clearscm.com/php/cvs_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
481 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Display.pm">Display</a><br>
482 <a href="http://clearscm.com/php/cvs_man.php?file=lib/GetConfig.pm">GetConf</a><br>
489 =head1 BUGS AND LIMITATIONS
491 There are no known bugs in this module.
493 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
495 =head1 LICENSE AND COPYRIGHT
497 Copyright (c) 2011, ClearSCM, Inc. All rights reserved.