Index: trunk/pstamp/scripts/pstampparse.pl
===================================================================
--- trunk/pstamp/scripts/pstampparse.pl	(revision 38194)
+++ trunk/pstamp/scripts/pstampparse.pl	(revision 38195)
@@ -200,10 +200,10 @@
 
 
+
+my $label_changed = 0;
+if (0) {
 # Adjust the label for requests coming in over the web upload interface
 # XXX: do this later based on the user information
-
-my $label_changed = 0;
 # We now use the access tabels to set the label.
-if (0) {
 if ($label and $label eq "WEB.UP") {
     my $lcname = lc($req_name);
@@ -234,22 +234,17 @@
 }
 
-# XXX: update these comments
-# product passed in is either one specific to the submitting pstampDataStore or the default
-# "pstampresults"
-# Here, we need to decide whether to change that based on email 
-# WE can't use label (yet) because the PSI cgi script sets it to PSI
-# Do we ever need to use label? Is it obsolete? Check test procedures.
-
+# based on the user's email address get the accessLevel, default label and data store product
 my $productForUser;
-my $labelForUser = $label;  # for now I pass the current label for use in hacking permissions for V1 requests
+my $labelForUser = $label;  # XXX: for now I pass the current label for use in hacking permissions for V1 requests.
 
 my $accessLevel = getUsersAccessLevel($email, \$labelForUser, \$productForUser);
 if ($accessLevel < 0) {
-    print STDERR "Data access is forbidden.\n";
+    print STDERR "Data access is forbidden for $email.\n";
     insertFakeJobForRow(undef, 0, $PSTAMP_NOT_AUTHORIZED);
 }
 
-# if the request came through the upload channel, change it to the user's specific label
+# if the request came through the request table upload channel, change it to the user's specific label
 # if any is known. Do we want to do this for any other channels?
+# requests from data store will have those values.
 if ($label and $label eq 'WEB.UP') {
     if ($labelForUser) {
@@ -259,8 +254,8 @@
 }
 
-# XXX: Think through when and if we change the product.
 # If the product is the system default, set it to the product for the user@domain. That way 
 # if the request came through a data store that target will be used.
-# We really only need to redirect the results with greater access level than the default
+# We really only need to redirect the results with greater access level than the default.
+# note that for most users productForUser will be undef so the default will be used.
 if ($productIsDefault or $product eq 'NULL') {
     if ($productForUser) {
@@ -297,4 +292,5 @@
 }
 
+# in these two error conditions we are done. The invoking script will finish up.
 if ($duplicate_req_name) {
     exit 0;
@@ -378,5 +374,5 @@
 
 if (($action eq 'LIST' or $mode eq "queue_job") and ($num_jobs eq 0)) {
-    # this should not happen. The function above is required to insert a fake job for any
+    # this should not happen. The processRow is required to insert a fake job for any
     # rows that did not yield any jobs.
     print STDERR "ERROR: zero jobs created for $req_name\n";
@@ -594,4 +590,13 @@
     my $rownum      = $row->{ROWNUM};
 
+    my $mjd_max;
+    my $adjustedDateCuts = adjustDateCuts($row, \$mjd_max);
+    if ($adjustedDateCuts and $mjd_max < 0) {
+        print STDERR "User is not authorized for data from this project.\n";
+        insertFakeJobForRow($row, 1, $PSTAMP_NOT_AUTHORIZED);
+        $num_jobs++;
+        return $num_jobs;
+    }
+
     # Since user can get unmagicked data "by coordinate" requests can go back in time
     # to dredge unusable data from the "dark days"...
@@ -608,9 +613,8 @@
         # if this user does not have unlimited access rights adjust the date cut
         # to avoid more recent data
-        my $mjd_max;
         # We do not adjust dates for stacks since they are not well defined enough.
         # We'll need to filter them by accessLevel during the lookup
         my $stage = $row->{IMG_TYPE};
-        if ($stage ne 'stack' and adjustDateCuts($row, \$mjd_max)) {
+        if ($stage ne 'stack' and $adjustedDateCuts) {
             # if lower limit was supplied by user we can leave the value alone
             if ($row->{MJD_MAX}) {
