The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CAS::DB - DBI wrapper which adds a few CAS specific methods.

VERSION

Version 0.40_02

SYNOPSIS

Connect to CAS database.

  use CAS::DB;
  my $dbh = CAS::DB->connectDB(\%params);
  

Though you shouldn't be connecting directly. Instead, load the CAS::Config data and get the dbh from there.

    use CAS::Config;
    my $HR_config = CAS::Config->load({CLIENT_ID => n});
    my $dbh = $HR_config->{dbh};

ABSTRACT

  Wraps the DBI module, extending the database handle with some CAS specific
  methods. This module is not intemded to be used directly - _config.pm
  makes the connection using paramters from the CAS.yaml configuration.

METHODS

connectDB

Wrapper for DBI->connect. Mainly does some configuration checking and if the connection attempt fails will try every three seconds ten times.

PARAMETERS:

user: Username to connect to the database with.

password: Password for user.

server: Type of database server. Defaults to mysql.

host: Host to connect to. Defaults to localhost.

allowed

Does the user have the requested permission on the indicated resource. Return value is true (actually returns the numeric value of the mask) if allowed, null (uundef) if not, 0 on error. Call $DBH->error to see any error messages.

This method will check for permissions by both user id ad group memberships. However it is important to remember that permission granted in any grants permission, and individual user permision is checked first.

PARAMS:

USER: The database ID of the user.

RESOURCE: The resource we are checking. Could be a database table, a file (such as a CGI or data archive), a port - whatever.

CLIENT: The client ID or domain from which this request is being made.

PERMISSION: This is the type of action you want to check if the user has permission for relative to the RESOURCE. The allowed values are read, modify, create and delete. Create refers to permision to create a new record which uses the refered to resource as a foreign key, or is under the refered resource 'tree'.

OPTIONS:

MASK: This is an integer mask of permissions to be checked for the specified RESOURCE. This can optionaly be used instead of PERMISSION, and is the only way to specify requests on more than one type of permission at the same time. The Values are 8 = read, 4 = modify, 2 = create, 1 = delete. To check for multiple permissions at the same time simply sum all the permissions you want to check. For example, to check for read and modify permision, provide 12 (8+4) as the value for MASK. MASK overides PERMISSION if both are specified.

MATCHKEY: A matchkey can be used to specify a specific element or key match required. For example, RESOURCE my specify a particular table in a database, with MATCHLEY specifying the primary key match required. Or if RESOURCE was a web page, MATCHKEY may indicate a specific form element.

Examples:

 # can place orders using fund 8887-009500
 my $can_do = $dbh->allowed({USER => 12345, RESOURCE => 'DNAcoreAdmin.Fund',
        MATCHKEY => '8887,009500', PERMISSION => create});

 # can view oligo OD QC tool CGI
 my $can_do = $dbh->allowed({RESOURCE => 'cgi-bin/synthesis/oligoOD',
        USER => 12345, PERMISSION => 'read'});

 # can delete results file
 my $can_do = $dbh->allowed({RESOURCE => 'sequencing/results/MK453GF67.seq',
        MASK => 1, USER => 12345);

To check the results unless($can_do) { if ($dbh->response_is('FORBIDDEN')) { # give user the bad news } # user does not have permission else { die "Problem checking permissions: $dbh->messages"; } # otherwise something went wrong } # user can't

client_info

Returns a hash reference with the info from the clients table.

PARAMETERS:

CLIENT_ID: The database ID of the client which is seeking to connect to CAS.

CLIENT_NAME: The name of the client which is seeking to connect to CAS.

CLIENT_DOMAIN: The domain of the client which is seeking to connect to CAS.

You can use any one. If more than one are defined, the first found in the order above is used.

client lookup on domain from SQCAS authorization my $client = 0; if ($HR_params->{CLIENT} =~ /^\d+$/) { $client = $HR_params->{CLIENT} } else { my $Qdomain = $self->{DBH}->quote($HR_params->{CLIENT}); $client = $self->{DBH}->selectrow_array("SELECT ID FROM Clients WHERE Domain = $Qdomain"); error("Problem fetching client ID with $Qdomain: " . $self->{DBH}->error) if $self->{DBH}->error;

                unless ($client) {
                        $self->_set_result(ERROR,"No client info provided.");
                        return undef;
                } # client required
        } # else look for domain in DB
        

enum_to_array

Sole argument is the 'DESC <Table_Name> <Field>' to be used. Sets error if not an enum field. Returns a list of the possible enum (or set) values.

AUTHOR

Sean P. Quinlan, <gilant at gmail.com>

BUGS

Please report any bugs or feature requests to bug-cas-db at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CAS. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

        perldoc CAS

The home page for this project is perl-cas.org.

The mailing list for Perl CAS can be found at: http://mail.perl-cas.org/mailman/listinfo/developers_perl-cas.org

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2006 Sean P. Quinlan, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.