[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 13 May 2002 09:26:29 -0000


This is a MIME encoded message

--albertel1021281989
Content-Type: text/plain

albertel		Mon May 13 05:26:29 2002 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - &EXT() takes optional $udom and $uname args, it they aren't specified 
     it checks with &Apache::lonxml::whichuser() to figure out who we are 
     running for 
  
  - However user.role
            user.course 
            user.access currently ignore this information 
        
       (user.access needs a &allowed to support this kind of user shifting)
       (user.course is only broken if the current user's current role is 
                    not the specific course they are asking about, this 
                    arguably shouldn't happen, and maybe should just 
                    explicitly return a blank when it happens)
       (user.role will return incorrect information since the requesting 
                  user will generally have a different role from what the 
                  user would have)
  
  
--albertel1021281989
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20020513052629.txt"

Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.217 loncom/lonnet/perl/lonnet.pm:1.218
--- loncom/lonnet/perl/lonnet.pm:1.217	Sat May 11 16:42:00 2002
+++ loncom/lonnet/perl/lonnet.pm	Mon May 13 05:26:29 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.217 2002/05/11 20:42:00 harris41 Exp $
+# $Id: lonnet.pm,v 1.218 2002/05/13 09:26:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2196,8 +2196,19 @@
 # --------------------------------------------------------- Value of a Variable
 
 sub EXT {
-    my ($varname,$symbparm)=@_;
+    my ($varname,$symbparm,$udom,$uname)=@_;
+
     unless ($varname) { return ''; }
+
+    #get real user name/domain, courseid and symb
+    my $courseid;
+    if (!($uname && $udom)) {
+      (my $cursymb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
+      if (!$symbparm) {	$symbparm=$cursymb; }
+    } else {
+	$courseid=$ENV{'request.course.id'};
+    }
+
     my ($realm,$space,$qualifier,@therest)=split(/\./,$varname);
     my $rest;
     if ($therest[0]) {
@@ -2212,19 +2223,28 @@
     if ($realm eq 'user') {
 # --------------------------------------------------------------- user.resource
 	if ($space eq 'resource') {
-	    my %restored=&restore();
+	    my %restored=&restore(undef,undef,$udom,$uname);
             return $restored{$qualifierrest};
 # ----------------------------------------------------------------- user.access
         } elsif ($space eq 'access') {
+	    # FIXME - not supporting calls for a specific user
             return &allowed($qualifier,$rest);
 # ------------------------------------------ user.preferences, user.environment
         } elsif (($space eq 'preferences') || ($space eq 'environment')) {
-            return $ENV{join('.',('environment',$qualifierrest))};
+	    if (($uname eq $ENV{'user.name'}) &&
+		($udom eq $ENV{'user.domain'})) {
+		return $ENV{join('.',('environment',$qualifierrest))};
+	    } else {
+		my %returnhash=&userenvironment($udom,$uname,$qualifierrest);
+		return $returnhash{$qualifierrest};
+	    }
 # ----------------------------------------------------------------- user.course
         } elsif ($space eq 'course') {
+	    # FIXME - not supporting calls for a specific user
             return $ENV{join('.',('request.course',$qualifier))};
 # ------------------------------------------------------------------- user.role
         } elsif ($space eq 'role') {
+	    # FIXME - not supporting calls for a specific user
             my ($role,$where)=split(/\./,$ENV{'request.role'});
             if ($qualifier eq 'value') {
 		return $role;
@@ -2233,10 +2253,10 @@
             }
 # ----------------------------------------------------------------- user.domain
         } elsif ($space eq 'domain') {
-            return $ENV{'user.domain'};
+            return $udom;
 # ------------------------------------------------------------------- user.name
         } elsif ($space eq 'name') {
-            return $ENV{'user.name'};
+            return $uname;
 # ---------------------------------------------------- Any other user namespace
         } else {
             my $item=($rest)?$qualifier.'.'.$rest:$qualifier;
@@ -2253,107 +2273,101 @@
         }
     } elsif ($realm eq 'course') {
 # ---------------------------------------------------------- course.description
-        return $ENV{'course.'.$ENV{'request.course.id'}.'.'.
-                              $spacequalifierrest};
+        return $ENV{'course.'.$courseid.'.'.$spacequalifierrest};
     } elsif ($realm eq 'resource') {
-       if ($ENV{'request.course.id'}) {
 
-#	   print '<br>'.$space.' - '.$qualifier.' - '.$spacequalifierrest;
+	if ($courseid eq $ENV{'request.course.id'}) {
 
+	    #print '<br>'.$space.' - '.$qualifier.' - '.$spacequalifierrest;
 
 # ----------------------------------------------------- Cascading lookup scheme
-         my $symbp;
-         if ($symbparm) {
-            $symbp=$symbparm;
-	 } else {
-            $symbp=&symbread();
-         }            
-         my $mapp=(split(/\_\_\_/,$symbp))[0];
-
-         my $symbparm=$symbp.'.'.$spacequalifierrest;
-         my $mapparm=$mapp.'___(all).'.$spacequalifierrest;
-
-         my $seclevel=
-            $ENV{'request.course.id'}.'.['.
-		$ENV{'request.course.sec'}.'].'.$spacequalifierrest;
-         my $seclevelr=
-            $ENV{'request.course.id'}.'.['.
-		$ENV{'request.course.sec'}.'].'.$symbparm;
-         my $seclevelm=
-            $ENV{'request.course.id'}.'.['.
-		$ENV{'request.course.sec'}.'].'.$mapparm;
-
-         my $courselevel=
-            $ENV{'request.course.id'}.'.'.$spacequalifierrest;
-         my $courselevelr=
-            $ENV{'request.course.id'}.'.'.$symbparm;
-         my $courselevelm=
-            $ENV{'request.course.id'}.'.'.$mapparm;
+	    if (!$symbparm) { $symbparm=&symbread(); }
+	    my $symbp=$symbparm;
+	    my $mapp=(split(/\_\_\_/,$symbp))[0];
+
+	    my $symbparm=$symbp.'.'.$spacequalifierrest;
+	    my $mapparm=$mapp.'___(all).'.$spacequalifierrest;
+
+	    my $section;
+	    if (($ENV{'user.name'} eq $uname) &&
+		($ENV{'user.domain'} eq $udom)) {
+		$section={'request.course.sec'};
+	    } else {
+		$section=&usection($udom,$uname,$courseid);
+	    }
 
-# ----------------------------------------------------------- first, check user
-         my %resourcedata=get('resourcedata',
-                           [$courselevelr,$courselevelm,$courselevel]);
-         if (($resourcedata{$courselevelr}!~/^error\:/) &&
-             ($resourcedata{$courselevelr}!~/^con_lost/)) {
-
-         if ($resourcedata{$courselevelr}) { 
-            return $resourcedata{$courselevelr}; }
-         if ($resourcedata{$courselevelm}) { 
-            return $resourcedata{$courselevelm}; }
-         if ($resourcedata{$courselevel}) { return $resourcedata{$courselevel}; }
+	    my $seclevel=$courseid.'.['.$section.'].'.$spacequalifierrest;
+	    my $seclevelr=$courseid.'.['.$section.'].'.$symbparm;
+	    my $seclevelm=$courseid.'.['.$section.'].'.$mapparm;
+
+	    my $courselevel=$courseid.'.'.$spacequalifierrest;
+	    my $courselevelr=$courseid.'.'.$symbparm;
+	    my $courselevelm=$courseid.'.'.$mapparm;
 
-      } else {
-	  if ($resourcedata{$courselevelr}!~/No such file/) {
-	    &logthis("<font color=blue>WARNING:".
-		   " Trying to get resource data for ".$ENV{'user.name'}." at "
-                   .$ENV{'user.domain'}.": ".$resourcedata{$courselevelr}.
-                 "</font>");
-	  }
-      }
+# ----------------------------------------------------------- first, check user
+	    my %resourcedata=&get('resourcedata',
+				  [$courselevelr,$courselevelm,$courselevel],
+				 $udom,$uname);
+	    if (($resourcedata{$courselevelr}!~/^error\:/) &&
+		($resourcedata{$courselevelr}!~/^con_lost/)) {
+
+		if ($resourcedata{$courselevelr}) {
+		    return $resourcedata{$courselevelr}; }
+		if ($resourcedata{$courselevelm}) {
+		    return $resourcedata{$courselevelm}; }
+		if ($resourcedata{$courselevel}) {
+		    return $resourcedata{$courselevel}; }
+	    } else {
+		if ($resourcedata{$courselevelr}!~/No such file/) {
+		    &logthis("<font color=blue>WARNING:".
+			     " Trying to get resource data for ".
+			     $uname." at ".$udom.": ".
+			     $resourcedata{$courselevelr}."</font>");
+		}
+	    }
 
 # -------------------------------------------------------- second, check course
 
-        my $coursereply=&courseresdata(
-                        $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
-                        $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
-                        ($seclevelr,$seclevelm,$seclevel,
-                         $courselevelr,$courselevelm,$courselevel));
-        if ($coursereply) { return $coursereply; }
+	    my $coursereply=&courseresdata($ENV{'course.'.$courseid.'.num'},
+					  $ENV{'course.'.$courseid.'.domain'},
+					  ($seclevelr,$seclevelm,$seclevel,
+					   $courselevelr,$courselevelm,
+					   $courselevel));
+	    if ($coursereply) { return $coursereply; }
 
 # ------------------------------------------------------ third, check map parms
-       my %parmhash=();
-       my $thisparm='';       
-       if (tie(%parmhash,'GDBM_File',
-          $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640)) {
-           $thisparm=$parmhash{$symbparm};
-	   untie(%parmhash);
-       }
-       if ($thisparm) { return $thisparm; }
-     }
-     
+	    my %parmhash=();
+	    my $thisparm='';
+	    if (tie(%parmhash,'GDBM_File',
+		    $ENV{'request.course.fn'}.'_parms.db',
+		    &GDBM_READER,0640)) {
+		$thisparm=$parmhash{$symbparm};
+		untie(%parmhash);
+	    }
+	    if ($thisparm) { return $thisparm; }
+	}
 # --------------------------------------------- last, look in resource metadata
 
-      $spacequalifierrest=~s/\./\_/;
-      my $metadata=&metadata($ENV{'request.filename'},$spacequalifierrest);
-      if ($metadata) { return $metadata; }
-      $metadata=&metadata($ENV{'request.filename'},
-                                         'parameter_'.$spacequalifierrest);
-      if ($metadata) { return $metadata; }
+	$spacequalifierrest=~s/\./\_/;
+	my $metadata=&metadata($ENV{'request.filename'},$spacequalifierrest);
+	if ($metadata) { return $metadata; }
+	$metadata=&metadata($ENV{'request.filename'},
+			    'parameter_'.$spacequalifierrest);
+	if ($metadata) { return $metadata; }
 
 # ------------------------------------------------------------------ Cascade up
-
-      unless ($space eq '0') {
-          my ($part,$id)=split(/\_/,$space);
-          if ($id) {
-	      my $partgeneral=&EXT('resource.'.$part.'.'.$qualifierrest,
-                                   $symbparm);
-              if ($partgeneral) { return $partgeneral; }
-          } else {
-              my $resourcegeneral=&EXT('resource.0.'.$qualifierrest,
-                                       $symbparm);
-              if ($resourcegeneral) { return $resourcegeneral; }
-          }
-      }
+	unless ($space eq '0') {
+	    my ($part,$id)=split(/\_/,$space);
+	    if ($id) {
+		my $partgeneral=&EXT('resource.'.$part.'.'.$qualifierrest,
+				     $symbparm,$udom,$uname);
+		if ($partgeneral) { return $partgeneral; }
+	    } else {
+		my $resourcegeneral=&EXT('resource.0.'.$qualifierrest,
+					 $symbparm,$udom,$uname);
+		if ($resourcegeneral) { return $resourcegeneral; }
+	    }
+	}
 
 # ---------------------------------------------------- Any other user namespace
     } elsif ($realm eq 'environment') {

--albertel1021281989--