IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37998


Ignore:
Timestamp:
Mar 24, 2015, 12:12:45 PM (11 years ago)
Author:
bills
Message:

add a prototype function to return a user's data access rights
based on email domain or as a fallback the label

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstampparse.pl

    r37997 r37998  
    270270my $num_jobs = 0;
    271271
     272my $accessLevel = getUsersAccessLevel($email, $label);
     273if ($accessLevel < 0) {
     274    print STDERR "Data access forbidden.\n";
     275    insertFakeJobForRow(undef, 0, $PSTAMP_NOT_AUTHORIZED);
     276    exit 0;
     277}
     278
    272279foreach my $row (@$rows) {
    273280
     
    281288    $row->{job_num} = 0;
    282289    $row->{error_code} = 0;
     290    $row->{accessLevel} = $accessLevel;
    283291
    284292    $num_jobs += processRow($action, $row);
     
    11321140}
    11331141
     1142# Prototype function for setting access level.
     1143# XXX: Implement something more flexible using the database.
     1144sub getUsersAccessLevel {
     1145    my $email = shift;
     1146    my $label = shift;
     1147
     1148    my $level = -1;
     1149
     1150    if (!$email) {
     1151        # No email provided. Eventually this will be forbidden.
     1152        # For now in order to temporarily continue to support the version 1 request format
     1153        # set the access rights based on the assigned label.
     1154        if ($label eq 'IFA' or $label eq 'QUB' or $label =~ 'MOPS') {
     1155            $level = 2;
     1156        } else {
     1157            # access rights PS1 data only
     1158            $level = 1;
     1159        }
     1160    } else {
     1161        # we've got an email check the domain
     1162        my ($user, $domain) = split '@', $email;
     1163        if ($domain) {
     1164            $domain = lc($domain);
     1165            if ($domain eq 'ifa.hawaii.edu' or $domain eq 'qub.ac.uk') {
     1166                $level = 2;
     1167            } else {
     1168                # XXX check for special users
     1169                # access rights PS1 data only
     1170                $level = 1;
     1171            }
     1172        } else {
     1173            print STDERR "Error: $email is not a valid email address\n";
     1174        }
     1175    }
     1176
     1177    return $level;
     1178}
     1179
    11341180sub my_die
    11351181{
Note: See TracChangeset for help on using the changeset viewer.